📄 event.h
字号:
#ifndef _M_EVENT_ZHY_H
#define _M_EVENT_ZHY_H
#include "include\exception.h"
#include <windows.h>
#include <string>
#include <cassert>
using namespace std;
namespace Synchronization{
class Event
{
public:
Event() : handle(NULL)
{
};
virtual ~Event()
{
if(handle)
::CloseHandle(handle);
}
virtual void signal() = 0;
// 隐式转换
operator void*() const
{
return handle;
}
protected:
void *handle;
};
class AutoEvent :public Event
{
public:
AutoEvent(const char* eventName="anonymous") throw(CExceptionBase)
{
handle = reinterpret_cast<void*>(::CreateEvent(NULL, false, false, eventName));
if(handle == INVALID_HANDLE_VALUE)
throw CExceptionBase(CREATE_AUTOEVENT_ERROR,eventName);
}
void signal()
{
::SetEvent(handle);
}
};
class ManualEvent : public Event
{
public:
ManualEvent(const char* eventName=NULL)
{
// Note that the handle is closed in the base Event class.
handle = ::CreateEvent(NULL, true, false, eventName);
if(handle == NULL)
throw CExceptionBase(CREATE_MENALEVENT_ERROR,eventName);
assert(handle);
}
void signal() throw()
{
assert(handle);
::SetEvent(handle);
}
void reset() throw()
{
assert(handle);
::ResetEvent(handle);
}
};
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -