From 7afc844d7432a56b1a3fbc4f338f3f3806cf2471 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Tue, 24 May 2022 08:14:11 +0200 Subject: [PATCH] Added a SpinLock around MIDI message processing. --- src/mididevice.cpp | 3 +++ src/mididevice.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/mididevice.cpp b/src/mididevice.cpp index 9762e49..6959b41 100644 --- a/src/mididevice.cpp +++ b/src/mididevice.cpp @@ -163,6 +163,8 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign return; } + m_MIDISpinLock.Acquire (); + u8 ucStatus = pMessage[0]; u8 ucChannel = ucStatus & 0x0F; u8 ucType = ucStatus >> 4; @@ -313,6 +315,7 @@ void CMIDIDevice::MIDIMessageHandler (const u8 *pMessage, size_t nLength, unsign } } } + m_MIDISpinLock.Release (); } void CMIDIDevice::AddDevice (const char *pDeviceName) diff --git a/src/mididevice.h b/src/mididevice.h index 196a61b..1bd5396 100644 --- a/src/mididevice.h +++ b/src/mididevice.h @@ -27,6 +27,7 @@ #include #include #include +#include class CMiniDexed; @@ -65,6 +66,8 @@ private: typedef std::unordered_map TDeviceMap; static TDeviceMap s_DeviceMap; + + CSpinLock m_MIDISpinLock; }; #endif