Rocstar
1.0
Rocstar multiphysics simulation application
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
Sync.h
Go to the documentation of this file.
1
/* *******************************************************************
2
* Rocstar Simulation Suite *
3
* Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4
* *
5
* Illinois Rocstar LLC *
6
* Champaign, IL *
7
* www.illinoisrocstar.com *
8
* sales@illinoisrocstar.com *
9
* *
10
* License: See LICENSE file in top level of distribution package or *
11
* http://opensource.org/licenses/NCSA *
12
*********************************************************************/
13
/* *******************************************************************
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17
* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21
* USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22
*********************************************************************/
23
#if !defined(_SYNC_H)
24
# define _SYNC_H
25
26
# include <pthread.h>
27
28
class
Mutex
29
{
30
public
:
31
Mutex
();
32
~Mutex
();
33
34
inline
bool
IsOk
()
const
{
return
m_isOk
; }
35
36
int
Lock
();
37
int
TryLock
();
38
int
Unlock
();
39
40
friend
class
Condition
;
41
42
private
:
43
pthread_mutex_t
m_mutex
;
44
bool
m_isOk
;
45
};
46
47
class
Condition
48
{
49
public
:
50
Condition
(
Mutex
& mutex);
51
~Condition
();
52
53
inline
bool
IsOk
()
const
{
return
(
m_isOk
&&
m_mutex
.
IsOk
()); }
54
55
int
Wait
();
56
int
Signal
();
57
int
Broadcast
();
58
59
private
:
60
Mutex
&
m_mutex
;
61
pthread_cond_t
m_cond
;
62
bool
m_isOk
;
63
};
64
65
class
Semaphore
66
{
67
public
:
68
Semaphore
(
int
initialcount = 0,
int
maxcount = 0);
69
~Semaphore
();
70
71
inline
bool
IsOk
()
const
{
return
m_isOk
; }
72
73
bool
Wait
();
74
bool
TryWait
();
75
bool
Post
();
76
77
private
:
78
Mutex
m_mutex
;
79
Condition
m_cond
;
80
int
m_count
;
81
int
m_maxcount
;
82
bool
m_isOk
;
83
};
84
85
#endif // !defined(_SYNC_H)
86
87
88
89
90
91
Condition::Condition
Condition(Mutex &mutex)
Definition:
Sync.C:116
Condition::IsOk
bool IsOk() const
Definition:
Sync.h:53
Semaphore::m_count
int m_count
Definition:
Sync.h:80
Mutex::IsOk
bool IsOk() const
Definition:
Sync.h:34
Mutex::Lock
int Lock()
Definition:
Sync.C:50
Mutex::~Mutex
~Mutex()
Definition:
Sync.C:39
Semaphore
Definition:
Sync.h:65
Mutex::m_isOk
bool m_isOk
Definition:
Sync.h:44
Mutex
Definition:
Sync.h:28
Mutex::Unlock
int Unlock()
Definition:
Sync.C:95
Semaphore::m_isOk
bool m_isOk
Definition:
Sync.h:82
Condition::~Condition
~Condition()
Definition:
Sync.C:129
Semaphore::m_cond
Condition m_cond
Definition:
Sync.h:79
Condition::m_mutex
Mutex & m_mutex
Definition:
Sync.h:60
Condition::m_cond
pthread_cond_t m_cond
Definition:
Sync.h:61
Mutex::m_mutex
pthread_mutex_t m_mutex
Definition:
Sync.h:43
Mutex::TryLock
int TryLock()
Definition:
Sync.C:74
Condition
Definition:
Sync.h:47
Semaphore::m_mutex
Mutex m_mutex
Definition:
Sync.h:78
Semaphore::Wait
bool Wait()
Definition:
Sync.C:191
Semaphore::TryWait
bool TryWait()
Definition:
Sync.C:208
Semaphore::Semaphore
Semaphore(int initialcount=0, int maxcount=0)
Definition:
Sync.C:170
Condition::Wait
int Wait()
Definition:
Sync.C:140
Semaphore::Post
bool Post()
Definition:
Sync.C:223
Condition::Broadcast
int Broadcast()
Definition:
Sync.C:160
Mutex::Mutex
Mutex()
Definition:
Sync.C:29
Semaphore::m_maxcount
int m_maxcount
Definition:
Sync.h:81
Condition::Signal
int Signal()
Definition:
Sync.C:150
Semaphore::IsOk
bool IsOk() const
Definition:
Sync.h:71
Semaphore::~Semaphore
~Semaphore()
Definition:
Sync.C:187
Condition::m_isOk
bool m_isOk
Definition:
Sync.h:62
Roccom
Rocin
include
Sync.h
Generated on Wed Nov 30 2016 16:56:19 for Rocstar by
1.8.5