Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

LOW_thread_mutex_POSIX Class Reference

Platform specific LOW_thread_mutex for POSIX platforms. More...

#include <LOW_thread_mutex_POSIX.h>

Inheritance diagram for LOW_thread_mutex_POSIX:

Inheritance graph
[legend]
Collaboration diagram for LOW_thread_mutex_POSIX:

Collaboration graph
[legend]
List of all members.

Public Types

enum  mutexKind_t { mutexKind_fast = 0, mutexKind_recursive, mutexKind_errorCheck }
 Basic type of a mutex. More...


Public Member Functions

virtual ~LOW_thread_mutex_POSIX ()
 Destructor.

virtual void lock ()
 Obtain a lock on the mutex (blocking).

virtual void tryLock ()
 Obtain a lock on the mutex (non-blocking).

virtual void unlock ()
 Release a lock on the mutex.

 class_DERIVE_FROM_EXCEPTION (thread_mutex_error, LOW_exception)
 Exception base class for all exceptions thrown by LOW_thread_mutex.

 class_DERIVE_FROM_EXCEPTION (thread_mutex_locked, thread_mutex_error)
 Exception class to indicate a mutex already locked by the calling thread.

 class_DERIVE_FROM_EXCEPTION (thread_mutex_busy, thread_mutex_error)
 Exception class to indicate a mutex locked by another thread.

virtual mutexKind_t getKind () const
 Get kind of the mutex.


Protected Member Functions

 LOW_thread_mutex_POSIX (const mutexKind_t inMutexKind)
 Constructor.


Private Attributes

pthread_mutexattr_t mutexAttr
 Initial mutex attributes.

pthread_mutex_t theMutex
 The mutex itself.


Friends

class LOW_thread_Factory
 To allow construction.


Detailed Description

Platform specific LOW_thread_mutex for POSIX platforms.

This class is thread-safe.

See also:
LOW_thread_mutex

IEEE Standard 1003.1-2003 (http://www.opengroup.org/onlinepubs/007904975/toc.htm)

Author:
Harald Roelle

Parts of the documentation taken from Linux man pages by Xavier Leroy.

Parts of the documentation taken from IEEE Standard 1003.1-2003.

Definition at line 40 of file LOW_thread_mutex_POSIX.h.


Member Enumeration Documentation

enum LOW_thread_mutex::mutexKind_t [inherited]
 

Basic type of a mutex.

Enumeration values:
mutexKind_fast  Binary mutex without deadlock prevention when called locked twice by same thread.
mutexKind_recursive  Integer/counting mutex.
mutexKind_errorCheck  Binary mutex with deadlock prevention and extended error checking.

Definition at line 104 of file LOW_thread_mutex.h.

Referenced by LOW_thread_mutex::getKind().


Constructor & Destructor Documentation

LOW_thread_mutex_POSIX::~LOW_thread_mutex_POSIX  )  [virtual]
 

Destructor.

Exceptions:
thread_mutex_busy The mutex is still locked.
thread_mutex_error Any other error.

Definition at line 65 of file LOW_thread_mutex_POSIX.cpp.

References mutexAttr, LOW_helper_msglog::printPerror(), and theMutex.

LOW_thread_mutex_POSIX::LOW_thread_mutex_POSIX const mutexKind_t  inMutexKind  )  [protected]
 

Constructor.

Not publicly constructable. Use LOW_thread_Factory.

Parameters:
inMutexKind Kind of the new mutex.
Exceptions:
thread_mutex_error Any error.

Definition at line 34 of file LOW_thread_mutex_POSIX.cpp.

References mutexAttr, LOW_thread_mutex::mutexKind_errorCheck, LOW_thread_mutex::mutexKind_fast, LOW_thread_mutex::mutexKind_recursive, and theMutex.


Member Function Documentation

LOW_thread_mutex::class_DERIVE_FROM_EXCEPTION thread_mutex_busy  ,
thread_mutex_error 
[inherited]
 

Exception class to indicate a mutex locked by another thread.

