This repository has been archived by the owner on Oct 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmultithread.h
93 lines (77 loc) · 1.47 KB
/
multithread.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// multithread.h
#ifndef _MULTITHREAD_H
# define _MULTITHREAD_H
#if defined(WIN32)
# include <windows.h>
#elif defined(__linux__)
# elif defined(__APPLE__)
#endif
///
class SyncObject
{
public:
///
virtual void acquire() = 0;
///
virtual void acquire(int ) { acquire(); }
///
virtual void release() = 0;
};
#if defined(_MSC_VER)
///
class CriticalSection : public SyncObject
{
CRITICAL_SECTION m_cs; ///
public:
///
CriticalSection() { InitializeCriticalSection(&m_cs); }
///
~CriticalSection() { DeleteCriticalSection(&m_cs); }
///
void acquire() { EnterCriticalSection(&m_cs); }
///
void release() { LeaveCriticalSection(&m_cs); }
};
#elif defined(__linux__) || defined(__APPLE__)
// TODO:
//とりあえずシングルスレッドで動かすので Null Object
class CriticalSection : public SyncObject
{
public:
///
CriticalSection() { }
///
virtual ~CriticalSection() { }
///
void acquire() { }
///
void release() { }
};
class Mutex : public SyncObject
{
public:
///
Mutex() {}
///
virtual ~Mutex() {}
///
void acquire() {}
///
void release() {}
};
#endif
///
class Acquire
{
SyncObject *m_so; ///
public:
///
Acquire(SyncObject *i_so) : m_so(i_so) { m_so->acquire(); }
///
Acquire(SyncObject *i_so, int i_n) : m_so(i_so) { m_so->acquire(i_n); }
///
~Acquire() { m_so->release(); }
};
# elif defined(__APPLE__)
#endif // !_MULTITHREAD_H