sbuild::lock Class Reference

Advisory locking. More...

#include <sbuild-lock.h>

Inheritance diagram for sbuild::lock:

Inheritance graph
[legend]
List of all members.

Public Types

enum  type { LOCK_SHARED = F_RDLCK, LOCK_EXCLUSIVE = F_WRLCK, LOCK_NONE = F_UNLCK }
 Lock type. More...
enum  error_code {
  TIMEOUT_HANDLER, TIMEOUT_SET, TIMEOUT_CANCEL, LOCK,
  LOCK_TIMEOUT, DEVICE_LOCK, DEVICE_LOCK_TIMEOUT, DEVICE_TEST,
  DEVICE_UNLOCK, DEVICE_UNLOCK_TIMEOUT
}
 Error codes. More...
typedef custom_error< error_codeerror
 Exception type.

Public Member Functions

virtual void set_lock (type lock_type, unsigned int timeout)=0
 Acquire a lock.
virtual void unset_lock ()=0
 Release a lock.

Protected Member Functions

 lock ()
 The constructor.
virtual ~lock ()
 The destructor.
void set_alarm ()
 Set the SIGALARM handler.
void clear_alarm ()
 Restore the state of SIGALRM prior to starting lock acquisition.
void set_timer (struct itimerval const &timer)
 Set up an itimer for future expiry.
void unset_timer ()
 Remove any itimer currently set up.

Private Attributes

sigaction saved_signals
 Signals saved during timeout.

Detailed Description

Advisory locking.

This class defines a simple interface for shared and exclusive locks.

Definition at line 38 of file sbuild-lock.h.


Member Typedef Documentation

typedef custom_error<error_code> sbuild::lock::error

Exception type.

Definition at line 65 of file sbuild-lock.h.


Member Enumeration Documentation

enum sbuild::lock::type

Lock type.

Enumerator:
LOCK_SHARED  A shared (read) lock.
LOCK_EXCLUSIVE  An exclusive (write) lock.
LOCK_NONE  No lock.

Definition at line 42 of file sbuild-lock.h.

enum sbuild::lock::error_code

Error codes.

Enumerator:
TIMEOUT_HANDLER  Failed to set timeout handler.
TIMEOUT_SET  Failed to set timeout.
TIMEOUT_CANCEL  Failed to cancel timeout.
LOCK  Failed to lock file (timed out).
LOCK_TIMEOUT  Failed to lock file.
DEVICE_LOCK  Failed to lock device.
DEVICE_LOCK_TIMEOUT  Failed to lock device (timed out).
DEVICE_TEST  Failed to test device lock.
DEVICE_UNLOCK  Failed to unlock device.
DEVICE_UNLOCK_TIMEOUT  Failed to unlock device (timed out).

Definition at line 50 of file sbuild-lock.h.


Constructor & Destructor Documentation

lock::lock (  )  [protected]

The constructor.

Definition at line 92 of file sbuild-lock.cc.

lock::~lock (  )  [protected, virtual]

The destructor.

Definition at line 97 of file sbuild-lock.cc.


Member Function Documentation

virtual void sbuild::lock::set_lock ( type  lock_type,
unsigned int  timeout 
) [pure virtual]

Acquire a lock.

Parameters:
lock_type the type of lock to acquire.
timeout the time in seconds to wait on the lock.

Implemented in sbuild::file_lock, and sbuild::device_lock.

virtual void sbuild::lock::unset_lock (  )  [pure virtual]

Release a lock.

This is equivalent to set_lock with a lock_type of LOCK_NONE and a timeout of 0.

Implemented in sbuild::file_lock, and sbuild::device_lock.

void lock::set_alarm (  )  [protected]

Set the SIGALARM handler.

An error will be thrown on failure.

Definition at line 102 of file sbuild-lock.cc.

References alarm_handler(), and TIMEOUT_HANDLER.

Referenced by set_timer().

Here is the call graph for this function:

Here is the caller graph for this function:

void lock::clear_alarm (  )  [protected]

Restore the state of SIGALRM prior to starting lock acquisition.

Definition at line 114 of file sbuild-lock.cc.

Referenced by set_timer(), and unset_timer().

Here is the caller graph for this function:

void lock::set_timer ( struct itimerval const &  timer  )  [protected]

Set up an itimer for future expiry.

This is used to interrupt system calls. This will set a handler for SIGALRM as a side effect (using set_alarm).

An error will be thrown on failure.

Parameters:
timer the timeout to set.

Definition at line 121 of file sbuild-lock.cc.

References clear_alarm(), set_alarm(), and TIMEOUT_SET.

Referenced by sbuild::device_lock::set_lock(), and sbuild::file_lock::set_lock().

Here is the call graph for this function:

Here is the caller graph for this function:

void lock::unset_timer (  )  [protected]

Remove any itimer currently set up.

This will clear any SIGALRM handler (using clear_alarm).

An error will be thrown on failure.

Definition at line 133 of file sbuild-lock.cc.

References clear_alarm(), and TIMEOUT_CANCEL.

Referenced by sbuild::device_lock::set_lock(), and sbuild::file_lock::set_lock().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

struct sigaction sbuild::lock::saved_signals [private]

Signals saved during timeout.

Definition at line 128 of file sbuild-lock.h.


The documentation for this class was generated from the following files:
Generated on Sat Jan 27 16:14:27 2007 for schroot by  doxygen 1.5.1