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

ACE_Process_Mutex Class Reference

A wrapper for mutexes that can be used across processes on the same host machine, as well as within a process, of course. More...

#include <Process_Mutex.h>

Collaboration diagram for ACE_Process_Mutex:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_Process_Mutex (const char *name=0, void *arg=0, mode_t mode=ACE_DEFAULT_FILE_PERMS)
 ACE_Process_Mutex (const wchar_t *name, void *arg=0, mode_t mode=ACE_DEFAULT_FILE_PERMS)
 ~ACE_Process_Mutex (void)
int remove (void)
int acquire (void)
int acquire (ACE_Time_Value &tv)
int tryacquire (void)
int release (void)
 Release lock and unblock a thread at head of queue. More...

int acquire_read (void)
 Acquire lock ownership (wait on queue if necessary). More...

int acquire_write (void)
 Acquire lock ownership (wait on queue if necessary). More...

int tryacquire_read (void)
int tryacquire_write (void)
int tryacquire_write_upgrade (void)
const ACE_mutex_t & lock (void) const
 Return the underlying mutex. More...

void dump (void) const
 Dump the state of an object. More...


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Private Methods

const ACE_TCHARunique_name (void)
 Create and return the unique name. More...


Private Attributes

ACE_TCHAR name_ [ACE_UNIQUE_NAME_LEN]
 If the user does not provide a name we generate a unique name in this buffer. More...

ACE_Mutex lock_

Detailed Description

A wrapper for mutexes that can be used across processes on the same host machine, as well as within a process, of course.

Attention:
The mechanism upon which ACE_Process_Mutex is based can be configured at build time to be either ACE_SV_Semaphore_Complex (on platforms that support it) or ACE_Mutex. On platforms that require interprocess mutexes be allocated from shared memory (Pthreads and UI Threads are examples), ACE_SV_Semaphore_Complex provides a more reliable mechanism for implementing inter-process mutex than ACE_Mutex. However, at least on some platforms, ACE_SV_Semaphore_Complex is limited to a small number of objects by the underlying System V IPC kernel parameters. If you want to force use of ACE_Mutex as the underlying mechanism, set ACE_USES_MUTEX_FOR_PROCESS_MUTEX in your config.h file. Also, if you require the ability to do a timed acquire(), you must set ACE_USES_MUTEX_FOR_PROCESS_MUTEX, as timed acquire does not work with System V semaphores.

Definition at line 61 of file Process_Mutex.h.


Constructor & Destructor Documentation

ACE_Process_Mutex::ACE_Process_Mutex const char *    name = 0,
void *    arg = 0,
mode_t    mode = ACE_DEFAULT_FILE_PERMS
 

Create a Process_Mutex, passing in the optional name.

Parameters:
name  optional, null-terminated string containing the name of the object. Multiple users of the same ACE_Process_Mutex must use the same name to access the same object. If not specified, a name is generated.
arg  optional, attributes to be used to initialize the mutex. If using ACE_SV_Semaphore_Complex as the underlying mechanism, this argument is ignored.
mode  optional, the protection mode for either the backing store file (for ACE_Mutex use) or the ACE_SV_Semaphore_Complex that's created.

Definition at line 36 of file Process_Mutex.cpp.

References ACE_TEXT_CHAR_TO_TCHAR, and mode_t.

00038   : lock_ (name ?
00039              ACE_TEXT_CHAR_TO_TCHAR (name) : this->unique_name (),
00040            ACE_SV_Semaphore_Complex::ACE_CREATE,
00041            1,
00042            1,
00043            mode)
00044 #else
00045   : lock_ (USYNC_PROCESS,
00046            name ?
00047              ACE_TEXT_CHAR_TO_TCHAR (name) : this->unique_name (),
00048            (ACE_mutexattr_t *) arg,
00049            mode)
00050 #endif /* _ACE_USE_SV_SEM */
00051 {
00052 #if defined (_ACE_USE_SV_SEM)
00053   ACE_UNUSED_ARG (arg);
00054 #endif /* !_ACE_USE_SV_SEM */
00055 }

ACE_Process_Mutex::ACE_Process_Mutex const wchar_t *    name,
void *    arg = 0,
mode_t    mode = ACE_DEFAULT_FILE_PERMS
 

Create a Process_Mutex, passing in the optional name. (wchar_t version)

Parameters:
name  optional, null-terminated string containing the name of the object. Multiple users of the same ACE_Process_Mutex must use the same name to access the same object. If not specified, a name is generated.
arg  optional, attributes to be used to initialize the mutex. If using ACE_SV_Semaphore_Complex as the underlying mechanism, this argument is ignored.
mode  optional, the protection mode for either the backing store file (for ACE_Mutex use) or the ACE_SV_Semaphore_Complex that's created.

Definition at line 58 of file Process_Mutex.cpp.

References ACE_TEXT_WCHAR_TO_TCHAR, and mode_t.

00062   : lock_ (name ?
00063              ACE_TEXT_WCHAR_TO_TCHAR (name) : this->unique_name (),
00064            ACE_SV_Semaphore_Complex::ACE_CREATE,
00065            1,
00066            1,
00067            mode)
00068 #else
00069   : lock_ (USYNC_PROCESS,
00070            name ?
00071              ACE_TEXT_WCHAR_TO_TCHAR (name) : this->unique_name (),
00072            (ACE_mutexattr_t *) arg,
00073            mode)
00074 #endif /* _ACE_USE_SV_SEM */
00075 {
00076 #if defined (_ACE_USE_SV_SEM)
00077   ACE_UNUSED_ARG (arg);
00078 #endif /* _ACE_USE_SV_SEM */
00079 }

ACE_Process_Mutex::~ACE_Process_Mutex void   
 

