blob: 80773d8c04d42cc7809957d97c410d28a988c603 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#ifndef __ASURA_SEMAPHORE_H__
#define __ASURA_SEMAPHORE_H__
#include "../utils_config.h"
#if ASURA_THREAD_WIN32
#include <windows.h>
#endif
namespace AsuraEngine
{
namespace Threading
{
class SemaphoreImpl;
///
/// ź
///
class Semaphore
{
public:
Semaphore(unsigned int init_count = 1);
~Semaphore();
void Signal();
void Wait(int timeout = 0);
private:
SemaphoreImpl* mImpl;
};
class SemaphoreImpl
{
public:
SemaphoreImpl(unsigned int init_value)
: mCount(init_value)
{
};
virtual ~SemaphoreImpl() {};
virtual void Signal() = 0;
virtual bool Wait(int timeout) = 0;
inline int Current() { return mCount; }
protected:
unsigned int mCount;
};
#define wait(sem) sem.Wait();
#define signal(sem) sem.Signal();
#if ASURA_THREAD_WIN32
class SemaphoreWin32 : public SemaphoreImpl
{
public:
SemaphoreWin32(unsigned int init_value);
~SemaphoreWin32();
void Signal() override;
bool Wait(int timeout) override;
private:
HANDLE mSem;
};
#endif // ASURA_THREAD_WIN32
}
}
#endif
|