larbin源碼分析(六) larbin中線程處理類
一 線程類
larbin下的線程操作類,主要在mypthread.h 中定義,實質上是利用宏定義,封裝了 pthread.h中的系統調用。
一個進程可以有多個線程,每個線程都有自己的處理流程。
二 具體實現
typedef void* (*StartFun) (void *);
void startThread (StartFun run, void *arg);
startThread 函數實質上是 調用pthread_create 啟動一個新的線程。
//下面為線程同步的操作
#define mypthread_cond_init(x,y) pthread_cond_init(x,y)
#define mypthread_cond_destroy(x) pthread_cond_destroy(x)
#define mypthread_cond_wait(c,x,y) while (c) { pthread_cond_wait(x,y); }
#define mypthread_cond_broadcast(x) pthread_cond_broadcast(x)
//下面為線程互斥的操作
#define mypthread_mutex_init(x,y) pthread_mutex_init(x,y)
#define mypthread_mutex_destroy(x) pthread_mutex_destroy(x)
#define mypthread_mutex_lock(x) pthread_mutex_lock(x)
#define mypthread_mutex_unlock(x) pthread_mutex_unlock(x)