commit e6387b5128e16f7900689863ac03ea67f2eae784
parent a548acbc01e805ce7f213c1a93423c8b43671a48
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Thu, 25 Jul 2024 20:36:22 +0200
trigger => semaphore
Diffstat:
5 files changed, 40 insertions(+), 44 deletions(-)
diff --git a/source/baseLib/CMakeLists.txt b/source/baseLib/CMakeLists.txt
@@ -8,7 +8,7 @@ set(SOURCES
configFile.cpp configFile.h
hybridcontainer.h
md5.cpp md5.h
- trigger.cpp trigger.h
+ semaphore.h
)
target_sources(baseLib PRIVATE ${SOURCES})
diff --git a/source/baseLib/semaphore.h b/source/baseLib/semaphore.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include <mutex>
+#include <condition_variable>
+#include <cstdint>
+
+namespace baseLib
+{
+ class Semaphore
+ {
+ public:
+ explicit Semaphore(const uint32_t _count = 0) : m_count(_count) {}
+
+ void wait()
+ {
+ std::unique_lock uLock(m_mutex);
+
+ m_cv.wait(uLock, [&]{ return m_count > 0; });
+
+ --m_count;
+ }
+
+ void notify()
+ {
+ {
+ std::lock_guard uLockHalt(m_mutex);
+ ++m_count;
+ }
+ m_cv.notify_one();
+ }
+
+ private:
+ std::condition_variable m_cv;
+ std::mutex m_mutex;
+ uint32_t m_count;
+ };
+}
diff --git a/source/baseLib/trigger.cpp b/source/baseLib/trigger.cpp
@@ -1 +0,0 @@
-#include "trigger.h"
diff --git a/source/baseLib/trigger.h b/source/baseLib/trigger.h
@@ -1,40 +0,0 @@
-#pragma once
-
-#include <mutex>
-#include <condition_variable>
-#include <cstdint>
-
-namespace baseLib
-{
- template<typename TCounter = uint32_t>
- class Trigger
- {
- public:
- void wait()
- {
- std::unique_lock uLock(m_haltMutex);
-
- m_haltcv.wait(uLock, [&]
- {
- return m_notifyCounter > m_waitCounter;
- });
-
- ++m_waitCounter;
- }
-
- void notify()
- {
- {
- std::lock_guard uLockHalt(m_haltMutex);
- ++m_notifyCounter;
- }
- m_haltcv.notify_one();
- }
-
- private:
- std::condition_variable m_haltcv;
- std::mutex m_haltMutex;
- TCounter m_waitCounter = 0;
- TCounter m_notifyCounter = 0;
- };
-}
diff --git a/source/nord/n2x/n2xLib/n2xdsp.h b/source/nord/n2x/n2xLib/n2xdsp.h
@@ -6,7 +6,7 @@
#include "dsp56kEmu/dsp.h"
#include "dsp56kEmu/dspthread.h"
-#include "baseLib/trigger.h"
+#include "baseLib/semaphore.h"
namespace mc68k
{
@@ -80,7 +80,7 @@ namespace n2x
std::condition_variable m_haltDSPcv;
std::mutex m_haltDSPmutex;
- baseLib::Trigger<> m_triggerInterruptDone;
+ baseLib::Semaphore m_triggerInterruptDone;
uint32_t m_vbaInterruptDone = 0;
};
}