MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
Mezzanine::Threading::SpinLock Class Reference

A mutex like construct that never makes a system call and uses CPU instructions instead. More...

#include <spinlock.h>

Public Member Functions

 SpinLock ()
 Constructor, creates an unlocked mutex.
 
 ~SpinLock ()
 Destructor.
 
void Lock ()
 Lock the SpinLock. More...
 
bool TryLock ()
 Try to lock the spinlock. More...
 
void Unlock ()
 Unlock the spinlock. More...
 

Detailed Description

A mutex like construct that 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.

This is compatible with the lock_guard class.

Definition at line 83 of file spinlock.h.

Member Function Documentation

void Mezzanine::Threading::SpinLock::Lock ( )

Lock the SpinLock.

The method will block the calling thread until a lock on the SpinLock can be obtained. The SpinLock remains locked until unlock() is called.

See Also
lock_guard

Definition at line 61 of file spinlock.cpp.

bool Mezzanine::Threading::SpinLock::TryLock ( )

Try to lock the spinlock.

The method will try to lock the SpinLock. 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 spinlock.cpp.

void Mezzanine::Threading::SpinLock::Unlock ( )

Unlock the spinlock.

If any threads are waiting for the lock on this mutex, one of them will be unblocked.

Definition at line 70 of file spinlock.cpp.


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