All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TfBigRWMutex Class Reference

#include <bigRWMutex.h>


struct  ScopedLock

Public Member Functions

TF_API TfBigRWMutex ()
 Construct a mutex, initially unlocked. More...

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

TF_API TfBigRWMutex::TfBigRWMutex ( )

Construct a mutex, initially unlocked.

Member Data Documentation

constexpr int TfBigRWMutex::NotLocked = 0

Definition at line 78 of file bigRWMutex.h.

constexpr unsigned TfBigRWMutex::NumStates = 16

Definition at line 73 of file bigRWMutex.h.

constexpr int TfBigRWMutex::WriteLocked = -1

Definition at line 79 of file bigRWMutex.h.

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