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

typedef runtime_error_custom<
Lock
error
 Exception type.
enum  Type { LOCK_SHARED = F_RDLCK, LOCK_EXCLUSIVE = F_WRLCK, LOCK_NONE = F_UNLCK }
 Lock type. More...

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.


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.


Member Function Documentation

void Lock::set_alarm  )  [protected]
 

Set the SIGALARM handler.

An error will be thrown on failure.

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.

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.

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::FileLock, and sbuild::DeviceLock.

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.


The documentation for this class was generated from the following files:
Generated on Thu Dec 29 17:20:07 2005 for schroot by  doxygen 1.4.5