sbuild  1.7.1
Public Member Functions | Private Attributes | List of all members
sbuild::file_lock Class Reference

File lock. More...

#include <lock.h>

+ Inheritance diagram for sbuild::file_lock:
+ Collaboration diagram for sbuild::file_lock:

Public Member Functions

 file_lock (int fd)
 The constructor. More...
 
virtual ~file_lock ()
 The destructor.
 
virtual void set_lock (lock::type lock_type, unsigned int timeout)
 Acquire a lock. More...
 
virtual void unset_lock ()
 Release a lock. More...
 

Private Attributes

int fd
 The file descriptor to lock.
 
bool locked
 Is the file locked?
 

Additional Inherited Members

- Public Types inherited from sbuild::lock
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,
  UNLOCK, LOCK_TIMEOUT, UNLOCK_TIMEOUT, DEVICE_LOCK,
  DEVICE_LOCK_TIMEOUT, DEVICE_TEST, DEVICE_UNLOCK, DEVICE_UNLOCK_TIMEOUT
}
 Error codes. More...
 
typedef custom_error< error_codeerror
 Exception type.
 
- Protected Member Functions inherited from sbuild::lock
 lock ()
 The constructor.
 
virtual ~lock ()
 The destructor.
 
void set_alarm ()
 Set the SIGALARM handler. More...
 
void clear_alarm ()
 Restore the state of SIGALRM prior to starting lock acquisition.
 
void set_timer (const struct itimerval &timer)
 Set up an itimer for future expiry. More...
 
void unset_timer ()
 Remove any itimer currently set up. More...
 

Detailed Description

File lock.

Simple whole-file shared and exclusive advisory locking based upon POSIX fcntl byte region locks.

Constructor & Destructor Documentation

sbuild::file_lock::file_lock ( int  fd)

The constructor.

Parameters
fdthe file descriptor to lock.

Member Function Documentation

void sbuild::file_lock::set_lock ( lock::type  lock_type,
unsigned int  timeout 
)
virtual

Acquire a lock.

Parameters
lock_typethe type of lock to acquire.
timeoutthe time in seconds to wait on the lock.

Implements sbuild::lock.

References fd, sbuild::lock::LOCK, sbuild::lock::LOCK_EXCLUSIVE, sbuild::lock::LOCK_SHARED, sbuild::lock::LOCK_TIMEOUT, locked, sbuild::lock::set_timer(), sbuild::lock::UNLOCK, sbuild::lock::UNLOCK_TIMEOUT, and sbuild::lock::unset_timer().

Referenced by sbuild::chroot::config::load_data(), sbuild::chroot::facet::session::setup_session_info(), and unset_lock().

+ Here is the caller graph for this function:

void sbuild::file_lock::unset_lock ( )
virtual

Release a lock.

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

Implements sbuild::lock.

References sbuild::lock::LOCK_NONE, and set_lock().

Referenced by sbuild::chroot::config::load_data(), and sbuild::chroot::facet::session::setup_session_info().

+ Here is the caller graph for this function:


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