The CYIAutoSpinLock is a helper class that simplifies the locking and unlocking of spin locks based on the RAII principle.
Locking and unlocking a CYISpinLock in a function that has multiple return points can be difficult. Forgetting to unlock a CYISpinLock can result a live-lock.
Consider the following example:
With the help of the CYIAutoSpinLock, the code above could be simplified to the following:
This way, the locked CYISpinLock will always unlock automatically for you, as soon as the lock object gets out of scope.
#include <thread/YiAutoSpinLock.h>
Public Member Functions | |
| CYIAutoSpinLock (CYISpinLock &rSpinLock) | |
| ~CYIAutoSpinLock () | |
| void | Relock () |
| void | Unlock () |
|
inline |
Constructs a CYIAutoSpinLock and locks m_rSpinLock. The CYISpinLock will automatically unlock when the instance is destroyed.
|
inline |
Destroys the CYIAutoSpinLock and unlocks m_rSpinLock that was locked by the constructor.
| void CYIAutoSpinLock::Relock | ( | ) |
Relocks a manually unlocked CYISpinLock.
| void CYIAutoSpinLock::Unlock | ( | ) |
Unlocks m_rSpinLock. You may relock the CYISpinLock using CYIAutoSpinLock::Relock().