認識Android的ProcessState類別和物件

ProcessState是一個singleton類別,它只有一個物件(Instance)。此物件負責打開Binder Driver(/dev/binder驅動),準備讓其進程裡的程式能與Binder Driver進行溝通。例如,它在其進程(於此,稱為client進程)裡誕生BpBinder物件,此BpBinder物件的執行緒(Thread)透過Binder Driver而轉接(relayto)IPC thread去執行另一個進程((於此,稱為service進程)裡的服務(例如ServiceManager service)


  


  與ProcessState類別具有密切關係的是IPCThreadState類別,這IPCThreadState類別也是singleton類別,只有一個物件(Instance)


 


       ProcessState負責打開BinderDriver,與Binder Driver溝通;而IPCThreadState負責透過Binder Driver而進行跨進程的實際資料讀寫動作。例如,client進程的程式呼叫BpBinderIBinder介面的transact()函數,此transact()函數則呼叫IPCThreadState物件的transact()函數去呼叫Binder Driverioctl()函數來進行實際資料傳遞。

 

       


       IPCThreadState block( 阻塞 ) client 進程的 calling thread ,而 轉接 (relay to) IPC thread 去執行 server 進程裡的 target 服務 。同時等待 IPC thread 執行完畢,回傳數據,才放行 calling thread

你可能感兴趣的:(thread,android)