Spinning Topp Logo BlackTopp Studios
inc
Public Member Functions | List of all members
Mezzanine::Threading::ReadWriteSpinLock Class Reference

A mutex like construct that supports multiple readsingle writer semantics and never makes a system call and uses CPU instructions instead. More...

#include <readwritespinlock.h>

Public Member Functions

 ReadWriteSpinLock ()
 Constructor, creates an unlocked mutex.
 
 ~ReadWriteSpinLock ()
 Destructor.
 
void lock ()
 Simply calls LockForWrite() for compatibility with lock_guard.
 
void LockForRead ()
 Lock the ReadWriteSpinLock for Reading. More...
 
void LockForWrite ()
 Lock the ReadWriteSpinLock for Writing. More...
 
bool TryLockForRead ()
 Try to lock this for reading. More...
 
bool TryLockForWrite ()
 Try to lock this for writing. More...
 
void unlock ()
 Simply calls UnlockWrite() for compatibility with lock_guard.
 
void UnlockRead ()
 Unlock this . More...
 
void UnlockWrite ()
 Unlock this for writing. More...
 

Detailed Description

A mutex like construct that supports multiple readsingle writer semantics and never makes a system call and uses CPU instructions instead.

This should be used when delay is likely to be measured in CPUs cycles and almost certainly a short while. For pauses of unknown length use a Mutex so that the OS is informed it could schedule another thread.

Provided readers and writers call the correct functions this will only allow access to a single writer or a group of readers at one time

Definition at line 62 of file readwritespinlock.h.

Member Function Documentation

void Mezzanine::Threading::ReadWriteSpinLock::LockForRead ( )

Lock the ReadWriteSpinLock for Reading.

The method will block the calling thread until a read lock be obtained. This remains locked until UnlockRead() is called.

Multiple read locks can be obtained. If this is locked multiple this will keep count until UnlockRead() decrements that count.

Definition at line 64 of file readwritespinlock.cpp.

void Mezzanine::Threading::ReadWriteSpinLock::LockForWrite ( )

Lock the ReadWriteSpinLock for Writing.

The method will block the calling thread until a write lock be obtained. This remains locked until UnlockWrite() is called.

Only a single write lock can exist and it can co-exist with no read locks.

Definition at line 95 of file readwritespinlock.cpp.

bool Mezzanine::Threading::ReadWriteSpinLock::TryLockForRead ( )

Try to lock this for reading.

The method will try to lock the ReadWriteSpinLock for Reading. If it fails, the function will return immediately (non-blocking).

Returns
true if the lock was acquired, or false if the lock could not be acquired.

Definition at line 67 of file readwritespinlock.cpp.

bool Mezzanine::Threading::ReadWriteSpinLock::TryLockForWrite ( )

Try to lock this for writing.

The method will try to lock the ReadWriteSpinLock for writing. If it fails, the function will return immediately (non-blocking).

Returns
true if the lock was acquired, or false if the lock could not be acquired.

Definition at line 98 of file readwritespinlock.cpp.

void Mezzanine::Threading::ReadWriteSpinLock::UnlockRead ( )

Unlock this .

Decrement the reader count and If zero any threads that are waiting for the LockWrite method on this mutex, one of them will be unblocked. If locked for write, this does nothing.

Definition at line 86 of file readwritespinlock.cpp.

void Mezzanine::Threading::ReadWriteSpinLock::UnlockWrite ( )

Unlock this for writing.

If any threads are waiting for the read or write lock on this, one of them willbe unblocked. If locked for read this doe nothing.

Definition at line 116 of file readwritespinlock.cpp.


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