今日之事
* 文档完成
* Jiarong例子
* test的例子
1. CRtThreadManager
* class definition
class RT_API_EXPORT CRtThreadManager
{
....
static CRtThreadManager* Instance(); // singleton implementation. bad implemented.
static void CleanupOnlyOne();
RtResult InitMainThread(int aArgc, char** aArgv);
.....
CRtThread* GetThread(TType aType); // for what ?
IRtReactor* GetThreadReactor(TType aType);
IRtEventQueue* GetThreadEventQueue(TType aType); // why this ? 实际上只是一个"convenient method“,调用GetThread()完成。 2011/12/08
IRtTimerQueue* GetThreadTimerQueue(TType aType);
...
// create Task Thread (include EventQueue and TimerQueue only) // for what ??? what is task thread ?
RtResult CreateUserTaskThread(
CRtThread *&aThread,
TFlag aFlag = TF_JOINABLE,
BOOL bWithTimerQueue = TRUE);
......
public:
// the following member functions are mainly used in TP.
RtResult CreateReactorThread(TType aType, IRtReactor *aReactor, CRtThread *&aThread);
// mainly invoked by CRtThreadManager::~CRtThreadManager()
RtResult StopAllThreads(CRtTimeValue* aTimeout = NULL);
RtResult JoinAllThreads(); // what's this ?
// mainly invoked by CRtThread::Create().
RtResult RegisterThread(CRtThread* aThread); // all threads need to be registered ?
RtResult UnregisterThread(CRtThread* aThread);
......
enum TModule // for what ?
{
TM_SINGLE_MAIN,
TM_MULTI_ONE_DEDICATED,
TM_MULTI_POOL
};
static TModule GetNetworkThreadModule();
......
......
static IRtReactor* CreateNetworkReactor(); // 根据不同的宏创建不同的reactor实例
// 基本上有3种不同的Reactor给network thread: CRtReactorSelect, CRtReactorWin32Asyncselect, CRtReactorEpoll 2011/12/08
private:
RtResult SpawnNetworkThread_i(); // 产生子线程,具体细节???
......
// singleton mutex is recursive due to CRtCleanUpBase() will lock it too.
CRtMutexThreadRecursive m_SingletonMutex;
CRtMutexThread m_ReferenceControlMutexThread;
typedef std::vector<CRtThread *> ThreadsType;
ThreadsType m_Threads;
typedef CRtMutexThread MutexType ;
MutexType m_Mutex;
TType m_TTpyeUserThread;
......
CRtThread *m_pThreadNetwork; // for what ?
......
};
* CRtThreadManager::InitMainThread()
初始化的不仅仅是main thread
* CRtThreadManager::CreateNetworkReactor()
根据宏选择生成不同的Reactor,以下三种之一:
CRtReactorSelect
CRtReactorWin32AsyncSelect
CRtReactorEpoll
CRtThreadManager::RegisterThread()
RtResult CRtThreadManager::RegisterThread(CRtThread* aThread)
{
RT_ASSERTE_RETURN(aThread, RT_ERROR_INVALID_ARG);
......
ThreadsType::iterator iter = m_Threads.begin();
for ( ; iter != m_Threads.end(); ++iter) {
// we don't check equal ThreadId because mutil CRtThreads may use the same id. WHY ???
if ((*iter) == aThread ||
(*iter)->GetThreadType() == aThread->GetThreadType())
{
......
return RT_ERROR_FOUND;
}
}
m_Threads.push_back(aThread);
return RT_OK;
}
2. 文档总结
Q:CEventQueue与TimerQueue分别完成什么功能?
A:前者用于不同线程之间传递信息,后者完成定时器功能 2011/12/08
Q:一个client下面也有3个线程?分别做什么东东?
Q:ThreadManager用于启动(管理)网络线程,only网络线程?
A:管理所有线程。 2011/12/08
N:关于线程与事件队列
主(平台)线程类 网络线程类 主线程事件队列类 网络线程事件队列类
操作系统
Win32 CRtThreadReactor CRtThreadReactor ? CRtReactorWin32Message CRtReactorWin32AsyncSelect
Linux CRtThreadTask CRThreadReactor EventQueue CRtReactorEpoll
注:从这里看,Reactor主要表现成一个Event Queue。
3. Jiarong的例子
main函数有三步:
* 初始化主线程
* 生成cmd conference
* 运行主线程
Q:init main thred的时候,主线程的run event loop未运行?
Q:几块东东如何关联的?
Q:运行主线程的时候,没有reactor也没有问题?