123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #pragma once
- #include "openmpt/all/BuildSettings.hpp"
- #if defined(MODPLUG_TRACKER)
- #include "../misc/mptMutex.h"
- #endif
- OPENMPT_NAMESPACE_BEGIN
- #if defined(MODPLUG_TRACKER)
- namespace mpt {
- class recursive_mutex_with_lock_count;
- }
- namespace Tracker {
- mpt::recursive_mutex_with_lock_count & GetGlobalMutexRef();
- }
- class CriticalSection
- {
- private:
-
- mpt::recursive_mutex_with_lock_count & m_refGlobalMutex;
- protected:
- bool inSection;
- public:
- enum class InitialState
- {
- Locked = 0,
- Unlocked = 1,
- };
- public:
- #if MPT_COMPILER_MSVC
- _Acquires_lock_(m_refGlobalMutex.mutex)
- #endif
- CriticalSection();
- CriticalSection(CriticalSection &&other) noexcept;
- explicit CriticalSection(InitialState state);
- #if MPT_COMPILER_MSVC
- _Acquires_lock_(m_refGlobalMutex.mutex)
- #endif
- void Enter();
- #if MPT_COMPILER_MSVC
- _Requires_lock_held_(m_refGlobalMutex.mutex) _Releases_lock_(m_refGlobalMutex.mutex)
- #endif
- void Leave();
- ~CriticalSection();
- };
- #else
- class CriticalSection
- {
- public:
- enum class InitialState
- {
- Locked = 0,
- Unlocked = 1,
- };
- public:
- CriticalSection() {}
- CriticalSection(CriticalSection &&) noexcept {}
- explicit CriticalSection(InitialState) {}
- void Enter() {}
- void Leave() {}
- ~CriticalSection() {}
- };
- #endif
- OPENMPT_NAMESPACE_END
|