Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
#include <MutexLock.h>
Inheritance diagram for MutexLock< num_doors >:
Use this to prevent more than one process from accessing a data structure at the same time (which often leads to unpredictable and unexpected results)
The template parameter specifies the maximum number of different processes which need to be protected. This needs to be allocated ahead of time, as there doesn't seem to be a way to dynamically scale as needed without risking possible errors if two processes are both trying to set up at the same time. Also, by using a template parameter, all data structures are contained within the class's memory allocation, so no pointers are involved.
Locks in this class can be recursive. If you lock 5 times and then unlock() once, the lock is released. If you want to have releases match locks, call release() instead of unlock().
Note that there is no check that the process doing the unlocking is the one that actually has the lock. Be careful about this.
Definition at line 36 of file MutexLock.h.
Public Member Functions | |
MutexLock () | |
constructor, just calls the init() function. | |
void | lock (int id) |
blocks (by busy looping on do_try_lock()) until a lock is achieved | |
bool | try_lock (int id) |
attempts to get a lock, returns true if it succeeds | |
void | release () |
releases one recursive lock-level from whoever has the current lock | |
void | unlock () |
completely unlocks, regardless of how many times a recursive lock has been obtained | |
unsigned int | get_lock_level () const |
returns the lockcount | |
int | owner () |
returns the current owner's id | |
void | forget (int id) |
allows you to reset one of the possible owners, so another process can take its place. This is not tested | |
Static Public Attributes | |
const unsigned int | NO_OWNER = -1U |
marks as unlocked | |
Protected Member Functions | |
bool | do_try_lock (unsigned int index, bool block) |
Does the work of trying to get a lock. | |
unsigned int | lookup (int id) |
returns the internal index mapping to the id number supplied by the process | |
void | init () |
Doesn't do anything if you have the MUTEX_LOCK_ET_USE_SPINCOUNT undef'ed. Used to do a memset, but that was causing problems.... | |
void | spin () |
If you find a way to sleep for a few microseconds instead of busy waiting, put it here. | |
Protected Attributes | |
door_t | doors [num_doors] |
holds all the doors | |
unsigned int | doors_used |
counts the number of doors used | |
unsigned int | owner_index |
holds the door index of the current lock owner | |
unsigned int | lockcount |
the depth of the lock, 0 when unlocked |
|
constructor, just calls the init() function.
Definition at line 41 of file MutexLock.h. |
|
Does the work of trying to get a lock.
Pass Definition at line 166 of file MutexLock.h. References MutexLock< num_doors >::doors, MutexLock< num_doors >::door_t::FCFS_in_use, mutexdebugout, MutexLock< num_doors >::NO_OWNER, MutexLock< num_doors >::owner_index, MutexLock< num_doors >::spin(), and MutexLock< num_doors >::door_t::turn. |
|
allows you to reset one of the possible owners, so another process can take its place. This is not tested
Definition at line 245 of file MutexLock.h. References MutexLock< num_doors >::do_try_lock(), MutexLock< num_doors >::doors, MutexLock< num_doors >::doors_used, MutexLock< num_doors >::door_t::id, MutexLock< num_doors >::lookup(), MutexLock< num_doors >::NO_OWNER, and MutexLock< num_doors >::release(). |
|
returns the lockcount
Definition at line 67 of file MutexLock.h. |
|
Doesn't do anything if you have the MUTEX_LOCK_ET_USE_SPINCOUNT undef'ed. Used to do a memset, but that was causing problems....
Definition at line 94 of file MutexLock.h. |
|
blocks (by busy looping on do_try_lock()) until a lock is achieved You should pass some process-specific ID number as the input - just make sure no other process will be using the same value. This is not a recursive lock - repeated locks still only require one release to undo them.
Definition at line 120 of file MutexLock.h. References MutexLock< num_doors >::do_try_lock(), MutexLock< num_doors >::lockcount, MutexLock< num_doors >::lookup(), MutexLock< num_doors >::owner(), and MutexLock< num_doors >::spin(). |
|
returns the internal index mapping to the id number supplied by the process
Definition at line 226 of file MutexLock.h. References MutexLock< num_doors >::doors, MutexLock< num_doors >::doors_used, MutexLock< num_doors >::door_t::id, and MutexLock< num_doors >::NO_OWNER. |
|
returns the current owner's id
Definition at line 70 of file MutexLock.h. |
|
releases one recursive lock-level from whoever has the current lock
Definition at line 146 of file MutexLock.h. References MutexLock< num_doors >::door_t::BL_in_use, MutexLock< num_doors >::door_t::BL_ready, MutexLock< num_doors >::doors, MutexLock< num_doors >::lockcount, MutexLock< num_doors >::NO_OWNER, and MutexLock< num_doors >::owner_index. |
|
If you find a way to sleep for a few microseconds instead of busy waiting, put it here.
Definition at line 96 of file MutexLock.h. |
|
attempts to get a lock, returns true if it succeeds You should pass some process-specific ID number as the input - just make sure no other process will be using the same value. This is not a recursive lock - repeated locks still only require one release to undo them. Definition at line 130 of file MutexLock.h. References MutexLock< num_doors >::do_try_lock(), MutexLock< num_doors >::lockcount, MutexLock< num_doors >::lookup(), and MutexLock< num_doors >::owner(). |
|
completely unlocks, regardless of how many times a recursive lock has been obtained
Definition at line 64 of file MutexLock.h. |
|
holds all the doors
Definition at line 111 of file MutexLock.h. |
|
counts the number of doors used
Definition at line 112 of file MutexLock.h. |
|
the depth of the lock, 0 when unlocked
Definition at line 114 of file MutexLock.h. |
|
marks as unlocked
Definition at line 38 of file MutexLock.h. |
|
holds the door index of the current lock owner
Definition at line 113 of file MutexLock.h. |
Tekkotsu v1.4 |
Generated Sat Jul 19 00:09:04 2003 by Doxygen 1.3.2 |