NCBI C++ ToolKit
|
Search Toolkit Book for CFutex
Wrapper around Linux's futex. More...
#include "srv_sync.hpp"
(Private to src/app/netcache
.)
Public Types | |
enum | EWaitResult { eWaitWokenUp , eValueChanged , eTimedOut } |
Type of result returned from WaitValueChange() More... | |
Public Member Functions | |
CFutex (void) | |
int | GetValue (void) |
Read value of the futex. More... | |
bool | ChangeValue (int old_value, int new_value) |
Atomically change value of the futex. More... | |
int | AddValue (int cnt_to_add) |
Atomically add some amount to futex's value. More... | |
void | SetValueNonAtomic (int new_value) |
Set futex's value non-atomically, i.e. More... | |
EWaitResult | WaitValueChange (int old_value) |
Wait for futex's value to change (with and without timeout). More... | |
EWaitResult | WaitValueChange (int old_value, const CSrvTime &timeout) |
int | WakeUpWaiters (int cnt_to_wake) |
Wake up some threads waiting on this futex. More... | |
Private Member Functions | |
CFutex (const CFutex &) | |
CFutex & | operator= (const CFutex &) |
Private Attributes | |
volatile int | m_Value |
Value of the futex. More... | |
Wrapper around Linux's futex.
Definition at line 140 of file srv_sync.hpp.
enum CFutex::EWaitResult |
Type of result returned from WaitValueChange()
Enumerator | |
---|---|
eWaitWokenUp | Thread was woken up by call to WakeUpWaiters() from another thread. |
eValueChanged | Futex's value was changed in another thread before waiting was started. |
eTimedOut | Method returned because total waiting time exceeded given timeout. |
Definition at line 162 of file srv_sync.hpp.
|
inline |
Definition at line 233 of file srv_sync.hpp.
Atomically add some amount to futex's value.
Result of addition is returned.
Definition at line 250 of file srv_sync.hpp.
References AtomicAdd(), and m_Value.
Referenced by CMiniMutex::Lock(), s_CheckFatalAbort(), s_DoFatalAbort(), and CMiniMutex::Unlock().
Atomically change value of the futex.
If current futex value was changed in another thread and doesn't match old_value then method returns FALSE and value is not changed. Otherwise value is changed to new_value and method returns TRUE.
Definition at line 244 of file srv_sync.hpp.
References AtomicCAS(), and m_Value.
Referenced by CMiniMutex::TryLock().
|
inline |
Read value of the futex.
Definition at line 238 of file srv_sync.hpp.
References m_Value.
Referenced by CMiniMutex::Lock(), s_AddTaskToQueue(), s_DoFatalAbort(), s_FindRebalanceTasks(), s_UnqueueTask(), SchedExecuteTask(), SchedIsAllIdle(), SchedStartJiffy(), CMiniMutex::TryLock(), and CMiniMutex::~CMiniMutex().
|
inline |
Set futex's value non-atomically, i.e.
caller should ensure that several threads don't race with each other with setting different values.
Definition at line 256 of file srv_sync.hpp.
References m_Value.
Referenced by AssignThreadSched(), CMiniMutex::CMiniMutex(), s_AddTaskToQueue(), s_BalanceTasks(), and s_UnqueueTask().
CFutex::EWaitResult CFutex::WaitValueChange | ( | int | old_value | ) |
Wait for futex's value to change (with and without timeout).
Thread won't wake up automatically when value has changed – thread changing it should call WakeUpWaiters().
Definition at line 44 of file srv_sync.cpp.
References eValueChanged, eWaitWokenUp, m_Value, and NULL.
Referenced by CMiniMutex::Lock(), s_CheckFatalAbort(), s_DoFatalAbort(), s_ServiceThreadMain(), and SchedExecuteTask().
CFutex::EWaitResult CFutex::WaitValueChange | ( | int | old_value, |
const CSrvTime & | timeout | ||
) |
Definition at line 60 of file srv_sync.cpp.
References CSrvTime::Current(), eTimedOut, eValueChanged, eWaitWokenUp, m_Value, NULL, and start_time.
Wake up some threads waiting on this futex.
cnt_to_wake is the maximum number of threads to wake.
Definition at line 98 of file srv_sync.cpp.
Referenced by s_AddTaskToQueue(), s_CheckFatalAbort(), and CMiniMutex::Unlock().
|
private |
Value of the futex.
Definition at line 186 of file srv_sync.hpp.
Referenced by AddValue(), ChangeValue(), GetValue(), SetValueNonAtomic(), WaitValueChange(), and WakeUpWaiters().