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

An optimized and convertable shared lock. More...

#include <thread.h>

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

Public Member Functions

void access (void)
 Acquire access (shared read) lock.
void commit (void)
 Commit changes / release a modify lock.
 ConditionalLock ()
 Construct conditional lock for default concurrency.
void exclusive (void)
 Convert read lock into exclusive (write/modify) access.
unsigned getReaders (void)
 Get the number of threads reading (sharing) the lock.
unsigned getWaiters (void)
 Get the number of threads waiting to share the lock.
void modify (void)
 Acquire write (exclusive modify) lock.
void release (void)
 Release a shared lock.
void share (void)
 Return an exclusive access lock back to share mode.
 ~ConditionalLock ()
 Destroy conditional lock.
- Public Member Functions inherited from ucommon::SharedProtocol
void Lock (void)
 A convenience member function for accessing the shared lock.

Static Public Member Functions

static void access (ConditionalLock &lock)
 Convenience function to aqcuire a shared lock.
static void commit (ConditionalLock &lock)
 Convenience function to commit a modify lock.
static void exclusive (ConditionalLock &lock)
 Convenience function to convert lock to exclusive mode.
static void modify (ConditionalLock &lock)
 Convenience function to modify lock.
static void release (ConditionalLock &lock)
 Convenience function to release a shared lock.
static void share (ConditionalLock &lock)
 Convenience function to convert lock to shared access.

Protected Member Functions

void Exclusive (void)
 Convert object to an exclusive lock.
Context * getContext (void)
void Share (void)
 Share the lock with other referencers.
void Shlock (void)
 Protocol interface to share lock the object.
void Unlock (void)
 Protocol interface to release a lock.
- Protected Member Functions inherited from ucommon::ConditionalAccess
 ConditionalAccess ()
 Initialize and construct conditional.
void limit_sharing (unsigned max)
 Specify a maximum sharing (access) limit.
 ~ConditionalAccess ()
 Destroy conditional, release any blocked threads.
void broadcast (void)
 Signal the conditional to release all broadcast threads.
void lock (void)
 Lock the conditional's supporting mutex.
void signal (void)
 Signal the conditional to release one signalled thread.
void unlock (void)
 Unlock the conditional's supporting mutex.
bool waitBroadcast (timeout_t timeout)
 Conditional wait for broadcast on millisecond timeout.
bool waitBroadcast (struct timespec *timeout)
 Conditional wait for broadcast on timespec timeout.
void waitBroadcast (void)
 Wait (block) until broadcast.
bool waitSignal (timeout_t timeout)
 Conditional wait for signal on millisecond timeout.
bool waitSignal (struct timespec *timeout)
 Conditional wait for signal on timespec timeout.
void waitSignal (void)
 Wait (block) until signalled.

Protected Attributes

LinkedObjectcontexts

Additional Inherited Members


Detailed Description

An optimized and convertable shared lock.

This is a form of read/write lock that has been optimized, particularly for shared access. Support for scheduling access around writer starvation is also included. The other benefits over traditional read/write locks is that the code is a little lighter, and read (shared) locks can be converted to exclusive (write) locks to perform brief modify operations and then returned to read locks, rather than having to release and re-aquire locks to change mode.

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

Definition at line 806 of file thread.h.


Member Function Documentation

static void ucommon::ConditionalLock::access ( ConditionalLock lock)
inlinestatic

Convenience function to aqcuire a shared lock.

Parameters:
lockto share.

Definition at line 903 of file thread.h.

Here is the call graph for this function:

static void ucommon::ConditionalLock::commit ( ConditionalLock lock)
inlinestatic

Convenience function to commit a modify lock.

Parameters:
lockto commit.

Definition at line 889 of file thread.h.

Here is the call graph for this function:

void ucommon::ConditionalLock::Exclusive ( void  )
protectedvirtual

Convert object to an exclusive lock.

Many of our shared locking objects such as the "conditional lock" support the ability to switch between shared and exclusive locking modes. This derived protocol member allows one to temporarily assert exclusive locking when tied to such methods.

Reimplemented from ucommon::SharedProtocol.

void ucommon::ConditionalLock::exclusive ( void  )

Convert read lock into exclusive (write/modify) access.

Schedule when other readers sharing.

static void ucommon::ConditionalLock::exclusive ( ConditionalLock lock)
inlinestatic

Convenience function to convert lock to exclusive mode.

Parameters:
lockto convert.

Definition at line 910 of file thread.h.

Here is the call graph for this function:

static void ucommon::ConditionalLock::modify ( ConditionalLock lock)
inlinestatic

Convenience function to modify lock.

Parameters:
lockto acquire in write exclusive mode.

Definition at line 882 of file thread.h.

Here is the call graph for this function:

static void ucommon::ConditionalLock::release ( ConditionalLock lock)
inlinestatic

Convenience function to release a shared lock.

Parameters:
lockto release.

Definition at line 896 of file thread.h.

Here is the call graph for this function:

void ucommon::ConditionalLock::Share ( void  )
protectedvirtual

Share the lock with other referencers.

Many of our shared locking objects support the ability to switch between shared and exclusive mode. This derived protocol member allows one to restore the lock to shared mode after it has been made exclusive.

Reimplemented from ucommon::SharedProtocol.

static void ucommon::ConditionalLock::share ( ConditionalLock lock)
inlinestatic

Convenience function to convert lock to shared access.

Parameters:
lockto convert.

Definition at line 917 of file thread.h.

Here is the call graph for this function:


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