Class shared_memory::LockedConditionVariable¶
-
class shared_memory::LockedConditionVariable¶
The LockedConditionVariable class is here as a anonymous layer on top of the boost intersprocess condition variable labrary.
It creates a condition variable in a shared memory automatically.
Public Functions
-
LockedConditionVariable(const std::string object_id, bool clean_memory_on_destruction = true)¶
A condition variable shared over the memory The condition variable is cleaned from the memory on destruction if clean_memory_on_destruction is set to true.
Contrary to shared_memory::ConditionVariable, instances of this class manages their mutex and lock internally, with the consequence the mutex can be locked and unlocked exclusively through other instances of LockedConditionVariable.
-
~LockedConditionVariable()¶
-
void notify_all()¶
notify_all is notifying all condition variables with the same mutex
-
void notify_one()¶
notify_one notifies one condition variable with the same mutex
-
void wait()¶
wait waits until another thread notifies this object
-
bool timed_wait(long wait_nano_seconds)¶
timed_wait wait a notify during a certain certain time and then wake up
- Parameters
wait_duration – in microsecond
- Returns
true: the condition variable has been notified, false otherwize
-
bool try_lock()¶
try_lock Tries to acquire the lock without waiting.
- Throws
- Returns
true if manages to acquire the lock, false otherwise.
-
void unlock()¶
unlock Unlocks the lock.
- Throws
-
bool owns()¶
-
void lock_scope()¶
lock_scope this function is used to lock the part of the code that needs protection.
It locks the mutex until unlock_scope is used
-
void unlock_scope()¶
unlock_scope this function unlock the mutex so remove the protection of the code
Public Members
-
SHMCondition *condition_variable_¶
condition_variable_ is the boost condition variable that is used
-
std::unique_ptr<SHMScopeLock> lock_¶
lock_ is a object that protects the codes with a mutex, see the boost documentation about “boost::interprocess::scoped_lock”
-
bool clean_memory_on_destruction_¶
if true (the default), clean the shared memory of the hosted mutex and condition.
Public Static Functions
-
static void clean(const std::string segment_id)¶
LockedConditionVariable clean their shared memory on destruction.
But the destructor may have failed to be called if for some reason the program crashed.
Private Members
-
std::string mutex_id_¶
mutex_id_ is the mutex name in the shared memory
-
std::string condition_id_¶
condition_id_ is the condition variable name in the shared memory
-
boost::interprocess::managed_shared_memory segment_manager_¶
shm_segment is the boost object that manages the shared memory segment
-
LockedConditionVariable(const std::string object_id, bool clean_memory_on_destruction = true)¶