Public Member Functions | Private Attributes | List of all members
FIX::Mutex Class Reference

Portable implementation of a mutex. More...

#include <Mutex.h>

Public Member Functions

 Mutex ()
 
 ~Mutex ()
 
void lock ()
 
void unlock ()
 

Private Attributes

pthread_mutex_t m_mutex
 
pthread_t m_threadID
 
int m_count
 

Detailed Description

Portable implementation of a mutex.

Definition at line 30 of file Mutex.h.

Constructor & Destructor Documentation

FIX::Mutex::Mutex ( )
inline

Definition at line 33 of file Mutex.h.

References m_count, m_mutex, and m_threadID.

34  {
35 #ifdef _MSC_VER
36  InitializeCriticalSection( &m_mutex );
37 #else
38  m_count = 0;
39  m_threadID = 0;
40  //pthread_mutexattr_t attr;
41  //pthread_mutexattr_init(&attr);
42  //pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
43  //pthread_mutex_init(&m_mutex, &attr);
44  pthread_mutex_init( &m_mutex, 0 );
45 #endif
46  }
pthread_mutex_t m_mutex
Definition: Mutex.h:88
pthread_t m_threadID
Definition: Mutex.h:89
int m_count
Definition: Mutex.h:90
FIX::Mutex::~Mutex ( )
inline

Definition at line 48 of file Mutex.h.

References m_mutex.

49  {
50 #ifdef _MSC_VER
51  DeleteCriticalSection( &m_mutex );
52 #else
53  pthread_mutex_destroy( &m_mutex );
54 #endif
55  }
pthread_mutex_t m_mutex
Definition: Mutex.h:88

Member Function Documentation

void FIX::Mutex::lock ( )
inline

Definition at line 57 of file Mutex.h.

References m_count, m_mutex, and m_threadID.

Referenced by FIX::Locker::Locker(), and FIX::ReverseLocker::~ReverseLocker().

58  {
59 #ifdef _MSC_VER
60  EnterCriticalSection( &m_mutex );
61 #else
62  if ( m_count && m_threadID == pthread_self() )
63  { ++m_count; return ; }
64  pthread_mutex_lock( &m_mutex );
65  ++m_count;
66  m_threadID = pthread_self();
67 #endif
68  }
pthread_mutex_t m_mutex
Definition: Mutex.h:88
pthread_t m_threadID
Definition: Mutex.h:89
int m_count
Definition: Mutex.h:90
void FIX::Mutex::unlock ( )
inline

Definition at line 70 of file Mutex.h.

References m_count, m_mutex, and m_threadID.

Referenced by FIX::ReverseLocker::ReverseLocker(), and FIX::Locker::~Locker().

71  {
72 #ifdef _MSC_VER
73  LeaveCriticalSection( &m_mutex );
74 #else
75  if ( m_count > 1 )
76  { m_count--; return ; }
77  --m_count;
78  m_threadID = 0;
79  pthread_mutex_unlock( &m_mutex );
80 #endif
81  }
pthread_mutex_t m_mutex
Definition: Mutex.h:88
pthread_t m_threadID
Definition: Mutex.h:89
int m_count
Definition: Mutex.h:90

Member Data Documentation

int FIX::Mutex::m_count
private

Definition at line 90 of file Mutex.h.

Referenced by lock(), Mutex(), and unlock().

pthread_mutex_t FIX::Mutex::m_mutex
private

Definition at line 88 of file Mutex.h.

Referenced by lock(), Mutex(), unlock(), and ~Mutex().

pthread_t FIX::Mutex::m_threadID
private

Definition at line 89 of file Mutex.h.

Referenced by lock(), Mutex(), and unlock().


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

Generated on Sat Mar 29 2014 15:13:34 for QuickFIX by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2001