Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members Related Pages

# ACE_Semaphore Class Reference

Wrapper for Dijkstra style general semaphores. More...

`#include <Synch.h>`

Inheritance diagram for ACE_Semaphore:

[legend]
List of all members.

## Public Methods
| ACE_Semaphore (u_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". More...
| ~ACE_Semaphore (void)
| Implicitly destroy the semaphore. More...
int | remove (void)
int | acquire (void)
| Block the thread until the semaphore count becomes greater than 0, then decrement it. More...
int | acquire (ACE_Time_Value &tv)
int | acquire (ACE_Time_Value *tv)
int | tryacquire (void)
int | release (void)
| Increment the semaphore by 1, potentially unblocking a waiting thread. More...
int | release (u_int release_count)
| Increment the semaphore by <release_count>, potentially unblocking waiting threads. More...
int | acquire_read (void)
int | acquire_write (void)
int | tryacquire_read (void)
int | tryacquire_write (void)
int | tryacquire_write_upgrade (void)
void | dump (void) const
| Dump the state of an object. More...
const ACE_sema_t & | lock (void) const
| Return the underlying lock. More...
## Public Attributes
| ACE_ALLOC_HOOK_DECLARE
| Declare the dynamic allocation hooks. More...
## Protected Attributes
ACE_sema_t | semaphore_
int | removed_
| 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... More...
## Private Methods
void | operator= (const ACE_Semaphore &)
| ACE_Semaphore (const ACE_Semaphore &)

## Detailed Description

Wrapper for Dijkstra style general semaphores.

## Constructor & Destructor Documentation

ACE_Semaphore::ACE_Semaphore | ( | u_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 | ( | void |  | ) |

| Implicitly destroy the semaphore.

ACE_Semaphore::ACE_Semaphore | ( | const ACE_Semaphore & |  | ) | `[private]`

## Member Function Documentation

ACE_INLINE int ACE_Semaphore::acquire | ( | ACE_Time_Value * | tv | ) |

| 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. NOTE: Solaris threads do not support timed semaphores. Therefore, if you're running on Solaris you might want to consider using the ACE POSIX pthreads implementation instead, which can be enabled by compiling ACE with -DACE_HAS_PTHREADS, rather than -DACE_HAS_STHREADS or -DACE_HAS_POSIX_SEM.

ACE_INLINE int ACE_Semaphore::acquire | ( | ACE_Time_Value & | tv | ) |

| 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. NOTE: Solaris threads do not support timed semaphores. Therefore, if you're running on Solaris you might want to consider using the ACE POSIX pthreads implementation instead, which can be enabled by compiling ACE with -DACE_HAS_PTHREADS, rather than -DACE_HAS_STHREADS or -DACE_HAS_POSIX_SEM.

ACE_INLINE int ACE_Semaphore::acquire | ( | void |  | ) |

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

ACE_INLINE int ACE_Semaphore::acquire_read | ( | void |  | ) |

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

ACE_INLINE int ACE_Semaphore::acquire_write | ( | void |  | ) |

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

void ACE_Semaphore::dump | ( | void |  | ) | const

| Dump the state of an object. Reimplemented in ACE_Thread_Semaphore.

ACE_INLINE const ACE_sema_t & ACE_Semaphore::lock | ( | void |  | ) | const

| Return the underlying lock.

void ACE_Semaphore::operator= | ( | const ACE_Semaphore & |  | ) | `[private]`

ACE_INLINE int ACE_Semaphore::release | ( | u_int | release_count | ) |

| Increment the semaphore by <release_count>, potentially unblocking waiting threads.

ACE_INLINE int ACE_Semaphore::release | ( | void |  | ) |

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

ACE_INLINE int ACE_Semaphore::remove | ( | void |  | ) |

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

ACE_INLINE int ACE_Semaphore::tryacquire | ( | void |  | ) |

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

ACE_INLINE int ACE_Semaphore::tryacquire_read | ( | void |  | ) |

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

ACE_INLINE int ACE_Semaphore::tryacquire_write | ( | void |  | ) |

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

ACE_INLINE int ACE_Semaphore::tryacquire_write_upgrade | ( | void |  | ) |

| 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_Semaphore::ACE_ALLOC_HOOK_DECLARE

| Declare the dynamic allocation hooks. Reimplemented in ACE_Thread_Semaphore.

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

ACE_sema_t ACE_Semaphore::semaphore_`[protected]`

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

- Synch.h
- Synch.cpp
- Synch.i