Options
All
  • Public
  • Public/Protected
  • All
Menu

A ReadWriteLocker that allows for multiple simultaneous read operations. Write operations will be blocked as long as read operations are not finished. New read operations are allowed while this is going on, which will cause write operations to wait longer.

Based on https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock#Using_two_mutexes . As soon as 1 read lock request is made, the write lock is locked. Internally a counter keeps track of the amount of active read locks. Only when this number reaches 0 will the write lock be released again. The internal read lock is only locked to increase/decrease this counter and is released afterwards. This allows for multiple read operations, although only 1 at the time can update the counter, which means there can still be a small waiting period if there are multiple simultaneous read operations.

Hierarchy

  • GreedyReadWriteLocker

Implements

Index

Constructors

constructor

Properties

Private Readonly locker

Private Readonly storage

Private Readonly suffixes

Methods

Private getCountIdentifier

Private getReadLockIdentifier

Private getWriteLockIdentifier

Private incrementCount

Private postReadCleanup

Private preReadSetup

Private withInternalReadLock

  • withInternalReadLock<T>(identifier: ResourceIdentifier, whileLocked: () => T | Promise<T>): Promise<T>

withReadLock

  • withReadLock<T>(identifier: ResourceIdentifier, whileLocked: () => T | Promise<T>): Promise<T>

withWriteLock

  • withWriteLock<T>(identifier: ResourceIdentifier, whileLocked: () => T | Promise<T>): Promise<T>