WebRTC原始碼分析-執行緒基礎之執行緒管理
阿新 • • 發佈:2021-01-07
技術標籤:webrtc
執行緒基礎之執行緒管理
WebRTC中的執行緒管理是通過ThreadManager物件來實施的,該類起著牧羊者的作用,rtc::Thread類物件就是羊群。其通過什麼樣的技術來實現對rtc::Thread管理的?在不同的系統平臺下如何實現?下文將進行闡述。
該類的宣告和定義與Thread類一樣,位於rtc_base目錄下的thread.h與thread.cc檔案中。先看其類的宣告:
class ThreadManager {
public:
static const int kForever = -1;
static ThreadManager* Instance();
Thread* CurrentThread();
void SetCurrentThread(Thread* thread);
Thread* WrapCurrentThread();
void UnwrapCurrentThread();
bool IsMainThread();
private:
ThreadManager();
~ThreadManager();
#if defined(WEBRTC_POSIX)
pthread_key_t key_;
#endif
#if defined(WEBRTC_WIN)
const DWORD key_;
#endif
const PlatformThreadRef main_thread_ref_;
RTC_DISALLOW_COPY_AND_ASSIGN(ThreadManager);
};