ACE_Process_Semaphore Class Reference

Wrapper for Dijkstra style general semaphores that work across processes. More...

#include <Process_Semaphore.h>

Collaboration diagram for ACE_Process_Semaphore:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_Process_Semaphore (u_int count=1, const ACE_TCHAR *name=0, void *=0, int max=0x7FFFFFFF)
int remove (void)
int acquire (void)
int tryacquire (void)
int release (void)
 Increment the semaphore, potentially unblocking a waiting thread.
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.

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

Protected Attributes

ACE_SV_Semaphore_Complex lock_
 We need this to get the right semantics...

Detailed Description

Wrapper for Dijkstra style general semaphores that work across processes.

Definition at line 41 of file Process_Semaphore.h.


Constructor & Destructor Documentation

ACE_Process_Semaphore::ACE_Process_Semaphore ( u_int  count = 1,
const ACE_TCHAR name = 0,
void *  = 0,
int  max = 0x7FFFFFFF 
)

Initialize the semaphore, with an initial value of count and a maximum value of max.

Definition at line 28 of file Process_Semaphore.cpp.

00033   : lock_ (count, USYNC_PROCESS, name, arg, max)
00034 #else
00035   : lock_ (ACE_TEXT_ALWAYS_CHAR (name),
00036            ACE_SV_Semaphore_Complex::ACE_CREATE,
00037            count)
00038 #endif /* ACE_WIN32 || ACE_HAS_POSIX_SEM */
00039 {
00040   ACE_UNUSED_ARG (arg);
00041   ACE_UNUSED_ARG (max);
00042 // ACE_TRACE ("ACE_Process_Semaphore::ACE_Process_Semaphore");
00043 }


Member Function Documentation

int ACE_Process_Semaphore::acquire ( void   ) 

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

Definition at line 58 of file Process_Semaphore.cpp.

References ACE_SV_Semaphore_Complex::acquire(), lock_, and SEM_UNDO.

Referenced by acquire_read(), and acquire_write().

00059 {
00060 // ACE_TRACE ("ACE_Process_Semaphore::acquire");
00061 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
00062   return this->lock_.acquire ();
00063 #else
00064   return this->lock_.acquire (0, SEM_UNDO);
00065 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
00066 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE int ACE_Process_Semaphore::acquire_read ( void   ) 

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

Definition at line 21 of file Process_Semaphore.inl.

References acquire().

00022 {
00023   return this->acquire ();
00024 }

ACE_INLINE int ACE_Process_Semaphore::acquire_write ( void   ) 

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

Definition at line 31 of file Process_Semaphore.inl.

References acquire().

00032 {
00033   return this->acquire ();
00034 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL void ACE_Process_Semaphore::dump ( void   )  const

Dump the state of an object.

Definition at line 18 of file Process_Semaphore.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, and LM_DEBUG.

00019 {
00020 #if defined (ACE_HAS_DUMP)
00021 // ACE_TRACE ("ACE_Process_Semaphore::dump");
00022   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00023   this->lock_.dump ();
00024   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00025 #endif /* ACE_HAS_DUMP */
00026 }

int ACE_Process_Semaphore::release ( void   ) 

Increment the semaphore, potentially unblocking a waiting thread.

Definition at line 86 of file Process_Semaphore.cpp.

References lock_, ACE_SV_Semaphore_Complex::release(), and SEM_UNDO.

00087 {
00088 // ACE_TRACE ("ACE_Process_Semaphore::release");
00089 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
00090   return this->lock_.release ();
00091 #else
00092   return this->lock_.release (0, SEM_UNDO);
00093 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
00094 }

int ACE_Process_Semaphore::remove ( void   ) 

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

Definition at line 48 of file Process_Semaphore.cpp.

References lock_, and ACE_SV_Semaphore_Simple::remove().

00049 {
00050 // ACE_TRACE ("ACE_Process_Semaphore::remove");
00051   return this->lock_.remove ();
00052 }

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

Definition at line 72 of file Process_Semaphore.cpp.

References lock_, SEM_UNDO, and ACE_SV_Semaphore_Complex::tryacquire().

Referenced by tryacquire_read(), and tryacquire_write().

00073 {
00074 // ACE_TRACE ("ACE_Process_Semaphore::tryacquire");
00075 #if defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM)
00076   return this->lock_.tryacquire ();
00077 #else
00078   return this->lock_.tryacquire (0, SEM_UNDO);
00079 #endif /* defined (ACE_WIN32) || defined (ACE_HAS_POSIX_SEM) */
00080 }

ACE_INLINE int ACE_Process_Semaphore::tryacquire_read ( void   ) 

Conditionally acquire semaphore (i.e., won't block). This calls <tryacquire> and is only here to make the ACE_Process_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.

Definition at line 41 of file Process_Semaphore.inl.

References tryacquire().

00042 {
00043   return this->tryacquire ();
00044 }

ACE_INLINE int ACE_Process_Semaphore::tryacquire_write ( void   ) 

Conditionally acquire semaphore (i.e., won't block). This calls <tryacquire> and is only here to make the ACE_Process_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.

Definition at line 51 of file Process_Semaphore.inl.

References tryacquire().

00052 {
00053   return this->tryacquire ();
00054 }

ACE_INLINE int ACE_Process_Semaphore::tryacquire_write_upgrade ( void   ) 

This is only here to make the ACE_Process_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.

Definition at line 61 of file Process_Semaphore.inl.

00062 {
00063   return 0;
00064 }


Member Data Documentation

ACE_Process_Semaphore::ACE_ALLOC_HOOK_DECLARE

Declare the dynamic allocation hooks.

Definition at line 122 of file Process_Semaphore.h.

ACE_SV_Semaphore_Complex ACE_Process_Semaphore::lock_ [protected]

We need this to get the right semantics...

Definition at line 129 of file Process_Semaphore.h.

Referenced by acquire(), release(), remove(), and tryacquire().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:27 2010 for ACE by  doxygen 1.4.7