ACE_File_Lock Class Reference

A wrapper around the UNIX file locking mechanism. More...

#include <File_Lock.h>

Collaboration diagram for ACE_File_Lock:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_File_Lock (ACE_HANDLE handle=ACE_INVALID_HANDLE, int unlink_in_destructor=1)
 ACE_File_Lock (const ACE_TCHAR *filename, int flags, mode_t mode=0, int unlink_in_destructor=1)
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 .

int remove (int unlink_file=1)
int acquire (short whence=0, off_t start=0, off_t len=1)
int tryacquire (short whence=0, off_t start=0, off_t len=1)
int release (short whence=0, off_t start=0, off_t len=1)
 Unlock a readers/writer lock.

int acquire_write (short whence=0, off_t start=0, off_t len=1)
int tryacquire_write (short whence=0, off_t start=0, off_t len=1)
int tryacquire_write_upgrade (short whence=0, off_t start=0, off_t len=1)
int acquire_read (short whence=0, off_t start=0, off_t len=1)
int tryacquire_read (short whence=0, off_t start=0, 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.

int removed_
int unlink_in_destructor_

Private Member Functions

void operator= (const ACE_File_Lock &)
 ACE_File_Lock (const ACE_File_Lock &)

Detailed Description

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.


Constructor & Destructor Documentation

ACE_File_Lock::ACE_File_Lock ACE_HANDLE  handle = ACE_INVALID_HANDLE,
int  unlink_in_destructor = 1
 

Set the of the File_Lock to . Note that this constructor assumes ownership of the and will close it down in . If you want the to stay open when is called make sure to call on the . If you don't want the file unlinked in the destructor pass a zero value for .

Definition at line 28 of file File_Lock.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_OS::flock_init(), LM_ERROR, and set_handle().

00030   : removed_ (0),
00031     unlink_in_destructor_ (unlink_in_destructor)
00032 {
00033 // ACE_TRACE ("ACE_File_Lock::ACE_File_Lock");
00034   if (ACE_OS::flock_init (&this->lock_) == -1)
00035     ACE_ERROR ((LM_ERROR,
00036                 ACE_LIB_TEXT ("%p\n"),
00037                 ACE_LIB_TEXT ("ACE_File_Lock::ACE_File_Lock")));
00038   this->set_handle (h);
00039 }

ACE_File_Lock::ACE_File_Lock const ACE_TCHAR filename,
int  flags,
mode_t  mode = 0,
int  unlink_in_destructor = 1
 

Open the with and and set the result to . If you don't want the file unlinked in the destructor pass a zero value for .

Definition at line 41 of file File_Lock.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TCHAR, LM_ERROR, mode_t, and open().

00045   : unlink_in_destructor_ (unlink_in_destructor)
00046 {
00047 // ACE_TRACE ("ACE_File_Lock::ACE_File_Lock");
00048 
00049   if (this->open (name, flags, perms) == -1)
00050     ACE_ERROR ((LM_ERROR,
00051                 ACE_LIB_TEXT ("%p %s\n"),
00052                 ACE_LIB_TEXT ("ACE_File_Lock::ACE_File_Lock"),
00053                 name));
00054 }

ACE_File_Lock::~ACE_File_Lock void   ) 
 

Remove a File lock by releasing it and closing down the .

Definition at line 66 of file File_Lock.cpp.

References remove().

00067 {
00068 // ACE_TRACE ("ACE_File_Lock::~ACE_File_Lock");
00069   this->remove (this->unlink_in_destructor_);
00070 }

ACE_File_Lock::ACE_File_Lock const ACE_File_Lock  )  [private]
 


Member Function Documentation

ACE_INLINE int ACE_File_Lock::acquire short  whence = 0,
off_t  start = 0,
off_t  len = 1
 

Note, for interface uniformity with other synchronization wrappers we include the method. This is implemented as a write-lock to be on the safe-side...

Definition at line 50 of file File_Lock.inl.

References acquire_write().

Referenced by ACE_RW_Process_Mutex::acquire().

00051 {
00052 // ACE_TRACE ("ACE_File_Lock::acquire");
00053   return this->acquire_write (whence, start, len);
00054 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE int ACE_File_Lock::acquire_read short  whence = 0,
off_t  start = 0,
off_t  len = 1
 

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, is set to .

Definition at line 8 of file File_Lock.inl.

References ACE_OS::flock_rdlock().

Referenced by ACE_RW_Process_Mutex::acquire_read().

00009 {
00010 // ACE_TRACE ("ACE_File_Lock::acquire_read");
00011   return ACE_OS::flock_rdlock (&this->lock_, whence, start, len);
00012 }

ACE_INLINE int ACE_File_Lock::acquire_write short  whence = 0,
off_t  start = 0,
off_t  len = 1
 

Acquire a write lock, but block if any readers or a writer hold the lock.

Definition at line 43 of file File_Lock.inl.

References ACE_OS::flock_wrlock().

Referenced by acquire(), and ACE_RW_Process_Mutex::acquire_write().

00044 {
00045 // ACE_TRACE ("ACE_File_Lock::acquire_write");
00046   return ACE_OS::flock_wrlock (&this->lock_, whence, start, len);
00047 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL void ACE_File_Lock::dump void   )  const
 

Dump state of the object.

Definition at line 17 of file File_Lock.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_OS::ace_flock_t::dump(), and LM_DEBUG.

Referenced by ACE_RW_Process_Mutex::dump().

00018 {
00019 #if defined (ACE_HAS_DUMP)
00020 // ACE_TRACE ("ACE_File_Lock::dump");
00021 
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 }

ACE_INLINE ACE_HANDLE ACE_File_Lock::get_handle void   )  const
 