Definition at line 81 of file Process_Mutex.cpp.

00082 {
00083 }


Member Function Documentation

ACE_INLINE int ACE_Process_Mutex::acquire ACE_Time_Value   tv
 

Acquire lock ownership, but timeout if lock if hasn't been acquired by given time.

Parameters:
tv  the absolute time until which the caller is willing to wait to acquire the lock.
Returns:
0 on success; -1 on failure.

Definition at line 29 of file Process_Mutex.inl.

References ACE_Mutex::acquire, and lock_.

00030 {
00031 #if !defined (_ACE_USE_SV_SEM)
00032   return this->lock_.acquire (tv);
00033 #else
00034   ACE_UNUSED_ARG (tv);
00035   ACE_NOTSUP_RETURN (-1);
00036 #endif  /* !_ACE_USE_SV_SEM */
00037 }

ACE_INLINE int ACE_Process_Mutex::acquire void   
 

Acquire lock ownership (wait on queue if necessary).

Returns:
0 on success; -1 on failure.

Definition at line 22 of file Process_Mutex.inl.

References ACE_Mutex::acquire, and lock_.

00023 {
00024   return this->lock_.acquire ();
00025 }

ACE_INLINE int ACE_Process_Mutex::acquire_read void   
 

Acquire lock ownership (wait on queue if necessary).

Definition at line 55 of file Process_Mutex.inl.

References ACE_Mutex::acquire_read, and lock_.

00056 {
00057   return this->lock_.acquire_read ();
00058 }

ACE_INLINE int ACE_Process_Mutex::acquire_write void   
 

Acquire lock ownership (wait on queue if necessary).

Definition at line 62 of file Process_Mutex.inl.

References ACE_Mutex::acquire_write, and lock_.

00063 {
00064   return this->lock_.acquire_write ();
00065 }

void ACE_Process_Mutex::dump void    const
 

Dump the state of an object.

Definition at line 18 of file Process_Mutex.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_Mutex::dump, LM_DEBUG, and lock_.

00019 {
00020 // ACE_TRACE ("ACE_Process_Mutex::dump");
00021   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00022   this->lock_.dump ();
00023   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00024 }

ACE_INLINE const ACE_mutex_t & ACE_Process_Mutex::lock void    const
 

Return the underlying mutex.

Definition at line 6 of file Process_Mutex.inl.

References ACE_Mutex::lock, and lock_.

Referenced by ACE_WFMO_Reactor::open.

00007 {
00008 // ACE_TRACE ("ACE_Process_Mutex::lock");
00009   return this->lock_.lock ();
00010 }

ACE_INLINE int ACE_Process_Mutex::release void   
 

Release lock and unblock a thread at head of queue.

Definition at line 48 of file Process_Mutex.inl.

References lock_, and ACE_Mutex::release.

Referenced by ACE_WFMO_Reactor::event_handling.

00049 {
00050   return this->lock_.release ();
00051 }

ACE_INLINE int ACE_Process_Mutex::remove void   
 

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

Returns:
0 on success; -1 on failure.

Definition at line 15 of file Process_Mutex.inl.

References lock_, and ACE_Mutex::remove.

00016 {
00017   return this->lock_.remove ();
00018 }

ACE_INLINE int ACE_Process_Mutex::tryacquire void   
 

Conditionally acquire lock (i.e., don't wait on queue).

Returns:
0 on success; -1 on failure. If the lock could not be acquired because someone else already had the lock, errno is set to EBUSY.

Definition at line 41 of file Process_Mutex.inl.

References lock_, and ACE_Mutex::tryacquire.

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

ACE_INLINE int ACE_Process_Mutex::tryacquire_read void   
 

Conditionally acquire a lock (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 69 of file Process_Mutex.inl.

References lock_, and ACE_Mutex::tryacquire_read.

00070 {
00071   return this->lock_.tryacquire_read ();
00072 }

ACE_INLINE int ACE_Process_Mutex::tryacquire_write void   
 

Conditionally acquire a lock (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 76 of file Process_Mutex.inl.

References lock_, and ACE_Mutex::tryacquire_write.

00077 {
00078   return this->lock_.tryacquire_write ();
00079 }

ACE_INLINE int ACE_Process_Mutex::tryacquire_write_upgrade void   
 

This is only here for consistency with the other synchronization APIs and usability with Lock adapters. Assumes the caller already has acquired the mutex and returns 0 in all cases.

Definition at line 82 of file Process_Mutex.inl.

00083 {
00084   return 0;
00085 }

const ACE_TCHAR * ACE_Process_Mutex::unique_name void    [private]
 

Create and return the unique name.

Definition at line 27 of file Process_Mutex.cpp.

References ACE_UNIQUE_NAME_LEN, name_, and ACE::unique_name.

00028 {
00029   // For all platforms other than Win32, we are going to create a
00030   // machine-wide unique name if one is not provided by the user.  On
00031   // Win32, unnamed synchronization objects are acceptable.
00032   ACE::unique_name (this, this->name_, ACE_UNIQUE_NAME_LEN);
00033   return this->name_;
00034 }


Member Data Documentation

ACE_Process_Mutex::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 177 of file Process_Mutex.h.

ACE_Mutex ACE_Process_Mutex::lock_ [private]
 

Definition at line 191 of file Process_Mutex.h.

Referenced by acquire, acquire_read, acquire_write, dump, lock, release, remove, tryacquire, tryacquire_read, and tryacquire_write.

ACE_TCHAR ACE_Process_Mutex::name_[ACE_UNIQUE_NAME_LEN] [private]
 

If the user does not provide a name we generate a unique name in this buffer.

Definition at line 182 of file Process_Mutex.h.

Referenced by unique_name.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:54:30 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002