The syscall itself is temporary.
Signed-off-by: Huw Davies huw@codeweavers.com --- dlls/winealsa.drv/alsa.c | 1 + dlls/winealsa.drv/alsamidi.c | 19 +++++++++++++++++++ dlls/winealsa.drv/midi.c | 31 ++++++++++++++++--------------- dlls/winealsa.drv/unixlib.h | 2 ++ 4 files changed, 38 insertions(+), 15 deletions(-)
diff --git a/dlls/winealsa.drv/alsa.c b/dlls/winealsa.drv/alsa.c index b629cd8317a..eb16203dbf9 100644 --- a/dlls/winealsa.drv/alsa.c +++ b/dlls/winealsa.drv/alsa.c @@ -2449,5 +2449,6 @@ unixlib_entry_t __wine_unix_call_funcs[] = midi_in_message,
midi_seq_lock, /* temporary */ + midi_in_lock, midi_seq_open, }; diff --git a/dlls/winealsa.drv/alsamidi.c b/dlls/winealsa.drv/alsamidi.c index 27ee17caa24..1ba674c234f 100644 --- a/dlls/winealsa.drv/alsamidi.c +++ b/dlls/winealsa.drv/alsamidi.c @@ -60,6 +60,7 @@ struct midi_dest };
static pthread_mutex_t seq_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t in_buffer_mutex = PTHREAD_MUTEX_INITIALIZER;
static unsigned int num_dests, num_srcs; static struct midi_dest dests[MAX_MIDIOUTDRV]; @@ -86,6 +87,24 @@ NTSTATUS midi_seq_lock(void *args) return STATUS_SUCCESS; }
+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 snd_seq_t *seq_open(int *port_in_ret) { static int midi_warn; diff --git a/dlls/winealsa.drv/midi.c b/dlls/winealsa.drv/midi.c index bd73c1f5db2..70e6caebfc7 100644 --- a/dlls/winealsa.drv/midi.c +++ b/dlls/winealsa.drv/midi.c @@ -54,15 +54,6 @@ static int MIDM_NumDevs = 0;
static int numStartedMidiIn = 0;
-static CRITICAL_SECTION crit_sect; /* protects all MidiIn buffer 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;
@@ -76,6 +67,16 @@ static void seq_unlock(void) ALSA_CALL(midi_seq_lock, (void *)(UINT_PTR)0); }
+static void in_buffer_lock(void) +{ + ALSA_CALL(midi_in_lock, (void *)(UINT_PTR)1); +} + +static void in_buffer_unlock(void) +{ + ALSA_CALL(midi_in_lock, (void *)(UINT_PTR)0); +} + static void notify_client(struct notify_context *notify) { TRACE("dev_id = %d msg = %d param1 = %04lX param2 = %04lX\n", notify->dev_id, notify->msg, notify->param_1, notify->param_2); @@ -240,7 +241,7 @@ static void handle_midi_event(snd_seq_event_t *ev) LPBYTE ptr = ev->data.ext.ptr; LPMIDIHDR lpMidiHdr;
- EnterCriticalSection(&crit_sect); + in_buffer_lock(); while (len) { if ((lpMidiHdr = MidiInDev[wDevID].lpQueueHdr) != NULL) { int copylen = min(len, lpMidiHdr->dwBufferLength - lpMidiHdr->dwBytesRecorded); @@ -262,7 +263,7 @@ static void handle_midi_event(snd_seq_event_t *ev) break; } } - LeaveCriticalSection(&crit_sect); + in_buffer_unlock(); } break; case SND_SEQ_EVENT_SENSING: @@ -475,7 +476,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; @@ -489,7 +490,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; } @@ -506,7 +507,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; @@ -514,7 +515,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/winealsa.drv/unixlib.h b/dlls/winealsa.drv/unixlib.h index 7907ad24efa..263e83eda57 100644 --- a/dlls/winealsa.drv/unixlib.h +++ b/dlls/winealsa.drv/unixlib.h @@ -301,6 +301,7 @@ enum alsa_funcs alsa_midi_in_message,
alsa_midi_seq_lock, /* temporary */ + alsa_midi_in_lock, alsa_midi_seq_open, };
@@ -309,6 +310,7 @@ NTSTATUS midi_out_message(void *args) DECLSPEC_HIDDEN; NTSTATUS midi_in_message(void *args) DECLSPEC_HIDDEN;
NTSTATUS midi_seq_lock(void *args) DECLSPEC_HIDDEN; +NTSTATUS midi_in_lock(void *args) DECLSPEC_HIDDEN; NTSTATUS midi_seq_open(void *args) DECLSPEC_HIDDEN;
extern unixlib_handle_t alsa_handle;