aboutsummaryrefslogtreecommitdiff
path: root/Src/external_dependencies/openmpt-trunk/soundlib/AudioCriticalSection.cpp
diff options
context:
space:
mode:
authorJean-Francois Mauguit <jfmauguit@mac.com>2024-09-24 09:03:25 -0400
committerGitHub <noreply@github.com>2024-09-24 09:03:25 -0400
commitbab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/external_dependencies/openmpt-trunk/soundlib/AudioCriticalSection.cpp
parent4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff)
parent20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff)
downloadwinamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/external_dependencies/openmpt-trunk/soundlib/AudioCriticalSection.cpp')
-rw-r--r--Src/external_dependencies/openmpt-trunk/soundlib/AudioCriticalSection.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/Src/external_dependencies/openmpt-trunk/soundlib/AudioCriticalSection.cpp b/Src/external_dependencies/openmpt-trunk/soundlib/AudioCriticalSection.cpp
new file mode 100644
index 00000000..d7514e25
--- /dev/null
+++ b/Src/external_dependencies/openmpt-trunk/soundlib/AudioCriticalSection.cpp
@@ -0,0 +1,83 @@
+/*
+ * AudioCriticalSection.cpp
+ * -----------
+ * Purpose: Implementation of OpenMPT's critical section for access to CSoundFile.
+ * Notes : (currently none)
+ * Authors: OpenMPT Devs
+ * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
+ */
+
+#include "stdafx.h"
+
+#include "AudioCriticalSection.h"
+
+#if defined(MODPLUG_TRACKER)
+#include "../misc/mptMutex.h"
+#endif
+
+OPENMPT_NAMESPACE_BEGIN
+
+#if defined(MODPLUG_TRACKER)
+
+#if MPT_COMPILER_MSVC
+_Acquires_lock_(m_refGlobalMutex.mutex)
+#endif // MPT_COMPILER_MSVC
+CriticalSection::CriticalSection()
+ : m_refGlobalMutex(Tracker::GetGlobalMutexRef())
+ , inSection(false)
+{
+ Enter();
+}
+
+CriticalSection::CriticalSection(CriticalSection &&other) noexcept
+ : m_refGlobalMutex(other.m_refGlobalMutex)
+ , inSection(other.inSection)
+{
+ other.inSection = false;
+}
+
+CriticalSection::CriticalSection(InitialState state)
+ : m_refGlobalMutex(Tracker::GetGlobalMutexRef())
+ , inSection(false)
+{
+ if(state == InitialState::Locked)
+ {
+ Enter();
+ }
+}
+
+#if MPT_COMPILER_MSVC
+_Acquires_lock_(m_refGlobalMutex.mutex)
+#endif // MPT_COMPILER_MSVC
+void CriticalSection::Enter()
+{
+ if(!inSection)
+ {
+ inSection = true;
+ m_refGlobalMutex.lock();
+ }
+}
+
+#if MPT_COMPILER_MSVC
+_Requires_lock_held_(m_refGlobalMutex.mutex) _Releases_lock_(m_refGlobalMutex.mutex)
+#endif // MPT_COMPILER_MSVC
+void CriticalSection::Leave()
+{
+ if(inSection)
+ {
+ inSection = false;
+ m_refGlobalMutex.unlock();
+ }
+}
+CriticalSection::~CriticalSection()
+{
+ Leave();
+}
+
+#else
+
+MPT_MSVC_WORKAROUND_LNK4221(AudioCriticalSection)
+
+#endif
+
+OPENMPT_NAMESPACE_END