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

◆ Mutex()

FIX::Mutex::Mutex ( )
inline

Definition at line 33 of file Mutex.h.

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
int m_count
Definition Mutex.h:90
pthread_t m_threadID
Definition Mutex.h:89

References m_count, m_mutex, and m_threadID.

◆ ~Mutex()

FIX::Mutex::~Mutex ( )
inline

Definition at line 48 of file Mutex.h.

49 {
50#ifdef _MSC_VER
51 DeleteCriticalSection( &m_mutex );
52#else
53 pthread_mutex_destroy( &m_mutex );
54#endif
55 }

References m_mutex.

Member Function Documentation

◆ lock()

void FIX::Mutex::lock ( )
inline

Definition at line 57 of file Mutex.h.

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 }

References m_count, m_mutex, and m_threadID.

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

◆ unlock()

void FIX::Mutex::unlock ( )
inline

Definition at line 70 of file Mutex.h.

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 }

References m_count, m_mutex, and m_threadID.

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

Member Data Documentation

◆ m_count

int FIX::Mutex::m_count
private

Definition at line 90 of file Mutex.h.

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

◆ m_mutex

pthread_mutex_t FIX::Mutex::m_mutex
private

Definition at line 88 of file Mutex.h.

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

◆ m_threadID

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 Fri Sep 27 2024 13:45:21 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001