The Micro C++ Library
micxx::Mutex Class Reference

A Mutex provides mutual exclusive access to critical sections of concurrent threads. More...

#include <micxx.hxx>

Inherits micxx::traits::NonCopyable, and micxx::traits::ToString.

Inherited by micxx::Condition, micxx::Socket, micxx::SocketSet, micxx::SSLProtocol, and micxx::Thread.

List of all members.

Public Member Functions

 Mutex ()
 Create a new Mutex.
virtual ~Mutex ()
 Deallocate and release the internally allocated mutex resources.
virtual unsigned getLockCount () const
 The number of (recursive) locks that have been obtained by the same thread.
virtual void lock ()
 Try to obtain the lock from this Mutex.
virtual std::string toString () const
 Returns a printable representation.
virtual void unlock ()
 Release the lock from this Mutex.

Protected Attributes

unsigned lockCount
 The number of (recursive) locks that have been obtained by the same thread.
pthread_t ownerId
pthread_mutex_t mutex

Detailed Description

A Mutex provides mutual exclusive access to critical sections of concurrent threads.

Author:
Norbert Klose
Date:
December, 2006

Constructor & Destructor Documentation

micxx::Mutex::Mutex ( )

Create a new Mutex.

virtual micxx::Mutex::~Mutex ( ) [virtual]

Deallocate and release the internally allocated mutex resources.


Member Function Documentation

virtual unsigned micxx::Mutex::getLockCount ( ) const [inline, virtual]

The number of (recursive) locks that have been obtained by the same thread.

    {
        return lockCount;
    }
virtual void micxx::Mutex::lock ( ) [virtual]

Try to obtain the lock from this Mutex.

Note:
This function blocks the calling thread from execution, until the lock has been obtained successfully.
For each call to lock() from the same thread, there must be an associated call to unlock(). Otherwise the lock will not be unlocked and ready to be obtained from other threads that are waiting for this lock.
virtual std::string micxx::Mutex::toString ( ) const [virtual]

Returns a printable representation.

Reimplemented from micxx::traits::ToString.

Reimplemented in micxx::ServerSocket, micxx::Socket, micxx::SSLProtocol, and micxx::StreamSocket.

virtual void micxx::Mutex::unlock ( ) [virtual]

Release the lock from this Mutex.

Note:
As long as getLockCount() is greater than 0, this Mutex is still locked by the calling thread.
For each call to lock() from the same thread, there must be an associated call to unlock(). Otherwise the lock will not be unlocked and ready to be obtained from other threads that are waiting for this lock.

Member Data Documentation

unsigned micxx::Mutex::lockCount [protected]

The number of (recursive) locks that have been obtained by the same thread.

See also:
getLockCount()
pthread_mutex_t micxx::Mutex::mutex [protected]
pthread_t micxx::Mutex::ownerId [protected]

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