NCBI C++ ToolKit
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CFutex Class Reference

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 &)
 
CFutexoperator= (const CFutex &)
 

Private Attributes

volatile int m_Value
 Value of the futex. More...
 

Detailed Description

Wrapper around Linux's futex.

Definition at line 140 of file srv_sync.hpp.

Member Enumeration Documentation

◆ 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.

Constructor & Destructor Documentation

◆ CFutex() [1/2]

CFutex::CFutex ( void  )
inline

Definition at line 233 of file srv_sync.hpp.

◆ CFutex() [2/2]

CFutex::CFutex ( const CFutex )
private

Member Function Documentation

◆ AddValue()

int CFutex::AddValue ( int  cnt_to_add)
inline

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().

◆ ChangeValue()

bool CFutex::ChangeValue ( int  old_value,
int  new_value 
)
inline

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().

◆ GetValue()

int CFutex::GetValue ( void  )
inline

◆ operator=()

CFutex& CFutex::operator= ( const CFutex )
private

◆ SetValueNonAtomic()

void CFutex::SetValueNonAtomic ( int  new_value)
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().

◆ WaitValueChange() [1/2]

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().

◆ WaitValueChange() [2/2]

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.

◆ WakeUpWaiters()

int CFutex::WakeUpWaiters ( int  cnt_to_wake)

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.

References m_Value, and NULL.

Referenced by s_AddTaskToQueue(), s_CheckFatalAbort(), and CMiniMutex::Unlock().

Member Data Documentation

◆ m_Value

volatile int CFutex::m_Value
private

Value of the futex.

Definition at line 186 of file srv_sync.hpp.

Referenced by AddValue(), ChangeValue(), GetValue(), SetValueNonAtomic(), WaitValueChange(), and WakeUpWaiters().


The documentation for this class was generated from the following files:
Modified on Fri Sep 20 14:56:58 2024 by modify_doxy.py rev. 669887