reSIProcate/rutil  9694
Public Member Functions | Private Member Functions | Private Attributes
resip::RecursiveMutex Class Reference

Wraps the recursive mutex implementation on your platform (if there is one). More...

#include <RecursiveMutex.hxx>

Inheritance diagram for resip::RecursiveMutex:
Inheritance graph
[legend]
Collaboration diagram for resip::RecursiveMutex:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 RecursiveMutex ()
virtual ~RecursiveMutex ()
virtual void lock ()
virtual void unlock ()

Private Member Functions

pthread_mutex_t * getId () const

Private Attributes

pthread_mutexattr_t mMutexAttr
pthread_mutex_t mId

Detailed Description

Wraps the recursive mutex implementation on your platform (if there is one).

Note:
A recursive mutex is a mutex that can be locked more than once by a given thread without causing a deadlock.

Definition at line 18 of file RecursiveMutex.hxx.


Constructor & Destructor Documentation

resip::RecursiveMutex::RecursiveMutex ( )

Definition at line 68 of file RecursiveMutex.cxx.

References mId, and mMutexAttr.

{
#ifndef WIN32
   int rc = pthread_mutexattr_init(&mMutexAttr);
 #if defined(__linux__)
   pthread_mutexattr_settype(&mMutexAttr, PTHREAD_MUTEX_RECURSIVE_NP);
 #else
   pthread_mutexattr_settype(&mMutexAttr, PTHREAD_MUTEX_RECURSIVE);
 #endif

   rc = pthread_mutex_init(&mId, &mMutexAttr);
   assert( rc == 0 );
#else
        InitializeCriticalSection(&mId);
#endif
}
resip::RecursiveMutex::~RecursiveMutex ( ) [virtual]

Definition at line 86 of file RecursiveMutex.cxx.

References mId, and mMutexAttr.

{
#ifndef WIN32
    int  rc = pthread_mutex_destroy(&mId);
    assert( rc != EBUSY );  // currently locked 
    assert( rc == 0 );
    rc = pthread_mutexattr_destroy(&mMutexAttr);
#else
        DeleteCriticalSection(&mId);
#endif
}

Member Function Documentation

pthread_mutex_t * resip::RecursiveMutex::getId ( ) const [private]

Definition at line 129 of file RecursiveMutex.cxx.

References mId.

{
    return ( &mId );
}
void resip::RecursiveMutex::lock ( ) [virtual]

Implements resip::Lockable.

Definition at line 100 of file RecursiveMutex.cxx.

References mId.

{
#ifndef WIN32
    int  rc = pthread_mutex_lock(&mId);
    (void)rc;
    assert( rc != EINVAL );
    assert( rc != EDEADLK );
    assert( rc == 0 );
#else
        EnterCriticalSection(&mId);
#endif
}
void resip::RecursiveMutex::unlock ( ) [virtual]

Implements resip::Lockable.

Definition at line 114 of file RecursiveMutex.cxx.

References mId.

{
#ifndef WIN32
    int  rc = pthread_mutex_unlock(&mId);
    (void)rc;
    assert( rc != EINVAL );
    assert( rc != EPERM );
    assert( rc == 0 );
#else
        LeaveCriticalSection(&mId);
#endif
}

Member Data Documentation

pthread_mutex_t resip::RecursiveMutex::mId [mutable, private]

Definition at line 31 of file RecursiveMutex.hxx.

Referenced by getId(), lock(), RecursiveMutex(), unlock(), and ~RecursiveMutex().

pthread_mutexattr_t resip::RecursiveMutex::mMutexAttr [private]

Definition at line 30 of file RecursiveMutex.hxx.

Referenced by RecursiveMutex(), and ~RecursiveMutex().


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