CMCore/inc/hgl/thread/CondVar.h
2020-01-23 20:37:42 +08:00

33 lines
1.2 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef HGL_MULTI_THREAD_CONDITION_VARIABLE_INCLUDE
#define HGL_MULTI_THREAD_CONDITION_VARIABLE_INCLUDE
#include<hgl/platform/Platform.h>
namespace hgl
{
class ThreadMutex;
class RWLock;
/**
* 条件变量
*/
class CondVar
{
cond_var_ptr *cond_var;
public:
CondVar();
virtual ~CondVar();
bool Wait(ThreadMutex *,double time=0); ///<释放指定ThreadMutex在条件符合后重新锁定并结束等待,0表示永久
#if HGL_OS == HGL_OS_Windows
bool Wait(RWLock *,double time=0,bool read=false); ///<释放指定RWLock在条件符合后重新锁定并结束等待。此函数仅在Windows 2008/Vista及更新版本中支持Linux/BSD版不支持
#endif//HGL_OS == HGL_OS_Windows
void Signal(); ///<发送一个信号,让一个等待的线程解锁
void Broadcast(); ///<广播一个信号,让所有等待的线程都解锁
};//class CondVar
}//namespace hgl
#endif//HGL_MULTI_THREAD_CONDITION_VARIABLE_INCLUDE