EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MRMutex Class Reference

#include "Mutex.h"

Collaboration diagram for MRMutex:

Public Member Functions

 MRMutex ()
 
 ~MRMutex ()
 
void ReadLock ()
 
bool TryReadLock ()
 
void UnReadLock ()
 
void WriteLock ()
 
bool TryWriteLock ()
 
void UnWriteLock ()
 
int32 ReadLockCount ()
 
int32 WriteLockCount ()
 

Private Attributes

int32 rl
 
int32 wr
 
int32 wl
 
Mutex MCounters
 

Detailed Description

Definition at line 81 of file Mutex.h.

Constructor & Destructor Documentation

MRMutex::MRMutex ( )

Definition at line 87 of file Mutex.cpp.

References rl, wl, and wr.

87  {
88  rl = 0;
89  wr = 0;
90  wl = 0;
91 }
int32 wl
Definition: Mutex.h:100
int32 wr
Definition: Mutex.h:99
int32 rl
Definition: Mutex.h:98
MRMutex::~MRMutex ( )

Definition at line 93 of file Mutex.cpp.

References rl, and wl.

93  {
94 #ifdef _EQDEBUG
95  if (wl || rl) {
96  cout << "MRMutex::~MRMutex: poor cleanup detected: rl=" << rl << ", wl=" << wl << endl;
97  }
98 #endif
99 }
int32 wl
Definition: Mutex.h:100
int32 rl
Definition: Mutex.h:98

Member Function Documentation

void MRMutex::ReadLock ( )

Definition at line 101 of file Mutex.cpp.

References Sleep(), and TryReadLock().

101  {
102  while (!TryReadLock()) {
103  Sleep(1);
104  }
105 }
bool TryReadLock()
Definition: Mutex.cpp:107
void Sleep(uint32 x)
Definition: eve-compat.cpp:32

Here is the call graph for this function:

int32 MRMutex::ReadLockCount ( )

Definition at line 178 of file Mutex.cpp.

References Mutex::Lock(), MCounters, rl, and Mutex::Unlock().

178  {
179  MCounters.Lock();
180  int32 ret = rl;
181  MCounters.Unlock();
182  return ret;
183 }
void Lock()
Locks the mutex.
Definition: Mutex.cpp:57
signed __int32 int32
Definition: eve-compat.h:49
Mutex MCounters
Definition: Mutex.h:101
void Unlock()
Unlocks the mutex.
Definition: Mutex.cpp:75
int32 rl
Definition: Mutex.h:98

Here is the call graph for this function:

bool MRMutex::TryReadLock ( )

Definition at line 107 of file Mutex.cpp.

References Mutex::Lock(), MCounters, rl, Mutex::Unlock(), wl, and wr.

Referenced by ReadLock().

107  {
108  MCounters.Lock();
109  if (!wr && !wl) {
110  ++rl;
111  MCounters.Unlock();
112  return true;
113  }
114  else {
115  MCounters.Unlock();
116  return false;
117  }
118 }
void Lock()
Locks the mutex.
Definition: Mutex.cpp:57
int32 wl
Definition: Mutex.h:100
Mutex MCounters
Definition: Mutex.h:101
void Unlock()
Unlocks the mutex.
Definition: Mutex.cpp:75
int32 wr
Definition: Mutex.h:99
int32 rl
Definition: Mutex.h:98

Here is the call graph for this function:

Here is the caller graph for this function:

bool MRMutex::TryWriteLock ( )

Definition at line 154 of file Mutex.cpp.

References Mutex::Lock(), MCounters, rl, Mutex::Unlock(), and wl.

154  {
155  MCounters.Lock();
156  if (!rl && !wl) {
157  ++wl;
158  MCounters.Unlock();
159  return true;
160  }
161  else {
162  MCounters.Unlock();
163  return false;
164  }
165 }
void Lock()
Locks the mutex.
Definition: Mutex.cpp:57
int32 wl
Definition: Mutex.h:100
Mutex MCounters
Definition: Mutex.h:101
void Unlock()
Unlocks the mutex.
Definition: Mutex.cpp:75
int32 rl
Definition: Mutex.h:98

