sjef
Classes | Public Member Functions | List of all members
sjef::util::Locker Class Reference

A thread-safe class for an inter-thread/inter-process lock. The lock mechanism is based on a locked file in the file system. The locked file is a file that may or may not already exist; if it doesn't, it is created. The file contents are not altered, and the file is not deleted. If the specified file is a directory, the lock is instead made on a file in that directory. All threads in the same process using the locker must do so through the same Locker object. More...

#include <Locker.h>

Classes

struct  Bolt
 

Public Member Functions

 Locker (fs::path path)
 
virtual ~Locker ()
 
const fs::path & path () const
 
void add_bolt ()
 
void remove_bolt ()
 
Bolt bolt ()
 

Detailed Description

A thread-safe class for an inter-thread/inter-process lock. The lock mechanism is based on a locked file in the file system. The locked file is a file that may or may not already exist; if it doesn't, it is created. The file contents are not altered, and the file is not deleted. If the specified file is a directory, the lock is instead made on a file in that directory. All threads in the same process using the locker must do so through the same Locker object.

The lock is initially open, and is closed by calling add_bolt() and reopened with remove_bolt(); add_bolt() can be called multiple times, with only the first instance having a real effect, and the lock being released when the last bolt is removed. It is recommended not to call add_bolt() directly, but to use the RAII pattern provided by the bolt() function.

Constructor & Destructor Documentation

◆ Locker()

sjef::util::Locker::Locker ( fs::path  path)
explicit

◆ ~Locker()

virtual sjef::util::Locker::~Locker ( )
virtual

Member Function Documentation

◆ add_bolt()

void sjef::util::Locker::add_bolt ( )

◆ bolt()

Bolt sjef::util::Locker::bolt ( )

◆ path()

const fs::path& sjef::util::Locker::path ( ) const
inline

◆ remove_bolt()

void sjef::util::Locker::remove_bolt ( )

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