|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
Recursive mutual-exclusion lock, optionally named for cross-process use. More...
#include <Utils.h>
Public Member Functions | |
| Mutex () | |
| Create an anonymous, process-local mutex. | |
| Mutex (const char *name, bool force=false) | |
| Create or open a named, cross-process mutex. | |
| ~Mutex () | |
| bool | enter () |
| Block until the mutex is acquired. | |
| bool | enter (uint32 timeout, const char *errorMsg=NULL) |
| Acquire with a timeout. | |
| bool | leave () |
| Release the mutex. | |
Protected Attributes | |
| char * | name |
| bool | created |
| uint32 | osid |
| uint32 | total |
| uint32 | count |
| pthread_mutex_t * | mutex |
Recursive mutual-exclusion lock, optionally named for cross-process use.
Unnamed mutexes are process-local; named mutexes are created in shared memory / as kernel objects so multiple processes can synchronize on the same name. Prefer the timeout overload of enter() in production code so a dead peer cannot deadlock the caller forever.
| cmlabs::utils::Mutex::Mutex | ( | ) |
| cmlabs::utils::Mutex::Mutex | ( | const char * | name, |
| bool | force = false ) |
Create or open a named, cross-process mutex.
| name | Global name (namespaced by the shared system instance). |
| force | Re-initialize the underlying object even if it already exists. |
Definition at line 976 of file Utils.cpp.
References count, created, cmlabs::utils::CreateSharedMemorySegment(), FALSE, MAXSHMEMNAMELEN, mutex, MUTEXMEMSIZE, name, cmlabs::utils::OpenSharedMemorySegment(), osid, total, and WINSHMEMSPACE.
| cmlabs::utils::Mutex::~Mutex | ( | ) |
Definition at line 1031 of file Utils.cpp.
References cmlabs::utils::CloseSharedMemorySegment(), created, mutex, MUTEXMEMSIZE, and name.
| bool cmlabs::utils::Mutex::enter | ( | ) |
Block until the mutex is acquired.
Definition at line 1059 of file Utils.cpp.
References count, cmlabs::utils::GetCurrentThreadOSID(), LOG_SYSTEM, LogPrint, mutex, name, osid, and total.
Referenced by cmlabs::PsySpace::emitSignal(), cmlabs::utils::EnterMutex(), cmlabs::ThreadManager::UnitTest(), and cmlabs::PsySpace::waitForSignal().
| bool cmlabs::utils::Mutex::enter | ( | uint32 | timeout, |
| const char * | errorMsg = NULL ) |
Acquire with a timeout.
| timeout | Max wait in milliseconds. |
| errorMsg | Optional label (typically FUNCTION) logged when the wait times out. |
Definition at line 1101 of file Utils.cpp.
References cmlabs::utils::CalcTimeout(), count, cmlabs::utils::GetCurrentThreadOSID(), LOG_SYSTEM, LogPrint, mutex, osid, and total.
| bool cmlabs::utils::Mutex::leave | ( | ) |
Release the mutex.
Definition at line 1204 of file Utils.cpp.
References count, mutex, and osid.
Referenced by cmlabs::PsySpace::emitSignal(), cmlabs::MemoryRequestConnection::shutdown(), cmlabs::ThreadManager::UnitTest(), and cmlabs::PsySpace::waitForSignal().
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |