CSemaphore Class Reference
[Threads]

Search Toolkit Book for CSemaphore

#include <ncbimtx.hpp>

Collaboration diagram for CSemaphore:

Collaboration graph
[legend]
List of all members.

Detailed Description

CSemaphore --.

Implement the semantics of an application-wide semaphore.

Definition at line 1304 of file ncbimtx.hpp.

Public Member Functions

 CSemaphore (unsigned int init_count, unsigned int max_count)
 Constructor.
 ~CSemaphore (void)
 Destructor.
void Wait (void)
 Wait on semaphore.
bool TryWait (unsigned int timeout_sec=0, unsigned int timeout_nsec=0)
 Timed wait.
void Post (unsigned int count=1)
 Increment the semaphore by "count".

Private Member Functions

 CSemaphore (const CSemaphore &)
 Private copy constructor to disallow initialization.
CSemaphoreoperator= (const CSemaphore &)
 Private assignment operator to disallow assignment.

Private Attributes

SSemaphorem_Sem
 System-specific semaphore data.


Constructor & Destructor Documentation

CSemaphore::CSemaphore unsigned int  init_count,
unsigned int  max_count
 

Constructor.

Parameters:
int_count The initial value of the semaphore. max_count Maximum value that semaphore value can be incremented to.

Definition at line 1014 of file ncbimtx.cpp.

References SSemaphore::count, m_Sem, SSemaphore::max_count, auto_ptr< X >::release(), and xncbi_Validate.

CSemaphore::~CSemaphore void   ) 
 

Destructor.

Report error if the semaphore is locked.

Definition at line 1064 of file ncbimtx.cpp.

References _ASSERT, m_Sem, and xncbi_Verify.

CSemaphore::CSemaphore const CSemaphore  )  [private]
 

Private copy constructor to disallow initialization.


Member Function Documentation

CSemaphore& CSemaphore::operator= const CSemaphore  )  [private]
 

Private assignment operator to disallow assignment.

void CSemaphore::Post unsigned int  count = 1  ) 
 

Increment the semaphore by "count".

Do nothing and throw an exception if counter would exceed "max_count".

Definition at line 1216 of file ncbimtx.cpp.

References _TROUBLE, SSemaphore::count, kMax_UInt, m_Sem, SSemaphore::max_count, and xncbi_Validate.

Referenced by CPrefetchTokenOld_Impl::AddResolvedId(), CNCFileSystem::Finalize(), CBlockingQueue< TRequest >::GetHandle(), CGridWorkerNode::LeaveExclusiveMode(), CGridCleanupThread::Main(), CPrefetchTokenOld_Impl::NextBioseqHandle(), CScheduler_ExecThread_Impl::OnNextExecutionTimeChange(), CNCMMCentral::PrepareToStop(), CBlockingQueue< TRequest >::Put(), CPrefetchTokenOld_Impl::RemoveTokenReference(), CThreadNonStop::RequestDoJob(), CWorkerNodeIdleThread::RequestShutdown(), CThreadNonStop::RequestStop(), CReadPipeThread::RequestStop(), CWorkerNodeIdleThread::Schedule(), CScheduler_ExecThread_Impl::Stop(), CBDB_Cache::StopPurge(), CWorkerNodeIdleThread::Suspend(), CThreadPool_Impl::TaskFinished(), CThreadPool_Impl::ThreadStateChanged(), CGridWorkerNode::WaitForExclusiveJobToFinish(), CBlockingQueue< TRequest >::WaitForHunger(), CBlockingQueue< TRequest >::WaitForRoom(), CThreadPool_ThreadImpl::WakeUp(), CThreadPool_ServiceThread::WakeUp(), CNCFileSystem::x_AddNewEvent(), CNCFileSystem::x_DoBackgroundWork(), CReader::x_ReleaseConnection(), CSyncQueue< Type, Container >::x_Unlock(), and CNCBlobStorage::~CNCBlobStorage().

bool CSemaphore::TryWait unsigned int  timeout_sec = 0,
unsigned int  timeout_nsec = 0
 

Timed wait.

Wait up to timeout_sec + timeout_nsec/1E9 seconds for the semaphore's count to exceed zero. If that happens, decrement the counter by one and return TRUE; otherwise, return FALSE.

Definition at line 1127 of file ncbimtx.cpp.

References SSemaphore::count, kMax_Int, m_Sem, and xncbi_Validate.

Referenced by CGridWorkerNode::EnterExclusiveMode(), CBlockingQueue< TRequest >::GetHandle(), CThreadNonStop::Main(), CScheduler_ExecThread_Impl::Main(), CReadPipeThread::Main(), CWorkerNodeIdleThread::Main(), CBlockingQueue< TRequest >::Put(), CGridCleanupThread::Wait(), CGridWorkerNode::WaitForExclusiveJobToFinish(), CNCBlobStorage::x_DoBackgroundWork(), CNCMMCentral::x_DoBackgroundWork(), CNCBlobStorage::x_GC_CleanDBVolume(), CSyncQueue< Type, Container >::x_Lock(), CThreadPool_Impl::x_WaitForPredicate(), and CBlockingQueue< TRequest >::x_WaitForPredicate().

void CSemaphore::Wait void   ) 
 

Wait on semaphore.

Decrement the counter by one. If the semaphore's count is zero then wait until it's not zero.

Definition at line 1079 of file ncbimtx.cpp.

References SSemaphore::count, m_Sem, and xncbi_Validate.

Referenced by CNCFileSystem::WriteToFile(), CReader::x_AllocConnection(), CThreadPool_ThreadImpl::x_Idle(), CSyncQueue< Type, Container >::x_Lock(), CThreadPool_ServiceThread::x_WaitForPoolStop(), and CThreadPool_Impl::x_WaitForPredicate().


Member Data Documentation

struct SSemaphore* CSemaphore::m_Sem [private]
 

System-specific semaphore data.

Definition at line 1338 of file ncbimtx.hpp.

Referenced by CSemaphore(), Post(), TryWait(), Wait(), and ~CSemaphore().


The documentation for this class was generated from the following files:
Generated on Mon Dec 7 14:01:41 2009 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Mon Dec 07 16:23:55 2009 by modify_doxy.py rev. 173732