ULRE/inc/hgl/thread/Semaphore.h

34 lines
1.1 KiB
C
Raw Normal View History

#ifndef HGL_SEMAPHORE_INCLUDE
2018-11-27 15:43:32 +08:00
#define HGL_SEMAPHORE_INCLUDE
#ifdef __APPLE__
#include<dispatch/dispatch.h>
#endif//__APPLE__
namespace hgl
{
/**
* 线<br>
*
*/
2018-11-27 15:43:32 +08:00
class Semaphore ///信号
{
2018-11-27 15:43:32 +08:00
#ifdef __APPLE__
dispatch_semaphore_t ptr;
#else
void *ptr;
2018-11-27 15:43:32 +08:00
#endif//__APPLE__
public:
2018-11-27 15:43:32 +08:00
Semaphore(int=1024);
virtual ~Semaphore();
2018-11-27 15:43:32 +08:00
virtual bool Post(int n=1); ///<发送信号
2018-11-27 15:43:32 +08:00
virtual bool TryAcquire(); ///<尝试取得一个信号
virtual bool Acquire(double time=0.0); ///<等待并获取一个信号
};//class Semaphore
2018-11-27 15:43:32 +08:00
}//namespace hgl
#endif//HGL_SEMAPHORE_INCLUDE