Kea  2.3.5-git
isc::log::interprocess::InterprocessSync Class Referenceabstract

Interprocess Sync Class. More...

#include <interprocess_sync.h>

+ Inheritance diagram for isc::log::interprocess::InterprocessSync:

Public Member Functions

 InterprocessSync (const std::string &task_name)
 Constructor. More...
 
virtual ~InterprocessSync ()
 Destructor. More...
 

Protected Member Functions

virtual bool lock ()=0
 Acquire the lock (blocks if something else has acquired a lock on the same task name) More...
 
virtual bool tryLock ()=0
 Try to acquire a lock (doesn't block) More...
 
virtual bool unlock ()=0
 Release the lock. More...
 

Protected Attributes

bool is_locked_
 Is the lock taken? More...
 
const std::string task_name_
 The task name. More...
 

Friends

class InterprocessSyncLocker
 

Detailed Description

Interprocess Sync Class.

This class specifies an interface for mutual exclusion among co-operating processes. This is an abstract class and a real implementation such as InterprocessSyncFile should be used in code. Usage is as follows:

  1. Client instantiates a sync object of an implementation (such as InterprocessSyncFile).
  2. Client then creates an automatic (stack) object of InterprocessSyncLocker around the sync object. Such an object destroys itself and releases any acquired lock when it goes out of extent.
  3. Client calls lock() method on the InterprocessSyncLocker.
  4. Client performs task that needs mutual exclusion.
  5. Client frees lock with unlock(), or simply returns from the basic block which forms the scope for the InterprocessSyncLocker.

NOTE: All implementations of InterprocessSync should keep the is_locked_ member variable updated whenever their lock()/tryLock()/unlock() implementations are called.

Definition at line 38 of file interprocess_sync.h.

Constructor & Destructor Documentation

◆ InterprocessSync()

isc::log::interprocess::InterprocessSync::InterprocessSync ( const std::string &  task_name)
inline

Constructor.

Creates an interprocess synchronization object

Parameters
task_nameName of the synchronization task. This has to be identical among the various processes that need to be synchronized for the same task.

Definition at line 52 of file interprocess_sync.h.

◆ ~InterprocessSync()

virtual isc::log::interprocess::InterprocessSync::~InterprocessSync ( )
inlinevirtual

Destructor.

Definition at line 57 of file interprocess_sync.h.

References lock(), tryLock(), and unlock().

+ Here is the call graph for this function:

Member Function Documentation

◆ lock()

virtual bool isc::log::interprocess::InterprocessSync::lock ( )
protectedpure virtual

Acquire the lock (blocks if something else has acquired a lock on the same task name)

Returns
Returns true if the lock was acquired, false otherwise.

Implemented in isc::log::interprocess::InterprocessSyncFile, and isc::log::interprocess::InterprocessSyncNull.

Referenced by ~InterprocessSync().

◆ tryLock()

virtual bool isc::log::interprocess::InterprocessSync::tryLock ( )
protectedpure virtual

Try to acquire a lock (doesn't block)

Returns
Returns true if the lock was acquired, false otherwise.

Implemented in isc::log::interprocess::InterprocessSyncFile, and isc::log::interprocess::InterprocessSyncNull.

Referenced by ~InterprocessSync().

◆ unlock()

virtual bool isc::log::interprocess::InterprocessSync::unlock ( )
protectedpure virtual

Release the lock.

Returns
Returns true if the lock was released, false otherwise.

Implemented in isc::log::interprocess::InterprocessSyncFile, and isc::log::interprocess::InterprocessSyncNull.

Referenced by ~InterprocessSync(), and isc::log::interprocess::InterprocessSyncLocker::~InterprocessSyncLocker().

Friends And Related Function Documentation

◆ InterprocessSyncLocker

friend class InterprocessSyncLocker
friend

Definition at line 42 of file interprocess_sync.h.

Member Data Documentation

◆ is_locked_

◆ task_name_

const std::string isc::log::interprocess::InterprocessSync::task_name_
protected

The task name.

Definition at line 76 of file interprocess_sync.h.

Referenced by isc::log::interprocess::InterprocessSyncFile::~InterprocessSyncFile().


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