LOW_thread_mutex::class_DERIVE_FROM_EXCEPTION thread_mutex_locked  ,
thread_mutex_error 
[inherited]
 

Exception class to indicate a mutex already locked by the calling thread.

LOW_thread_mutex::class_DERIVE_FROM_EXCEPTION thread_mutex_error  ,
LOW_exception 
[inherited]
 

Exception base class for all exceptions thrown by LOW_thread_mutex.

LOW_thread_mutex::mutexKind_t LOW_thread_mutex::getKind  )  const [virtual, inherited]
 

Get kind of the mutex.

Returns:
Kind of the mutex.

Definition at line 47 of file LOW_thread_mutex.cpp.

References LOW_thread_mutex::mutexKind, and LOW_thread_mutex::mutexKind_t.

void LOW_thread_mutex_POSIX::lock  )  [virtual]
 

Obtain a lock on the mutex (blocking).

Blocks the calling thread if another thread has already locked the mutex.

If the mutex is already locked by the calling thread, behaviour depends on the mutex kind:

  • mutexKind_fast: The calling thread is suspended until the mutex is unlocked, thus effectively causing the calling thread to deadlock.
  • mutexKind_recursive: The call succeeds and returns immediately, recording the number of times the calling thread has locked the mutex. An equal number of unlock() calls must be performed before the mutex returns to the unlocked state.
  • mutexKind_errorCheck: A thread_mutex_locked exception is thrown.

Exceptions:
thread_mutex_locked Calling thread has already locked the mutex and mutex kind is mutexKind_errorCheck.
thread_mutex_error Any other error.

Implements LOW_thread_mutex.

Definition at line 82 of file LOW_thread_mutex_POSIX.cpp.

References theMutex.

void LOW_thread_mutex_POSIX::tryLock  )  [virtual]
 

Obtain a lock on the mutex (non-blocking).

Behaves identically to lock(), except that it does not block the calling thread if the mutex is already locked by another thread. Instead an thread_mutex_busy exception is thrown.

Exceptions:
thread_mutex_busy The mutex is already locked by another thread.
thread_mutex_locked Calling thread has already locked the mutex and mutex kind is mutexKind_errorCheck.
thread_mutex_error Any other error.

Implements LOW_thread_mutex.

Definition at line 93 of file LOW_thread_mutex_POSIX.cpp.

References theMutex.

void LOW_thread_mutex_POSIX::unlock  )  [virtual]
 

Release a lock on the mutex.

Behaviour depends on the mutex kind:

  • mutexKind_fast: The mutex is assumed to be locked and owned by the calling thread on entrance and always returns it to the unlocked state.
  • mutexKind_recursive: The mutex is assumed to be locked and owned by the calling thread on entrance. Decrements the locking count of the mutex (number of lock() calls performed on it by the calling thread), and only when this count reaches zero is the mutex actually unlocked.
  • mutexKind_errorCheck: Actually checks at run-time that the mutex is locked on entrance, and that it was locked by the same thread that is now calling.

Exceptions:
thread_mutex_busy The mutex is already by another thread.
thread_mutex_error Any other error.

Implements LOW_thread_mutex.

Definition at line 106 of file LOW_thread_mutex_POSIX.cpp.

References theMutex.


Friends And Related Function Documentation

friend class LOW_thread_Factory [friend]
 

To allow construction.

Definition at line 122 of file LOW_thread_mutex_POSIX.h.


Member Data Documentation

pthread_mutexattr_t LOW_thread_mutex_POSIX::mutexAttr [private]
 

Initial mutex attributes.

Definition at line 146 of file LOW_thread_mutex_POSIX.h.

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

pthread_mutex_t LOW_thread_mutex_POSIX::theMutex [private]
 

The mutex itself.

Definition at line 147 of file LOW_thread_mutex_POSIX.h.

Referenced by lock(), LOW_thread_mutex_POSIX(), tryLock(), unlock(), and ~LOW_thread_mutex_POSIX().


The documentation for this class was generated from the following files:
Generated on Tue Feb 3 11:31:08 2004 for OneWireLibrary++ by doxygen 1.3.2