Loading...
Searching...
No Matches
TfBigRWMutex Class Reference

This class implements a readers-writer mutex and provides a scoped lock utility. More...

#include <bigRWMutex.h>

Classes

struct  ScopedLock
 Scoped lock utility class. More...
 

Public Member Functions

TF_API TfBigRWMutex ()
 Construct a mutex, initially unlocked.
 

Static Public Attributes

static constexpr unsigned NumStates = 16
 
static constexpr int NotLocked = 0
 
static constexpr int WriteLocked = -1
 

Detailed Description

This class implements a readers-writer mutex and provides a scoped lock utility.

Multiple clients may acquire a read lock simultaneously, but only one client may hold a write lock, exclusive to all other locks.

This class emphasizes throughput for (and is thus best used in) the case where there are many simultaneous reader clients all concurrently taking read locks, with clients almost never taking write locks. As such, taking a read lock is a lightweight operation that usually does not imply much hardware-level concurrency penalty (i.e. writes to shared cache lines). This is done by allocating several cache-line-sized chunks of memory to represent lock state, and readers typically only deal with a single lock state (and therefore a single cache line). On the other hand, taking a write lock is very expensive from a hardware concurrency point of view; it requires atomic memory operations on every cache-line.

To achieve good throughput under highly read-contended workloads, this class allocates 10s of cachelines worth of state (~1 KB) to help minimize hardware-level contention. So it is probably not appropriate to use as (e.g.) a member variable in an object that there are likely to be many of.

This class has been measured to show >10x throughput compared to tbb::spin_rw_mutex, and >100x better throughput compared to tbb::queuing_rw_mutex on reader-contention-heavy loads. The tradeoff being the relatively large size required compared to these other classes.

Definition at line 69 of file bigRWMutex.h.

Constructor & Destructor Documentation

◆ TfBigRWMutex()

TF_API TfBigRWMutex ( )

Construct a mutex, initially unlocked.

Member Data Documentation

◆ NotLocked

constexpr int NotLocked = 0
staticconstexpr

Definition at line 78 of file bigRWMutex.h.

◆ NumStates

constexpr unsigned NumStates = 16
staticconstexpr

Definition at line 73 of file bigRWMutex.h.

◆ WriteLocked

constexpr int WriteLocked = -1
staticconstexpr

Definition at line 79 of file bigRWMutex.h.


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