ProcessState实例化过程讲解
迪丽瓦拉
2024-03-20 23:17:08
0

1.ProcessState实例化过程

main.cProcessStateopen_driveropenioctlmmapProcessState::self()->>startThreadPool()mDriverFD = open_driver("/dev/binder")int fd = open("/dev/binder", O_RDWR | O_CLOEXEC)ioctl(fd, BINDER_VERSION, &vers)mmap(mDriverFD)main.cProcessStateopen_driveropenioctlmmapProcessState实例化过程

2.程序例子

RefBase基类和智能指针StrongPointer关系

1).make()函数用法在StrongPointer.h里.
system/core/libutils/include/utils/StrongPointer.h
class sp {template template sp sp::make(Args&&... args) {T* t = new T(std::forward(args)...);sp result;result.m_ptr = t;t->incStrong(t);  // bypass check_not_on_stack for heap allocationreturn result;}
};

2).其实RefBase.h里引用了utils/StrongPointer.h,即使用了智能指针,如下位置:

system/core/libutils/include/utils/RefBase.h
#include **

<1>.Android.mk

```Makefile
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := sppointer
LOCAL_SRC_FILES := strong_pointer.cpp
LOCAL_SHARED_LIBRARIES := libcutils libutils
include $(BUILD_EXECUTABLE)

<2>.strong_pointer.cpp

#include 
#include 
#include using namespace android;class Bigclass : public RefBase{
public:Bigclass(String8 name): mDriverName(name){printf("Bigclass::mDriverName = %s\n",mDriverName.c_str());}String8 getDriverName() {return mDriverName;}private:String8 mDriverName;
};int main(){const char *driver = "/dev/binder";static sp  bC;//bC = = new Bigclass(String8(driver));//Or  bC = sp::make(String8(driver));printf("xxx------> driverName = %s\n",bC->getDriverName().c_str());return 0;
}

相关内容