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

Common wrapper for platform-specific mutexes. More...

#include "Mutex.h"

Inheritance diagram for Mutex:
Collaboration diagram for Mutex:

Public Member Functions

 Mutex ()
 Primary contructor. More...
 
 ~Mutex ()
 Destructor, releases allocated resources. More...
 
void Lock ()
 Locks the mutex. More...
 
bool TryLock ()
 Attempts to lock the mutex. More...
 
void Unlock ()
 Unlocks the mutex. More...
 

Protected Attributes

pthread_mutex_t mMutex
 A pthread mutex used for mutex implementation using pthread library. More...
 

Detailed Description

Common wrapper for platform-specific mutexes.

Author
Zhur, Bloody.Rabbit

Definition at line 36 of file Mutex.h.

Constructor & Destructor Documentation

Mutex::Mutex ( )

Primary contructor.

Definition at line 33 of file Mutex.cpp.

References mMutex.

34 {
35 #ifdef HAVE_WINDOWS_H
36  InitializeCriticalSection( &mCriticalSection );
37 #else /* !HAVE_WINDOWS_H */
38  pthread_mutexattr_t attr;
39  pthread_mutexattr_init( &attr );
40 
41  pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE );
42 
43  pthread_mutex_init( &mMutex, &attr );
44  pthread_mutexattr_destroy( &attr );
45 #endif /* !HAVE_WINDOWS_H */
46 }
pthread_mutex_t mMutex
A pthread mutex used for mutex implementation using pthread library.
Definition: Mutex.h:72
Mutex::~Mutex ( )

Destructor, releases allocated resources.

Definition at line 48 of file Mutex.cpp.

References mMutex.

49 {
50 #ifdef HAVE_WINDOWS_H
51  DeleteCriticalSection( &mCriticalSection );
52 #else /* !HAVE_WINDOWS_H */
53  pthread_mutex_destroy( &mMutex );
54 #endif /* !HAVE_WINDOWS_H */
55 }
pthread_mutex_t mMutex
A pthread mutex used for mutex implementation using pthread library.
Definition: Mutex.h:72

Member Function Documentation

void Mutex::Lock ( )
virtual

Locks the mutex.

Implements Lockable.

Definition at line 57 of file Mutex.cpp.

References mMutex.

Referenced by TCPConnection::AsyncConnect(), TCPConnection::Connect(), BaseTCPServer::IsOpen(), BaseTCPServer::Open(), MRMutex::ReadLockCount(), TCPConnection::SendData(), TCPConnection::TCPConnectionLoop(), BaseTCPServer::TCPServerLoop(), MRMutex::TryReadLock(), MRMutex::TryWriteLock(), MRMutex::UnReadLock(), MRMutex::UnWriteLock(), BaseTCPServer::WaitLoop(), TCPConnection::WaitLoop(), MRMutex::WriteLock(), and MRMutex::WriteLockCount().

58 {
59 #ifdef HAVE_WINDOWS_H
60  EnterCriticalSection( &mCriticalSection );
61 #else /* !HAVE_WINDOWS_H */
62  pthread_mutex_lock( &mMutex );
63 #endif /* !HAVE_WINDOWS_H */
64 }
pthread_mutex_t mMutex
A pthread mutex used for mutex implementation using pthread library.
Definition: Mutex.h:72

Here is the caller graph for this function:

bool Mutex::TryLock ( )
virtual

Attempts to lock the mutex.

Return values
trueMutex successfully locked.
falseMutex locked by another thread.

Implements Lockable.

Definition at line 66 of file Mutex.cpp.

References mMutex.

Referenced by DBcore::ping().

67 {
68 #ifdef HAVE_WINDOWS_H
69  return TRUE == TryEnterCriticalSection( &mCriticalSection );
70 #else /* !HAVE_WINDOWS_H */
71  return 0 == pthread_mutex_trylock( &mMutex );
72 #endif /* !HAVE_WINDOWS_H */
73 }
pthread_mutex_t mMutex
A pthread mutex used for mutex implementation using pthread library.
Definition: Mutex.h:72

Here is the caller graph for this function:

void Mutex::Unlock ( )
virtual

Unlocks the mutex.

Implements Lockable.

Definition at line 75 of file Mutex.cpp.

References mMutex.

Referenced by TCPConnection::AsyncConnect(), TCPConnection::Connect(), BaseTCPServer::IsOpen(), BaseTCPServer::Open(), DBcore::ping(), MRMutex::ReadLockCount(), TCPConnection::SendData(), TCPConnection::TCPConnectionLoop(), BaseTCPServer::TCPServerLoop(), MRMutex::TryReadLock(), MRMutex::TryWriteLock(), MRMutex::UnReadLock(), MRMutex::UnWriteLock(), BaseTCPServer::WaitLoop(), TCPConnection::WaitLoop(), MRMutex::WriteLock(), and MRMutex::WriteLockCount().

76 {
77 #ifdef HAVE_WINDOWS_H
78  LeaveCriticalSection( &mCriticalSection );
79 #else /* !HAVE_WINDOWS_H */
80  pthread_mutex_unlock( &mMutex );
81 #endif /* !HAVE_WINDOWS_H */
82 }
pthread_mutex_t mMutex
A pthread mutex used for mutex implementation using pthread library.
Definition: Mutex.h:72

Here is the caller graph for this function:

Member Data Documentation

pthread_mutex_t Mutex::mMutex
protected

A pthread mutex used for mutex implementation using pthread library.

Definition at line 72 of file Mutex.h.

Referenced by Lock(), Mutex(), TryLock(), Unlock(), and ~Mutex().


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