Get underlying ACE_HANDLE for the file.

Definition at line 80 of file File_Lock.inl.

References ACE_OS::ace_flock_t::handle_.

00081 {
00082 // ACE_TRACE ("ACE_File_Lock::get_handle");
00083   return this->lock_.handle_;
00084 }

int ACE_File_Lock::open const ACE_TCHAR filename,
int  flags,
mode_t  mode = 0
 

Open the with and and set the result to .

Definition at line 57 of file File_Lock.cpp.

References ACE_TCHAR, ACE_OS::flock_init(), and mode_t.

Referenced by ACE_File_Lock().

00060 {
00061 // ACE_TRACE ("ACE_File_Lock::open");
00062   this->removed_ = 0;
00063   return ACE_OS::flock_init (&this->lock_, flags, name, perms);
00064 }

void ACE_File_Lock::operator= const ACE_File_Lock  )  [private]
 

ACE_INLINE int ACE_File_Lock::release short  whence = 0,
off_t  start = 0,
off_t  len = 1
 

Unlock a readers/writer lock.

Definition at line 57 of file File_Lock.inl.

References ACE_OS::flock_unlock().

Referenced by ACE_RW_Process_Mutex::release().

00058 {
00059 // ACE_TRACE ("ACE_File_Lock::release");
00060   return ACE_OS::flock_unlock (&this->lock_, whence, start, len);
00061 }

ACE_INLINE int ACE_File_Lock::remove int  unlink_file = 1  ) 
 

Remove a File lock by releasing it and closing down the . If is non-0 then we unlink the file.

Definition at line 64 of file File_Lock.inl.

References ACE_OS::flock_destroy().

Referenced by ACE_RW_Process_Mutex::remove(), and ~ACE_File_Lock().

00065 {
00066 // ACE_TRACE ("ACE_File_Lock::remove");
00067 
00068   int result = 0;
00069 
00070   if (this->removed_ == 0)
00071     {
00072       this->removed_ = 1;
00073       result = ACE_OS::flock_destroy (&this->lock_,
00074                                       unlink_file);
00075     }
00076   return result;
00077 }

ACE_INLINE void ACE_File_Lock::set_handle ACE_HANDLE   ) 
 

Set underlying ACE_HANDLE. Note that this method assumes ownership of the and will close it down in . If you want the to stay open when is called make sure to call on the before closing it. You are responsible for the closing the existing before overwriting it.

Definition at line 87 of file File_Lock.inl.

References ACE_OS::ace_flock_t::handle_.

Referenced by ACE_File_Lock().

00088 {
00089 // ACE_TRACE ("ACE_File_Lock::set_handle");
00090   this->lock_.handle_ = h;
00091   this->removed_ = 0;
00092 }

ACE_INLINE int ACE_File_Lock::tryacquire short  whence = 0,
off_t  start = 0,
off_t  len = 1
 

Note, for interface uniformity with other synchronization wrappers we include the 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, is set to .

Definition at line 36 of file File_Lock.inl.

References tryacquire_write().

Referenced by ACE_RW_Process_Mutex::tryacquire().

00037 {
00038 // ACE_TRACE ("ACE_File_Lock::tryacquire");
00039   return this->tryacquire_write (whence, start, len);
00040 }

ACE_INLINE int ACE_File_Lock::tryacquire_read short  whence = 0,
off_t  start = 0,
off_t  len = 1
 

Conditionally acquire a read lock (i.e., won't block). Returns -1 on failure. If we "failed" because someone else already had the lock, is set to .

Definition at line 15 of file File_Lock.inl.

References ACE_OS::flock_tryrdlock().

Referenced by ACE_RW_Process_Mutex::tryacquire_read().

00016 {
00017 // ACE_TRACE ("ACE_File_Lock::tryacquire_read");
00018   return ACE_OS::flock_tryrdlock (&this->lock_, whence, start, len);
00019 }

ACE_INLINE int ACE_File_Lock::tryacquire_write short  whence = 0,
off_t  start = 0,
off_t  len = 1
 

Conditionally acquire a write lock (i.e., won't block). Returns -1 on failure. If we "failed" because someone else already had the lock, is set to .

Definition at line 22 of file File_Lock.inl.

References ACE_OS::flock_trywrlock().

Referenced by tryacquire(), and ACE_RW_Process_Mutex::tryacquire_write().

00023 {
00024 // ACE_TRACE ("ACE_File_Lock::tryacquire_write");
00025   return ACE_OS::flock_trywrlock (&this->lock_, whence, start, len);
00026 }

ACE_INLINE int ACE_File_Lock::tryacquire_write_upgrade short  whence = 0,
off_t  start = 0,
off_t  len = 1
 

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, is set to .

Definition at line 29 of file File_Lock.inl.

References ACE_OS::flock_trywrlock().

Referenced by ACE_RW_Process_Mutex::tryacquire_write_upgrade().

00030 {
00031 // ACE_TRACE ("ACE_File_Lock::tryacquire_write_upgrade");
00032   return ACE_OS::flock_trywrlock (&this->lock_, whence, start, len);
00033 }


Member Data Documentation

ACE_File_Lock::ACE_ALLOC_HOOK_DECLARE
 

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.

int ACE_File_Lock::removed_ [protected]
 

Keeps track of whether has been called yet to avoid multiple 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 on the same object, which is a bad idea anyway...

Definition at line 151 of file File_Lock.h.

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


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:22:16 2006 for ACE by doxygen 1.3.6