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>
Public Member Functions | |
ACE_Process_Mutex (const char *name=0, 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. | |
int | acquire_read (void) |
Acquire lock ownership (wait on queue if necessary). | |
int | acquire_write (void) |
Acquire lock ownership (wait on queue if necessary). | |
int | tryacquire_read (void) |
int | tryacquire_write (void) |
int | tryacquire_write_upgrade (void) |
const ACE_mutex_t & | lock (void) const |
Return the underlying mutex. | |
void | dump (void) const |
Dump the state of an object. | |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Private Member Functions | |
const ACE_TCHAR * | unique_name (void) |
Create and return the unique name. | |
Private Attributes | |
ACE_TCHAR | name_ [ACE_UNIQUE_NAME_LEN] |
ACE_Mutex | lock_ |
A wrapper for mutexes that can be used across processes on the same host machine, as well as within a process, of course.
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 offer System V IPC (the ACE_HAS_SYSV_IPC
config macro is defined) ACE_SV_Semaphore_Complex
is the default because it is more convenient and easy to use. ACE_Mutex
is the default on all other platforms. On platforms where ACE_SV_Semaphore_Complex is used by default, the mechanism can be changed to ACE_Mutex when ACE is built by adding #define ACE_USES_MUTEX_FOR_PROCESS_MUTEX
config.h
file. acquire()
, you must use ACE_Mutex as the underlying mechanism because timed acquire does not work with System V semaphores.Definition at line 86 of file Process_Mutex.h.
ACE_Process_Mutex::ACE_Process_Mutex | ( | const char * | name = 0 , |
|
void * | arg = 0 , |
|||
mode_t | mode = ACE_DEFAULT_FILE_PERMS | |||
) |
Create an ACE_Process_Mutex.
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 41 of file Process_Mutex.cpp.
: lock_ (name ? name : ACE_TEXT_ALWAYS_CHAR (this->unique_name ()), ACE_SV_Semaphore_Complex::ACE_CREATE, 1, 1, mode) #else : lock_ (USYNC_PROCESS, name ? ACE_TEXT_CHAR_TO_TCHAR (name) : this->unique_name (), (ACE_mutexattr_t *) arg, mode) #endif /* _ACE_USE_SV_SEM */ { #if defined (_ACE_USE_SV_SEM) ACE_UNUSED_ARG (arg); #endif /* !_ACE_USE_SV_SEM */ }
ACE_Process_Mutex::~ACE_Process_Mutex | ( | void | ) |
Destructor.
Definition at line 86 of file Process_Mutex.cpp.
{ }
int ACE_Process_Mutex::acquire | ( | void | ) |
int ACE_Process_Mutex::acquire | ( | ACE_Time_Value & | tv | ) |
Acquire lock ownership, but timeout if lock if hasn't been acquired by given time.
tv | the absolute time until which the caller is willing to wait to acquire the lock. |
Definition at line 36 of file Process_Mutex.inl.
{ #if !defined (_ACE_USE_SV_SEM) return this->lock_.acquire (tv); #else ACE_UNUSED_ARG (tv); ACE_NOTSUP_RETURN (-1); #endif /* !_ACE_USE_SV_SEM */ }
int ACE_Process_Mutex::acquire_read | ( | void | ) |
Acquire lock ownership (wait on queue if necessary).
Definition at line 70 of file Process_Mutex.inl.
{ #if defined (_ACE_USE_SV_SEM) return this->lock_.acquire_read (0, SEM_UNDO); #else return this->lock_.acquire_read (); #endif // _ACE_USE_SV_SEM }
int ACE_Process_Mutex::acquire_write | ( | void | ) |
Acquire lock ownership (wait on queue if necessary).
Definition at line 81 of file Process_Mutex.inl.
{ #if defined (_ACE_USE_SV_SEM) return this->lock_.acquire_write (0, SEM_UNDO); #else return this->lock_.acquire_write (); #endif // _ACE_USE_SV_SEM }
void ACE_Process_Mutex::dump | ( | void | ) | const |
Dump the state of an object.
Definition at line 21 of file Process_Mutex.cpp.
{ #if defined (ACE_HAS_DUMP) // ACE_TRACE ("ACE_Process_Mutex::dump"); ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); this->lock_.dump (); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); #endif /* ACE_HAS_DUMP */ }
const ACE_mutex_t & ACE_Process_Mutex::lock | ( | void | ) | const |
Return the underlying mutex.
Definition at line 9 of file Process_Mutex.inl.
int ACE_Process_Mutex::release | ( | void | ) |
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.
Definition at line 18 of file Process_Mutex.inl.
int ACE_Process_Mutex::tryacquire | ( | void | ) |
Conditionally acquire lock (i.e., don't wait on queue).
errno
is set to EBUSY
. Definition at line 48 of file Process_Mutex.inl.
{ #if defined (_ACE_USE_SV_SEM) return this->lock_.tryacquire (0, SEM_UNDO); #else return this->lock_.tryacquire (); #endif // _ACE_USE_SV_SEM }
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 92 of file Process_Mutex.inl.
{ #if defined (_ACE_USE_SV_SEM) return this->lock_.tryacquire_read (0, SEM_UNDO); #else return this->lock_.tryacquire_read (); #endif // _ACE_USE_SV_SEM }
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 103 of file Process_Mutex.inl.
{ #if defined (_ACE_USE_SV_SEM) return this->lock_.tryacquire_write (0, SEM_UNDO); #else return this->lock_.tryacquire_write (); #endif // _ACE_USE_SV_SEM }
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 113 of file Process_Mutex.inl.
{
return 0;
}
const ACE_TCHAR * ACE_Process_Mutex::unique_name | ( | void | ) | [private] |
Create and return the unique name.
Definition at line 32 of file Process_Mutex.cpp.
{ // For all platforms other than Win32, we are going to create a // machine-wide unique name if one is not provided by the user. On // Win32, unnamed synchronization objects are acceptable. ACE::unique_name (this, this->name_, ACE_UNIQUE_NAME_LEN); return this->name_; }
Declare the dynamic allocation hooks.
Definition at line 207 of file Process_Mutex.h.
ACE_Mutex ACE_Process_Mutex::lock_ [private] |
Definition at line 221 of file Process_Mutex.h.
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 212 of file Process_Mutex.h.