winecoreaudio: Move the midi in lock to the unixlib.

The syscall itself is temporary.

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Andrew Eikum <aeikum@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2021-11-29 11:26:45 +00:00 committed by Alexandre Julliard
parent 05731b14d3
commit 9eeee3ddbf
4 changed files with 32 additions and 18 deletions

View File

@ -1633,4 +1633,6 @@ unixlib_entry_t __wine_unix_call_funcs[] =
midi_release,
midi_out_message,
midi_in_message,
midi_in_lock, /* temporary */
};

View File

@ -72,6 +72,8 @@
#undef HRESULT
#undef STDMETHODCALLTYPE
#include <pthread.h>
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h"
@ -112,6 +114,17 @@ static struct midi_dest *dests;
static struct midi_src *srcs;
static CFStringRef midi_in_thread_port_name;
static pthread_mutex_t midi_in_mutex = PTHREAD_MUTEX_INITIALIZER;
NTSTATUS midi_in_lock(void *args)
{
BOOL lock = !!args;
if (lock) pthread_mutex_lock(&midi_in_mutex);
else pthread_mutex_unlock(&midi_in_mutex);
return STATUS_SUCCESS;
}
static void set_in_notify(struct notify_context *notify, struct midi_src *src, WORD dev_id, WORD msg,
DWORD_PTR param_1, DWORD_PTR param_2)
{

View File

@ -52,7 +52,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(midi);
static DWORD MIDIIn_NumDevs = 0;
static CRITICAL_SECTION midiInLock; /* Critical section for MIDI In */
static CFStringRef MIDIInThreadPortName;
static DWORD WINAPI MIDIIn_MessageThread(LPVOID p);
@ -89,9 +89,6 @@ static LONG CoreAudio_MIDIInit(void)
if (MIDIIn_NumDevs > 0)
{
InitializeCriticalSection(&midiInLock);
midiInLock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": midiInLock");
MIDIInThreadPortName = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("MIDIInThreadPortName.%u"), getpid());
CloseHandle( CreateThread(NULL, 0, MIDIIn_MessageThread, NULL, 0, NULL));
}
@ -105,12 +102,6 @@ static LONG CoreAudio_MIDIRelease(void)
UNIX_CALL(midi_release, NULL);
sources = NULL;
if (MIDIIn_NumDevs > 0)
{
midiInLock.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&midiInLock);
}
return DRV_SUCCESS;
}
@ -146,6 +137,11 @@ static void MIDI_NotifyClient(UINT wDevID, WORD wMsg, DWORD_PTR dwParam1, DWORD_
DriverCallback(dwCallBack, uFlags, hDev, wMsg, dwInstance, dwParam1, dwParam2);
}
static void midi_lock( BOOL lock )
{
UNIX_CALL(midi_in_lock, (void *)lock);
}
static DWORD MIDIIn_AddBuffer(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
{
TRACE("wDevID=%d lpMidiHdr=%p dwSize=%d\n", wDevID, lpMidiHdr, dwSize);
@ -175,7 +171,7 @@ static DWORD MIDIIn_AddBuffer(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
return MIDIERR_UNPREPARED;
}
EnterCriticalSection(&midiInLock);
midi_lock( TRUE );
lpMidiHdr->dwFlags &= ~WHDR_DONE;
lpMidiHdr->dwFlags |= MHDR_INQUEUE;
lpMidiHdr->dwBytesRecorded = 0;
@ -189,7 +185,7 @@ static DWORD MIDIIn_AddBuffer(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
ptr = ptr->lpNext);
ptr->lpNext = lpMidiHdr;
}
LeaveCriticalSection(&midiInLock);
midi_lock( FALSE );
return MMSYSERR_NOERROR;
}
@ -204,7 +200,7 @@ static DWORD MIDIIn_Reset(WORD wDevID)
return MMSYSERR_BADDEVICEID;
}
EnterCriticalSection(&midiInLock);
midi_lock( TRUE );
while (sources[wDevID].lpQueueHdr) {
LPMIDIHDR lpMidiHdr = sources[wDevID].lpQueueHdr;
sources[wDevID].lpQueueHdr = lpMidiHdr->lpNext;
@ -213,7 +209,7 @@ static DWORD MIDIIn_Reset(WORD wDevID)
/* FIXME: when called from 16 bit, lpQueueHdr needs to be a segmented ptr */
MIDI_NotifyClient(wDevID, MIM_LONGDATA, (DWORD_PTR)lpMidiHdr, dwTime);
}
LeaveCriticalSection(&midiInLock);
midi_lock( FALSE );
return MMSYSERR_NOERROR;
}
@ -258,7 +254,7 @@ static CFDataRef MIDIIn_MessageHandler(CFMessagePortRef local, SInt32 msgid, CFD
src->state |= 2;
}
EnterCriticalSection(&midiInLock);
midi_lock( TRUE );
currentTime = GetTickCount() - src->startTime;
while (len) {
@ -289,11 +285,11 @@ static CFDataRef MIDIIn_MessageHandler(CFMessagePortRef local, SInt32 msgid, CFD
}
}
LeaveCriticalSection(&midiInLock);
midi_lock( FALSE );
return NULL;
}
EnterCriticalSection(&midiInLock);
midi_lock( TRUE );
currentTime = GetTickCount() - src->startTime;
while (pos < msg->length)
@ -320,7 +316,7 @@ static CFDataRef MIDIIn_MessageHandler(CFMessagePortRef local, SInt32 msgid, CFD
}
MIDI_NotifyClient(msg->devID, MIM_DATA, sendData, currentTime);
}
LeaveCriticalSection(&midiInLock);
midi_lock( FALSE );
break;
default:
CFRunLoopStop(CFRunLoopGetCurrent());

View File

@ -252,12 +252,15 @@ enum unix_funcs
unix_midi_release,
unix_midi_out_message,
unix_midi_in_message,
unix_midi_in_lock, /* temporary */
};
NTSTATUS midi_init( void * ) DECLSPEC_HIDDEN;
NTSTATUS midi_release( void * ) DECLSPEC_HIDDEN;
NTSTATUS midi_out_message( void * ) DECLSPEC_HIDDEN;
NTSTATUS midi_in_message( void * ) DECLSPEC_HIDDEN;
NTSTATUS midi_in_lock( void * ) DECLSPEC_HIDDEN;
extern unixlib_handle_t coreaudio_handle;