The syscall itself is temporary.
Signed-off-by: Huw Davies huw@codeweavers.com --- dlls/wineoss.drv/midi.c | 31 ++++++++++++++++--------------- dlls/wineoss.drv/oss.c | 1 + dlls/wineoss.drv/ossmidi.c | 21 +++++++++++++++++++++ dlls/wineoss.drv/unixlib.h | 2 ++ 4 files changed, 40 insertions(+), 15 deletions(-)
diff --git a/dlls/wineoss.drv/midi.c b/dlls/wineoss.drv/midi.c index 46a0f03e819..4f9e6b3c6f9 100644 --- a/dlls/wineoss.drv/midi.c +++ b/dlls/wineoss.drv/midi.c @@ -70,15 +70,6 @@ static int MIDM_NumDevs = 0;
static int numStartedMidiIn = 0;
-static CRITICAL_SECTION crit_sect; /* protects all MidiIn buffers queues */ -static CRITICAL_SECTION_DEBUG critsect_debug = -{ - 0, 0, &crit_sect, - { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": crit_sect") } -}; -static CRITICAL_SECTION crit_sect = { &critsect_debug, -1, 0, 0, 0, 0 }; - static int end_thread; static HANDLE hThread;
@@ -135,6 +126,16 @@ static LRESULT OSS_MidiExit(void) return 0; }
+static void in_buffer_lock(void) +{ + OSS_CALL(midi_in_lock, ULongToPtr(1)); +} + +static void in_buffer_unlock(void) +{ + OSS_CALL(midi_in_lock, ULongToPtr(0)); +} + static void notify_client(struct notify_context *notify) { TRACE("dev_id = %d msg = %d param1 = %04lX param2 = %04lX\n", @@ -231,7 +232,7 @@ static void midReceiveChar(WORD wDevID, unsigned char value, DWORD dwTime) LPMIDIHDR lpMidiHdr; BOOL sbfb = FALSE;
- EnterCriticalSection(&crit_sect); + in_buffer_lock(); if ((lpMidiHdr = MidiInDev[wDevID].lpQueueHdr) != NULL) { LPBYTE lpData = (LPBYTE) lpMidiHdr->lpData;
@@ -251,7 +252,7 @@ static void midReceiveChar(WORD wDevID, unsigned char value, DWORD dwTime) lpMidiHdr->dwFlags |= MHDR_DONE; MIDI_NotifyClient(wDevID, MIM_LONGDATA, (DWORD_PTR)lpMidiHdr, dwTime); } - LeaveCriticalSection(&crit_sect); + in_buffer_unlock(); return; }
@@ -505,7 +506,7 @@ static DWORD midAddBuffer(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize) if (lpMidiHdr->dwFlags & MHDR_INQUEUE) return MIDIERR_STILLPLAYING; if (!(lpMidiHdr->dwFlags & MHDR_PREPARED)) return MIDIERR_UNPREPARED;
- EnterCriticalSection(&crit_sect); + in_buffer_lock(); lpMidiHdr->dwFlags &= ~WHDR_DONE; lpMidiHdr->dwFlags |= MHDR_INQUEUE; lpMidiHdr->dwBytesRecorded = 0; @@ -520,7 +521,7 @@ static DWORD midAddBuffer(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize) ptr = ptr->lpNext); ptr->lpNext = lpMidiHdr; } - LeaveCriticalSection(&crit_sect); + in_buffer_unlock();
return MMSYSERR_NOERROR; } @@ -537,7 +538,7 @@ static DWORD midReset(WORD wDevID) if (wDevID >= MIDM_NumDevs) return MMSYSERR_BADDEVICEID; if (MidiInDev[wDevID].state == -1) return MIDIERR_NODEVICE;
- EnterCriticalSection(&crit_sect); + in_buffer_lock(); while (MidiInDev[wDevID].lpQueueHdr) { LPMIDIHDR lpMidiHdr = MidiInDev[wDevID].lpQueueHdr; MidiInDev[wDevID].lpQueueHdr = lpMidiHdr->lpNext; @@ -545,7 +546,7 @@ static DWORD midReset(WORD wDevID) lpMidiHdr->dwFlags |= MHDR_DONE; MIDI_NotifyClient(wDevID, MIM_LONGDATA, (DWORD_PTR)lpMidiHdr, dwTime); } - LeaveCriticalSection(&crit_sect); + in_buffer_unlock();
return MMSYSERR_NOERROR; } diff --git a/dlls/wineoss.drv/oss.c b/dlls/wineoss.drv/oss.c index aab7c5a32d6..a9081f2cac9 100644 --- a/dlls/wineoss.drv/oss.c +++ b/dlls/wineoss.drv/oss.c @@ -1410,4 +1410,5 @@ unixlib_entry_t __wine_unix_call_funcs[] = midi_in_message,
midi_seq_open, + midi_in_lock, }; diff --git a/dlls/wineoss.drv/ossmidi.c b/dlls/wineoss.drv/ossmidi.c index f9c34943c46..2f75c4aa773 100644 --- a/dlls/wineoss.drv/ossmidi.c +++ b/dlls/wineoss.drv/ossmidi.c @@ -37,6 +37,7 @@ #include <fcntl.h> #include <sys/ioctl.h> #include <sys/soundcard.h> +#include <pthread.h>
#include "ntstatus.h" #define WIN32_NO_STATUS @@ -59,6 +60,8 @@ struct midi_dest int fd; };
+static pthread_mutex_t in_buffer_mutex = PTHREAD_MUTEX_INITIALIZER; + static unsigned int num_dests, num_srcs, num_synths, seq_refs; static struct midi_dest dests[MAX_MIDIOUTDRV]; static struct midi_src srcs[MAX_MIDIINDRV]; @@ -134,6 +137,24 @@ static int oss_to_win_device_type(int type) } }
+static void in_buffer_lock(void) +{ + pthread_mutex_lock(&in_buffer_mutex); +} + +static void in_buffer_unlock(void) +{ + pthread_mutex_unlock(&in_buffer_mutex); +} + +NTSTATUS midi_in_lock(void *args) +{ + if (args) in_buffer_lock(); + else in_buffer_unlock(); + + return STATUS_SUCCESS; +} + static int seq_open(void) { static int midi_warn = 1; diff --git a/dlls/wineoss.drv/unixlib.h b/dlls/wineoss.drv/unixlib.h index c86bc3450df..544a462dcc4 100644 --- a/dlls/wineoss.drv/unixlib.h +++ b/dlls/wineoss.drv/unixlib.h @@ -302,12 +302,14 @@ enum oss_funcs oss_midi_in_message,
oss_midi_seq_open, /* temporary */ + oss_midi_in_lock, };
NTSTATUS midi_init(void *args) DECLSPEC_HIDDEN; NTSTATUS midi_out_message(void *args) DECLSPEC_HIDDEN; NTSTATUS midi_in_message(void *args) DECLSPEC_HIDDEN; NTSTATUS midi_seq_open(void *args) DECLSPEC_HIDDEN; +NTSTATUS midi_in_lock(void *args) DECLSPEC_HIDDEN;
extern unixlib_handle_t oss_handle;