Here is the call graph for this function:

void MRMutex::UnReadLock ( )

Definition at line 120 of file Mutex.cpp.

References Mutex::Lock(), MCounters, rl, and Mutex::Unlock().

120  {
121  MCounters.Lock();
122  --rl;
123 #ifdef _EQDEBUG
124  if (rl < 0) {
125  ThrowError("rl < 0 in MRMutex::UnReadLock()");
126  }
127 #endif
128  MCounters.Unlock();
129 }
void Lock()
Locks the mutex.
Definition: Mutex.cpp:57
Mutex MCounters
Definition: Mutex.h:101
void Unlock()
Unlocks the mutex.
Definition: Mutex.cpp:75
int32 rl
Definition: Mutex.h:98

Here is the call graph for this function:

void MRMutex::UnWriteLock ( )

Definition at line 167 of file Mutex.cpp.

References Mutex::Lock(), MCounters, Mutex::Unlock(), and wl.

167  {
168  MCounters.Lock();
169  --wl;
170 #ifdef _EQDEBUG
171  if (wl < 0) {
172  ThrowError("wl < 0 in MRMutex::UnWriteLock()");
173  }
174 #endif
175  MCounters.Unlock();
176 }
void Lock()
Locks the mutex.
Definition: Mutex.cpp:57
int32 wl
Definition: Mutex.h:100
Mutex MCounters
Definition: Mutex.h:101
void Unlock()
Unlocks the mutex.
Definition: Mutex.cpp:75

Here is the call graph for this function:

void MRMutex::WriteLock ( )

Definition at line 131 of file Mutex.cpp.

References Mutex::Lock(), MCounters, rl, Sleep(), Mutex::Unlock(), wl, and wr.

131  {
132  MCounters.Lock();
133  if (!rl && !wl) {
134  ++wl;
135  MCounters.Unlock();
136  return;
137  }
138  else {
139  ++wr;
140  MCounters.Unlock();
141  while (1) {
142  Sleep(1);
143  MCounters.Lock();
144  if (!rl && !wl) {
145  --wr;
146  MCounters.Unlock();
147  return;
148  }
149  MCounters.Lock();
150  }
151  }
152 }
void Lock()
Locks the mutex.
Definition: Mutex.cpp:57
int32 wl
Definition: Mutex.h:100
Mutex MCounters
Definition: Mutex.h:101
void Unlock()
Unlocks the mutex.
Definition: Mutex.cpp:75
void Sleep(uint32 x)
Definition: eve-compat.cpp:32
int32 wr
Definition: Mutex.h:99
int32 rl
Definition: Mutex.h:98

Here is the call graph for this function:

int32 MRMutex::WriteLockCount ( )

Definition at line 185 of file Mutex.cpp.

References Mutex::Lock(), MCounters, Mutex::Unlock(), and wl.

185  {
186  MCounters.Lock();
187  int32 ret = wl;
188  MCounters.Unlock();
189  return ret;
190 }
void Lock()
Locks the mutex.
Definition: Mutex.cpp:57
signed __int32 int32
Definition: eve-compat.h:49
int32 wl
Definition: Mutex.h:100
Mutex MCounters
Definition: Mutex.h:101
void Unlock()
Unlocks the mutex.
Definition: Mutex.cpp:75

Here is the call graph for this function:

Member Data Documentation

Mutex MRMutex::MCounters
private
int32 MRMutex::rl
private

Definition at line 98 of file Mutex.h.

Referenced by MRMutex(), ReadLockCount(), TryReadLock(), TryWriteLock(), UnReadLock(), WriteLock(), and ~MRMutex().

int32 MRMutex::wl
private
int32 MRMutex::wr
private

Definition at line 99 of file Mutex.h.

Referenced by MRMutex(), TryReadLock(), and WriteLock().


The documentation for this class was generated from the following files: