muduo/base库学习笔记(5)-----Condition类
Condition
1 构造函数和析构函数的实现
** Condition(MutexLock& mutex)函数的实现**
explicit Condition(MutexLock& mutex)
: mutex_(mutex)
{
MCHECK(pthread_cond_init(&pcond_, NULL));
}
~Condition()函数的实现
~Condition()
{
MCHECK(pthread_cond_destroy(&pcond_));
}
2 普通成员函数的实现
wait()函数的实现
void wait()
{
//阻塞等待条件变量的满足
MutexLock::UnassignGuard ug(mutex_);
MCHECK(pthread_cond_wait(&pcond_, mutex_.getPthreadMutex()));
}
notify()函数的实现,通知一个线程
void notify()
{
MCHECK(pthread_cond_signal(&pcond_));
}
notifyAll()函数的实现,通知所有线程
void notifyAll()
{
MCHECK(pthread_cond_broadcast(&pcond_));
}