ACE 8.0.1
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | Private Member Functions | List of all members
ACE_Semaphore Class Reference

Wrapper for Dijkstra style general semaphores. More...

#include <Semaphore.h>

Inheritance diagram for ACE_Semaphore:
Inheritance graph
[legend]

Public Member Functions

 ACE_Semaphore (unsigned int count=1, int type=USYNC_THREAD, const ACE_TCHAR *name=0, void *=0, int max=0x7fffffff)
 Initialize the semaphore, with initial value of "count".
 
 ~ACE_Semaphore ()
 Implicitly destroy the semaphore.
 
int remove ()
 
int acquire ()
 
int acquire (ACE_Time_Value &tv)
 
int acquire (ACE_Time_Value *tv)
 
int tryacquire ()
 
int release ()
 
int release (unsigned int release_count)
 
int acquire_read ()
 
int acquire_write ()
 
int tryacquire_read ()
 
int tryacquire_write ()
 
int tryacquire_write_upgrade ()
 
void dump () const
 Dump the state of an object.
 
const ACE_sema_tlock () const
 Return the underlying lock.
 

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.
 

Protected Attributes

ACE_sema_t semaphore_
 
bool removed_
 

Private Member Functions

void operator= (const ACE_Semaphore &)=delete
 
 ACE_Semaphore (const ACE_Semaphore &)=delete
 

Detailed Description

Wrapper for Dijkstra style general semaphores.

Constructor & Destructor Documentation

◆ ACE_Semaphore() [1/2]

ACE_Semaphore::ACE_Semaphore ( unsigned int count = 1,
int type = USYNC_THREAD,
const ACE_TCHAR * name = 0,
void * arg = 0,
int max = 0x7fffffff )

Initialize the semaphore, with initial value of "count".

◆ ~ACE_Semaphore()

ACE_Semaphore::~ACE_Semaphore ( )

Implicitly destroy the semaphore.

◆ ACE_Semaphore() [2/2]

ACE_Semaphore::ACE_Semaphore ( const ACE_Semaphore & )
privatedelete

Member Function Documentation

◆ acquire() [1/3]

int ACE_Semaphore::acquire ( )
inline

Block the thread until the semaphore count becomes greater than 0, then decrement it.

◆ acquire() [2/3]

int ACE_Semaphore::acquire ( ACE_Time_Value & tv)
inline

Block the thread until the semaphore count becomes greater than 0 (at which point it is decremented) or until tv times out (in which case -1 is returned and errno == ETIME). Note that tv is assumed to be in "absolute" rather than "relative" time. The value of tv is updated upon return to show the actual (absolute) acquisition time.

◆ acquire() [3/3]

int ACE_Semaphore::acquire ( ACE_Time_Value * tv)
inline

If tv == 0 then call <acquire()> directly. Otherwise, Block the thread until the semaphore count becomes greater than 0 (at which point it is decremented) or until tv times out (in which case -1 is returned and errno == ETIME). Note that <*tv> is assumed to be in "absolute" rather than "relative" time. The value of <*tv> is updated upon return to show the actual (absolute) acquisition time.

◆ acquire_read()

int ACE_Semaphore::acquire_read ( )
inline

Acquire semaphore ownership. This calls <acquire> and is only here to make the ACE_Semaphore interface consistent with the other synchronization APIs.

◆ acquire_write()

int ACE_Semaphore::acquire_write ( )
inline

Acquire semaphore ownership. This calls <acquire> and is only here to make the ACE_Semaphore interface consistent with the other synchronization APIs.

◆ dump()

void ACE_Semaphore::dump ( ) const

Dump the state of an object.

◆ lock()

const ACE_sema_t & ACE_Semaphore::lock ( ) const
inline

Return the underlying lock.

◆ operator=()

void ACE_Semaphore::operator= ( const ACE_Semaphore & )
privatedelete

◆ release() [1/2]

int ACE_Semaphore::release ( )
inline

Increment the semaphore by 1, potentially unblocking a waiting thread.

◆ release() [2/2]

int ACE_Semaphore::release ( unsigned int release_count)
inline

Increment the semaphore by release_count, potentially unblocking waiting threads.

◆ remove()

int ACE_Semaphore::remove ( )
inline

Explicitly destroy the semaphore. Note that only one thread should call this method since it doesn't protect against race conditions.

◆ tryacquire()

int ACE_Semaphore::tryacquire ( )
inline

Conditionally decrement the semaphore if count is greater than 0 (i.e., won't block). Returns -1 on failure. If we "failed" because someone else already had the lock, errno is set to EBUSY.

◆ tryacquire_read()

int ACE_Semaphore::tryacquire_read ( )
inline

Conditionally acquire semaphore (i.e., won't block). This calls <tryacquire> and is only here to make the ACE_Semaphore interface consistent with the other synchronization APIs. Returns -1 on failure. If we "failed" because someone else already had the lock, errno is set to EBUSY.

◆ tryacquire_write()

int ACE_Semaphore::tryacquire_write ( )
inline

Conditionally acquire semaphore (i.e., won't block). This calls <tryacquire> and is only here to make the ACE_Semaphore interface consistent with the other synchronization APIs. Returns -1 on failure. If we "failed" because someone else already had the lock, errno is set to EBUSY.

◆ tryacquire_write_upgrade()

int ACE_Semaphore::tryacquire_write_upgrade ( )
inline

This is only here to make the ACE_Semaphore interface consistent with the other synchronization APIs. Assumes the caller has already acquired the semaphore using one of the above calls, and returns 0 (success) always.

Member Data Documentation

◆ ACE_ALLOC_HOOK_DECLARE

ACE_Semaphore::ACE_ALLOC_HOOK_DECLARE

Declare the dynamic allocation hooks.

◆ removed_

bool ACE_Semaphore::removed_
protected

Keeps track of whether remove() has been called yet to avoid multiple remove() calls, e.g., explicitly and implicitly in the destructor. This flag isn't protected by a lock, so make sure that you don't have multiple threads simultaneously calling remove () on the same object, which is a bad idea anyway...

◆ semaphore_

ACE_sema_t ACE_Semaphore::semaphore_
protected

The documentation for this class was generated from the following files: