#include <ReadWriteLock.h>

Collaboration diagram for Ipc::ReadWriteLock:

Public Member Functions

 ReadWriteLock ()
 
bool lockShared ()
 lock for reading or return false More...
 
bool lockExclusive ()
 lock for modification or return false More...
 
bool lockHeaders ()
 lock for [readable] metadata update or return false More...
 
void unlockShared ()
 undo successful sharedLock() More...
 
void unlockExclusive ()
 undo successful exclusiveLock() More...
 
void unlockHeaders ()
 undo successful lockHeaders() More...
 
void switchExclusiveToShared ()
 
bool unlockSharedAndSwitchToExclusive ()
 
void startAppending ()
 writer keeps its lock but also allows reading More...
 
bool stopAppendingAndRestoreExclusive ()
 
void updateStats (ReadWriteLockStats &stats) const
 adds approximate current stats to the supplied ones More...
 

Public Attributes

std::atomic< uint32_t > readers
 number of reading users More...
 
std::atomic< bool > writing
 there is a writing user (there can be at most 1) More...
 
std::atomic< bool > appending
 the writer has promised to only append More...
 
std::atomic_flag updating
 a reader is updating metadata/headers More...
 

Private Member Functions

bool finalizeExclusive ()
 

Private Attributes

std::atomic< uint32_t > readLevel
 number of users reading (or trying to) More...
 
std::atomic< uint32_t > writeLevel
 number of users writing (or trying to write) More...
 

Detailed Description

an atomic readers-writer or shared-exclusive lock suitable for maps/tables Also supports reading-while-appending mode when readers and writer are allowed to access the same locked object because the writer promisses to only append new data and all size-related object properties are atomic.

Definition at line 26 of file ReadWriteLock.h.

Constructor & Destructor Documentation

◆ ReadWriteLock()

Ipc::ReadWriteLock::ReadWriteLock ( )
inline

Definition at line 29 of file ReadWriteLock.h.

Member Function Documentation

◆ finalizeExclusive()

bool Ipc::ReadWriteLock::finalizeExclusive ( )
private

common lockExclusive() and unlockSharedAndSwitchToExclusive() logic: either finish exclusive locking or bail properly

Precondition
The caller must (be the first to) increment writeLevel.
Returns
whether we got the exclusive lock

Definition at line 28 of file ReadWriteLock.cc.

References appending, assert, readLevel, writeLevel, and writing.

◆ lockExclusive()

◆ lockHeaders()

bool Ipc::ReadWriteLock::lockHeaders ( )

Definition at line 63 of file ReadWriteLock.cc.

Referenced by Ipc::StoreMap::openForUpdating().

◆ lockShared()

bool Ipc::ReadWriteLock::lockShared ( )

◆ startAppending()

void Ipc::ReadWriteLock::startAppending ( )

Definition at line 124 of file ReadWriteLock.cc.

References assert.

Referenced by Ipc::StoreMap::startAppending().

◆ stopAppendingAndRestoreExclusive()

bool Ipc::ReadWriteLock::stopAppendingAndRestoreExclusive ( )

writer keeps its lock and disallows future readers

Returns
whether access became exclusive (i.e. no readers) \prec appending is true

Definition at line 131 of file ReadWriteLock.cc.

References assert.

Referenced by Ipc::StoreMap::abortWriting().

◆ switchExclusiveToShared()

void Ipc::ReadWriteLock::switchExclusiveToShared ( )

stop writing, start reading

Definition at line 100 of file ReadWriteLock.cc.

References assert.

Referenced by Ipc::StoreMap::closeForUpdating(), Ipc::MemMap::switchWritingToReading(), and Ipc::StoreMap::switchWritingToReading().

◆ unlockExclusive()

◆ unlockHeaders()

void Ipc::ReadWriteLock::unlockHeaders ( )

◆ unlockShared()

◆ unlockSharedAndSwitchToExclusive()

bool Ipc::ReadWriteLock::unlockSharedAndSwitchToExclusive ( )

same as unlockShared() but also attempts to get a writer lock beforehand

Returns
whether the writer lock was acquired

Definition at line 109 of file ReadWriteLock.cc.

References assert.

◆ updateStats()

void Ipc::ReadWriteLock::updateStats ( ReadWriteLockStats stats) const

Definition at line 148 of file ReadWriteLock.cc.

References Ping::stats.

Member Data Documentation

◆ appending

std::atomic<bool> Ipc::ReadWriteLock::appending

Definition at line 56 of file ReadWriteLock.h.

Referenced by Ipc::StoreMap::abortWriting(), finalizeExclusive(), and Ipc::operator<<().

◆ readers

std::atomic<uint32_t> Ipc::ReadWriteLock::readers
mutable

◆ readLevel

std::atomic<uint32_t> Ipc::ReadWriteLock::readLevel
mutableprivate

Definition at line 62 of file ReadWriteLock.h.

Referenced by finalizeExclusive().

◆ updating

std::atomic_flag Ipc::ReadWriteLock::updating

◆ writeLevel

std::atomic<uint32_t> Ipc::ReadWriteLock::writeLevel
private

Definition at line 63 of file ReadWriteLock.h.

Referenced by finalizeExclusive().

◆ writing

std::atomic<bool> Ipc::ReadWriteLock::writing

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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors