UCommon
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
ucommon::Mutex Class Reference

Generic non-recursive exclusive lock class. More...

#include <thread.h>

Inheritance diagram for ucommon::Mutex:
Inheritance graph
[legend]
Collaboration diagram for ucommon::Mutex:
Collaboration graph
[legend]

Public Types

typedef autoexclusive< Mutexautolock
 

Public Member Functions

void acquire (void)
 Acquire mutex lock. More...
 
void lock (void)
 Acquire mutex lock. More...
 
 Mutex ()
 Create a mutex lock.
 
void release (void)
 Release acquired lock.
 
void unlock (void)
 Release acquired lock.
 
 ~Mutex ()
 Destroy mutex lock, release waiting threads.
 

Static Public Member Functions

static void acquire (pthread_mutex_t *lock)
 Convenience function to acquire os native mutex lock directly. More...
 
static void indexing (unsigned size)
 Specify hash table size for guard protection. More...
 
static bool protect (const void *pointer)
 Specify pointer/object/resource to guard protect. More...
 
static void release (pthread_mutex_t *lock)
 Convenience function to release os native mutex lock directly. More...
 
static bool release (const void *pointer)
 Specify a pointer/object/resource to release. More...
 

Protected Member Functions

virtual void _lock (void)
 
virtual void _unlock (void)
 

Protected Attributes

pthread_mutex_t mlock
 

Detailed Description

Generic non-recursive exclusive lock class.

This class also impliments the exclusive_lock protocol. In addition, an interface is offered to support dynamically managed mutexes which are internally pooled. These can be used to protect and serialize arbitrary access to memory and objects on demand. This offers an advantage over embedding mutexes to serialize access to individual objects since the maximum number of mutexes will never be greater than the number of actually running threads rather than the number of objects being potentially protected. The ability to hash the pointer address into an indexed table further optimizes access by reducing the chance for collisions on the primary index mutex.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 459 of file thread.h.

Member Function Documentation

◆ acquire() [1/2]

void ucommon::Mutex::acquire ( void  )
inline

Acquire mutex lock.

This is a blocking operation.

Definition at line 486 of file thread.h.

◆ acquire() [2/2]

static void ucommon::Mutex::acquire ( pthread_mutex_t *  lock)
inlinestatic

Convenience function to acquire os native mutex lock directly.

Parameters
lockto acquire.

Definition at line 515 of file thread.h.

◆ indexing()

static void ucommon::Mutex::indexing ( unsigned  size)
static

Specify hash table size for guard protection.

The default is 1. This should be called at initialization time from the main thread of the application before any other threads are created.

Parameters
sizeof hash table used for guarding.

◆ lock()

void ucommon::Mutex::lock ( void  )
inline

Acquire mutex lock.

This is a blocking operation.

Definition at line 493 of file thread.h.

◆ protect()

static bool ucommon::Mutex::protect ( const void *  pointer)
static

Specify pointer/object/resource to guard protect.

This uses a dynamically managed mutex.

Parameters
pointerto protect.

◆ release() [1/2]

static void ucommon::Mutex::release ( pthread_mutex_t *  lock)
inlinestatic

Convenience function to release os native mutex lock directly.

Parameters
lockto release.

Definition at line 523 of file thread.h.

◆ release() [2/2]

static bool ucommon::Mutex::release ( const void *  pointer)
static

Specify a pointer/object/resource to release.

Parameters
pointerto release.

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