lintel 0.2.0
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
lintel::shm::SegmentSemaphoreGuard Class Reference

#include <ShmConstructors.h>

Public Member Functions

 SegmentSemaphoreGuard (boost::interprocess::named_semaphore &semaphore, std::chrono::steady_clock::duration timeout=kDefaultWaitTimeout)
 
 ~SegmentSemaphoreGuard ()
 
 SegmentSemaphoreGuard (const SegmentSemaphoreGuard &)=delete
 
SegmentSemaphoreGuard & operator= (const SegmentSemaphoreGuard &)=delete
 

Static Public Attributes

static constexpr std::chrono::seconds kDefaultWaitTimeout { 30 }
 

Detailed Description

RAII guard that acquires (default) the segment remap semaphore and releases it on destruction. Used as a cross-process mutex around the shared memory remap / construct critical sections.

The acquisition is bounded: a process that crashes while holding the semaphore leaves its count at zero forever, so an unbounded wait() would deadlock every other process. Instead the guard times out and throws, turning the silent hang into an actionable error (the orphaned handle can be inspected/removed out of band).

Constructor & Destructor Documentation

◆ SegmentSemaphoreGuard() [1/2]

lintel::shm::SegmentSemaphoreGuard::SegmentSemaphoreGuard ( boost::interprocess::named_semaphore &  semaphore,
std::chrono::steady_clock::duration  timeout = kDefaultWaitTimeout 
)
inlineexplicit
Parameters
semaphoresemaphore of the segment to guard
timeoutupper bound for acquiring the semaphore
Exceptions
std::runtime_errorif the semaphore could not be acquired within the timeout (e.g. a previous holder crashed)

◆ ~SegmentSemaphoreGuard()

lintel::shm::SegmentSemaphoreGuard::~SegmentSemaphoreGuard ( )
inline

◆ SegmentSemaphoreGuard() [2/2]

lintel::shm::SegmentSemaphoreGuard::SegmentSemaphoreGuard ( const SegmentSemaphoreGuard &  )
delete

Member Function Documentation

◆ operator=()

SegmentSemaphoreGuard & lintel::shm::SegmentSemaphoreGuard::operator= ( const SegmentSemaphoreGuard &  )
delete

Member Data Documentation

◆ kDefaultWaitTimeout

constexpr std::chrono::seconds lintel::shm::SegmentSemaphoreGuard::kDefaultWaitTimeout { 30 }
staticconstexpr

Default time to wait for the semaphore before giving up. Generous, because the guarded critical sections are short (remap/construct).


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