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 <handle_>.
int remove (int unlink_file=1)
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.
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...


Constructor & Destructor Documentation

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

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

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

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 zero value for <unlink_in_destructor>.

ACE_File_Lock::~ACE_File_Lock ( void   ) 

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

ACE_File_Lock::ACE_File_Lock ( const ACE_File_Lock  )  [private]


Member Function Documentation

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

ACE_INLINE int ACE_File_Lock::remove ( int  unlink_file = 1  ) 

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

ACE_INLINE int ACE_File_Lock::acquire ( short  whence = 0,
ACE_OFF_T  start = 0,
ACE_OFF_T  len = 1 
)

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

ACE_INLINE int ACE_File_Lock::tryacquire ( short  whence = 0,
ACE_OFF_T  start = 0,
ACE_OFF_T  len = 1 
)

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.

ACE_INLINE int ACE_File_Lock::release ( short  whence = 0,
ACE_OFF_T  start = 0,
ACE_OFF_T  len = 1 
)

Unlock a readers/writer lock.

ACE_INLINE int ACE_File_Lock::acquire_write ( short  whence = 0,
ACE_OFF_T  start = 0,
ACE_OFF_T  len = 1 
)

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

ACE_INLINE int ACE_File_Lock::tryacquire_write ( short  whence = 0,
ACE_OFF_T  start = 0,
ACE_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, errno is set to EBUSY.

ACE_INLINE int ACE_File_Lock::tryacquire_write_upgrade ( short  whence = 0,
ACE_OFF_T  start = 0,
ACE_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, errno is set to EBUSY.

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE int ACE_File_Lock::acquire_read ( short  whence = 0,
ACE_OFF_T  start = 0,
ACE_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, errno is set to EBUSY.

ACE_INLINE int ACE_File_Lock::tryacquire_read ( short  whence = 0,
ACE_OFF_T  start = 0,
ACE_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, errno is set to EBUSY.

ACE_INLINE ACE_HANDLE ACE_File_Lock::get_handle ( void   )  const

Get underlying ACE_HANDLE for the file.

ACE_INLINE void ACE_File_Lock::set_handle ( ACE_HANDLE  h  ) 

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.

ACE_BEGIN_VERSIONED_NAMESPACE_DECL void ACE_File_Lock::dump ( void   )  const

Dump state of the object.

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


Member Data Documentation

Declare the dynamic allocation hooks.

Locking structure for OS record locks.

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

Keeps track of whether to unlink the underlying file in the destructor.


The documentation for this class was generated from the following files:

Generated on Wed Apr 23 02:39:07 2008 for ACE by  doxygen 1.5.5