Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Mutex class which provides the ability to check whether an sf::Mutex is locked for recursion protection.
- class LockDetectionSFMutex : public sf::Mutex
- {
- public:
- LockDetectionSFMutex(void)
- {
- _bIsLocked = false;
- }
- virtual ~LockDetectionSFMutex(void)
- {
- }
- void lock(void)
- {
- sf::Mutex::lock();
- //***
- // At this point, either a single thread owns the lock, or a thread
- // that already owned the lock has just locked it for the second time.
- // Since no more than one thread owns this lock, it is now safe to read
- // and write _bIsLocked.
- //***
- if(_bIsLocked)
- {
- LogError("Mutex recursively acquired! Fatal error!");
- // Immediately crash since this error should be logically impossible,
- // and it should be VERY visible if it happens.
- exit(-1);
- }
- _bIsLocked = true;
- }
- void unlock(void)
- {
- _bIsLocked = false;
- sf::Mutex::unlock();
- }
- // Returns true if the mutex is locked, and false otherwise.
- bool IsLocked(void)
- {
- return _bIsLocked;
- };
- private:
- bool _bIsLocked;
- };
Advertisement
Add Comment
Please, Sign In to add comment