Main Page
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Enumerations
Enumerator
Pages
src
server
sync.h
1
/*
2
Copyright (c) 2014 by Elvis Angelaccio
3
4
Permission is hereby granted, free of charge, to any person obtaining a copy
5
of this software and associated documentation files (the "Software"), to deal
6
in the Software without restriction, including without limitation the rights
7
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
copies of the Software, and to permit persons to whom the Software is
9
furnished to do so, subject to the following conditions:
10
11
The above copyright notice and this permission notice shall be included in
12
all copies or substantial portions of the Software.
13
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
THE SOFTWARE.
21
*/
22
23
#ifndef SYNC_H
24
#define SYNC_H
25
26
#if (defined(_WIN32) || defined(__WIN32__) || defined(WIN32))
27
#include <windows.h>
28
#else
29
#include <pthread.h>
30
#endif
31
32
33
namespace
server
34
{
40
class
Mutex
41
{
42
public
:
43
44
Mutex
();
45
~
Mutex
();
46
48
void
lock
();
49
51
void
unlock
();
52
53
private
:
54
55
#if (defined(_WIN32) || defined(__WIN32__) || defined(WIN32))
56
HANDLE mutex;
57
#else
58
pthread_mutex_t mutex;
59
#endif
60
};
61
62
69
class
RWLock
70
{
71
72
public
:
73
74
RWLock
();
75
77
void
rLock
();
78
80
void
rUnlock
();
81
83
void
wLock
();
84
86
void
wUnlock
();
87
88
private
:
89
90
int
readerCount;
91
Mutex
countMutex;
92
Mutex
writeMutex;
94
};
95
96
97
#if (defined(_WIN32) || defined(__WIN32__) || defined(WIN32))
98
102
struct
Event
103
{
104
Event();
105
106
~Event();
107
108
HANDLE event;
109
};
110
111
112
#else
113
118
struct
CondVarBundle
119
{
121
CondVarBundle
();
122
124
~CondVarBundle
();
125
126
pthread_mutex_t mutex;
127
pthread_cond_t cond;
128
bool
condition;
129
};
130
131
#endif
132
133
}
134
135
#endif
server::CondVarBundle::CondVarBundle
CondVarBundle()
Definition:
sync.cpp:57
server::RWLock::rUnlock
void rUnlock()
Definition:
sync.cpp:40
server::RWLock::wLock
void wLock()
Definition:
sync.cpp:51
server::RWLock::wUnlock
void wUnlock()
Definition:
sync.cpp:56
server::Mutex::unlock
void unlock()
Definition:
sync.cpp:51
server::Mutex::lock
void lock()
Definition:
sync.cpp:46
server::Mutex
A Mutex object.
Definition:
sync.h:40
server::CondVarBundle
Definition:
sync.h:118
server::RWLock::rLock
void rLock()
Definition:
sync.cpp:29
server::RWLock
A Read-Write lock object.
Definition:
sync.h:69
server::CondVarBundle::~CondVarBundle
~CondVarBundle()
Definition:
sync.cpp:70
server
Definition:
Server.h:34
Generated on Thu Dec 25 2014 19:20:49 by
1.8.8