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

LOW_thread_mutex Class Reference

Abstract base class for thread mutex. More...

#include <LOW_thread_mutex.h>

Inheritance diagram for LOW_thread_mutex:

Inheritance 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

 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.

 LOW_thread_mutex (const mutexKind_t inMutexKind)
 Constructor.

virtual ~LOW_thread_mutex ()
 Destructor.

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

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

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

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


Private Attributes

const mutexKind_t mutexKind

Detailed Description

Abstract base class for thread mutex.

Each instance represents one thread mutex.

Specific platforms dereive their implementation classes from this class.

The instances are created by LOW_thread_Factory, following the factory design pattern.

Implementation classes must at least support three kinds od a mutex as defined by mutexKind_t.

This class is thread-safe.

See also:
LOW_thread_Factory
Author:
Harald Roelle

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

Definition at line 43 of file LOW_thread_mutex.h.


Member Enumeration Documentation

enum LOW_thread_mutex::mutexKind_t
 

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 getKind().


Constructor & Destructor Documentation

LOW_thread_mutex::LOW_thread_mutex const mutexKind_t  inMutexKind  ) 
 

Constructor.

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

Definition at line 29 of file LOW_thread_mutex.cpp.

LOW_thread_mutex::~LOW_thread_mutex  )  [virtual]
 

Destructor.

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

Definition at line 35 of file LOW_thread_mutex.cpp.


Member Function Documentation

LOW_thread_mutex::class_DERIVE_FROM_EXCEPTION thread_mutex_busy  ,
thread_mutex_error 
 

Exception class to indicate a mutex locked by another thread.

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.

LOW_thread_mutex::class_DERIVE_FROM_EXCEPTION thread_mutex_error  ,
LOW_exception 
 

Exception base class for all exceptions thrown by LOW_thread_mutex.

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

Get kind of the mutex.

Returns:
Kind of the mutex.

Definition at line 47 of file LOW_thread_mutex.cpp.

References mutexKind, and mutexKind_t.

virtual void LOW_thread_mutex::lock  )  [pure 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.

Abstract method to be implemented by derived class.

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

Implemented in LOW_thread_mutex_POSIX.

Referenced by LOW_link::commLock::commLock(), LOW_compJalousieController::jcLock::jcLock(), LOW_helper_msglog::msgLock::msgLock(), and LOW_thread_mutex::mutexLock::mutexLock().

virtual void LOW_thread_mutex::tryLock  )  [pure 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.

Abstract method to be implemented by derived class.

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.

Implemented in LOW_thread_mutex_POSIX.

virtual void LOW_thread_mutex::unlock  )  [pure 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.

Abstract method to be implemented by derived class.

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

Implemented in LOW_thread_mutex_POSIX.

Referenced by LOW_link::commLock::~commLock(), LOW_compJalousieController::jcLock::~jcLock(), LOW_helper_msglog::msgLock::~msgLock(), and LOW_thread_mutex::mutexLock::~mutexLock().


Member Data Documentation

const mutexKind_t LOW_thread_mutex::mutexKind [private]
 

Definition at line 208 of file LOW_thread_mutex.h.

Referenced by getKind().


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