A wrapper around the UNIX file locking mechanism. More...
#include <File_Lock.h>
Public Member Functions | |
ACE_File_Lock (ACE_HANDLE handle=ACE_INVALID_HANDLE, bool unlink_in_destructor=true) | |
ACE_File_Lock (const ACE_TCHAR *filename, int flags, mode_t mode=0, bool unlink_in_destructor=true) | |
int | open (const ACE_TCHAR *filename, int flags, mode_t mode=0) |
~ACE_File_Lock (void) | |
Remove a File lock by releasing it and closing down the <handle_>. | |
int | remove (bool unlink_file=true) |
int | acquire (short whence=0, ACE_OFF_T start=0, ACE_OFF_T len=1) |
int | tryacquire (short whence=0, ACE_OFF_T start=0, ACE_OFF_T len=1) |
int | release (short whence=0, ACE_OFF_T start=0, ACE_OFF_T len=1) |
Unlock a readers/writer lock. | |
int | acquire_write (short whence=0, ACE_OFF_T start=0, ACE_OFF_T len=1) |
int | tryacquire_write (short whence=0, ACE_OFF_T start=0, ACE_OFF_T len=1) |
int | tryacquire_write_upgrade (short whence=0, ACE_OFF_T start=0, ACE_OFF_T len=1) |
int | acquire_read (short whence=0, ACE_OFF_T start=0, ACE_OFF_T len=1) |
int | tryacquire_read (short whence=0, ACE_OFF_T start=0, ACE_OFF_T len=1) |
ACE_HANDLE | get_handle (void) const |
Get underlying ACE_HANDLE for the file. | |
void | set_handle (ACE_HANDLE) |
void | dump (void) const |
Dump state of the object. | |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Protected Attributes | |
ACE_OS::ace_flock_t | lock_ |
Locking structure for OS record locks. | |
bool | removed_ |
bool const | unlink_in_destructor_ |
Private Member Functions | |
void | operator= (const ACE_File_Lock &) |
ACE_File_Lock (const ACE_File_Lock &) |
A wrapper around the UNIX file locking mechanism.
Allows us to "adapt" the UNIX file locking mechanisms to work with all of our Guard stuff...
Definition at line 35 of file File_Lock.h.
ACE_File_Lock::ACE_File_Lock | ( | ACE_HANDLE | handle = ACE_INVALID_HANDLE , |
|
bool | unlink_in_destructor = true | |||
) |
Set the <handle_> of the File_Lock to handle. Note that this constructor assumes ownership of the handle and will close it down in <remove>. If you want the handle to stay open when <remove> is called make sure to call <dup> on the handle. If you don't want the file unlinked in the destructor pass a zero value for <unlink_in_destructor>.
Definition at line 28 of file File_Lock.cpp.
: removed_ (false), unlink_in_destructor_ (unlink_in_destructor) { // ACE_TRACE ("ACE_File_Lock::ACE_File_Lock"); if (ACE_OS::flock_init (&this->lock_) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE_File_Lock::ACE_File_Lock"))); this->set_handle (h); }
ACE_File_Lock::ACE_File_Lock | ( | const ACE_TCHAR * | filename, | |
int | flags, | |||
mode_t | mode = 0 , |
|||
bool | unlink_in_destructor = true | |||
) |
Open the filename with flags and mode and set the result to <handle_>. If you don't want the file unlinked in the destructor pass a false value for unlink_in_destructor.
Definition at line 41 of file File_Lock.cpp.
ACE_File_Lock::~ACE_File_Lock | ( | void | ) |
Remove a File lock by releasing it and closing down the <handle_>.
Definition at line 66 of file File_Lock.cpp.
{ // ACE_TRACE ("ACE_File_Lock::~ACE_File_Lock"); this->remove (this->unlink_in_destructor_); }
ACE_File_Lock::ACE_File_Lock | ( | const ACE_File_Lock & | ) | [private] |
Note, for interface uniformity with other synchronization wrappers we include the acquire() method. This is implemented as a write-lock to be on the safe-side...
Definition at line 52 of file File_Lock.inl.
{ // ACE_TRACE ("ACE_File_Lock::acquire"); return this->acquire_write (whence, start, len); }
int ACE_File_Lock::acquire_read | ( | short | whence = 0 , |
|
ACE_OFF_T | start = 0 , |
|||
ACE_OFF_T | len = 1 | |||
) | [inline] |
Acquire a read lock, but block if a writer hold the lock. Returns -1 on failure. If we "failed" because someone else already had the lock, errno
is set to EBUSY
.
Definition at line 8 of file File_Lock.inl.
{ // ACE_TRACE ("ACE_File_Lock::acquire_read"); return ACE_OS::flock_rdlock (&this->lock_, whence, start, len); }
int ACE_File_Lock::acquire_write | ( | short | whence = 0 , |
|
ACE_OFF_T | start = 0 , |
|||
ACE_OFF_T | len = 1 | |||
) | [inline] |
Acquire a write lock, but block if any readers or a writer hold the lock.
Definition at line 45 of file File_Lock.inl.
{ // ACE_TRACE ("ACE_File_Lock::acquire_write"); return ACE_OS::flock_wrlock (&this->lock_, whence, start, len); }
void ACE_File_Lock::dump | ( | void | ) | const |
Dump state of the object.
Definition at line 17 of file File_Lock.cpp.
{ #if defined (ACE_HAS_DUMP) // ACE_TRACE ("ACE_File_Lock::dump"); ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); this->lock_.dump (); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); #endif /* ACE_HAS_DUMP */ }
ACE_HANDLE ACE_File_Lock::get_handle | ( | void | ) | const [inline] |
Get underlying ACE_HANDLE for the file.
Definition at line 82 of file File_Lock.inl.
int ACE_File_Lock::open | ( | const ACE_TCHAR * | filename, | |
int | flags, | |||
mode_t | mode = 0 | |||
) |
Open the filename with flags and mode and set the result to <handle_>.
Definition at line 57 of file File_Lock.cpp.
{ // ACE_TRACE ("ACE_File_Lock::open"); this->removed_ = false; return ACE_OS::flock_init (&this->lock_, flags, name, perms); }
void ACE_File_Lock::operator= | ( | const ACE_File_Lock & | ) | [private] |
Unlock a readers/writer lock.
Definition at line 59 of file File_Lock.inl.
{ // ACE_TRACE ("ACE_File_Lock::release"); return ACE_OS::flock_unlock (&this->lock_, whence, start, len); }
int ACE_File_Lock::remove | ( | bool | unlink_file = true |
) | [inline] |
Remove a File lock by releasing it and closing down the <handle_>. If unlink_file is true then we unlink the file.
Definition at line 66 of file File_Lock.inl.
{ // ACE_TRACE ("ACE_File_Lock::remove"); int result = 0; if (!this->removed_) { this->removed_ = true; result = ACE_OS::flock_destroy (&this->lock_, unlink_file); } return result; }
void ACE_File_Lock::set_handle | ( | ACE_HANDLE | h | ) | [inline] |
Set underlying ACE_HANDLE. Note that this method assumes ownership of the handle and will close it down in <remove>. If you want the handle to stay open when <remove> is called make sure to call <dup> on the handle before closing it. You are responsible for the closing the existing handle before overwriting it.
Definition at line 89 of file File_Lock.inl.
Note, for interface uniformity with other synchronization wrappers we include the <tryacquire> method. This is implemented as a write-lock to be on the safe-side... Returns -1 on failure. If we "failed" because someone else already had the lock, errno
is set to EBUSY
.
Definition at line 38 of file File_Lock.inl.
{ // ACE_TRACE ("ACE_File_Lock::tryacquire"); return this->tryacquire_write (whence, start, len); }
int ACE_File_Lock::tryacquire_read | ( | short | whence = 0 , |
|
ACE_OFF_T | start = 0 , |
|||
ACE_OFF_T | len = 1 | |||
) | [inline] |
Conditionally acquire a read 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 15 of file File_Lock.inl.
{ // ACE_TRACE ("ACE_File_Lock::tryacquire_read"); return ACE_OS::flock_tryrdlock (&this->lock_, whence, start, len); }
int ACE_File_Lock::tryacquire_write | ( | short | whence = 0 , |
|
ACE_OFF_T | start = 0 , |
|||
ACE_OFF_T | len = 1 | |||
) | [inline] |
Conditionally acquire a write 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 22 of file File_Lock.inl.
{ // ACE_TRACE ("ACE_File_Lock::tryacquire_write"); return ACE_OS::flock_trywrlock (&this->lock_, whence, start, len); }
int ACE_File_Lock::tryacquire_write_upgrade | ( | short | whence = 0 , |
|
ACE_OFF_T | start = 0 , |
|||
ACE_OFF_T | len = 1 | |||
) | [inline] |
Conditionally upgrade to a write 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 29 of file File_Lock.inl.
{ // ACE_TRACE ("ACE_File_Lock::tryacquire_write_upgrade"); return ACE_OS::flock_trywrlock (&this->lock_, whence, start, len); }
Declare the dynamic allocation hooks.
Definition at line 140 of file File_Lock.h.
ACE_OS::ace_flock_t ACE_File_Lock::lock_ [protected] |
Locking structure for OS record locks.
Definition at line 144 of file File_Lock.h.
bool ACE_File_Lock::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...
Definition at line 151 of file File_Lock.h.
bool const ACE_File_Lock::unlink_in_destructor_ [protected] |
Keeps track of whether to unlink the underlying file in the destructor.
Definition at line 155 of file File_Lock.h.