mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-23 16:54:03 +02:00
Simplify the ma_thread structure.
This commit is contained in:
+11
-26
@@ -3000,27 +3000,12 @@ typedef enum
|
|||||||
ma_thread_priority_default = 0
|
ma_thread_priority_default = 0
|
||||||
} ma_thread_priority;
|
} ma_thread_priority;
|
||||||
|
|
||||||
typedef struct
|
#if defined(MA_WIN32)
|
||||||
{
|
typedef ma_handle ma_thread;
|
||||||
ma_context* pContext;
|
|
||||||
|
|
||||||
union
|
|
||||||
{
|
|
||||||
#ifdef MA_WIN32
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
/*HANDLE*/ ma_handle hThread;
|
|
||||||
} win32;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef MA_POSIX
|
#if defined(MA_POSIX)
|
||||||
struct
|
typedef pthread_t ma_thread;
|
||||||
{
|
|
||||||
pthread_t thread;
|
|
||||||
} posix;
|
|
||||||
#endif
|
#endif
|
||||||
int _unused;
|
|
||||||
};
|
|
||||||
} ma_thread;
|
|
||||||
|
|
||||||
#if defined(MA_WIN32)
|
#if defined(MA_WIN32)
|
||||||
typedef ma_handle ma_mutex;
|
typedef ma_handle ma_mutex;
|
||||||
@@ -3035,9 +3020,9 @@ typedef ma_handle ma_event;
|
|||||||
#if defined(MA_POSIX)
|
#if defined(MA_POSIX)
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
ma_uint32 value;
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
pthread_cond_t cond;
|
pthread_cond_t cond;
|
||||||
ma_uint32 value;
|
|
||||||
} ma_event;
|
} ma_event;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -7707,19 +7692,19 @@ static int ma_thread_priority_to_win32(ma_thread_priority priority)
|
|||||||
|
|
||||||
static ma_result ma_thread_create__win32(ma_thread* pThread, ma_thread_priority priority, ma_thread_entry_proc entryProc, void* pData)
|
static ma_result ma_thread_create__win32(ma_thread* pThread, ma_thread_priority priority, ma_thread_entry_proc entryProc, void* pData)
|
||||||
{
|
{
|
||||||
pThread->win32.hThread = CreateThread(NULL, 0, entryProc, pData, 0, NULL);
|
*pThread = CreateThread(NULL, 0, entryProc, pData, 0, NULL);
|
||||||
if (pThread->win32.hThread == NULL) {
|
if (*pThread == NULL) {
|
||||||
return ma_result_from_GetLastError(GetLastError());
|
return ma_result_from_GetLastError(GetLastError());
|
||||||
}
|
}
|
||||||
|
|
||||||
SetThreadPriority((HANDLE)pThread->win32.hThread, ma_thread_priority_to_win32(priority));
|
SetThreadPriority((HANDLE)*pThread, ma_thread_priority_to_win32(priority));
|
||||||
|
|
||||||
return MA_SUCCESS;
|
return MA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ma_thread_wait__win32(ma_thread* pThread)
|
static void ma_thread_wait__win32(ma_thread* pThread)
|
||||||
{
|
{
|
||||||
WaitForSingleObject(pThread->win32.hThread, INFINITE);
|
WaitForSingleObject((HANDLE)*pThread, INFINITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ma_sleep__win32(ma_uint32 milliseconds)
|
static void ma_sleep__win32(ma_uint32 milliseconds)
|
||||||
@@ -7870,7 +7855,7 @@ static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
result = pthread_create(&pThread->posix.thread, pAttr, entryProc, pData);
|
result = pthread_create(pThread, pAttr, entryProc, pData);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
return ma_result_from_errno(result);
|
return ma_result_from_errno(result);
|
||||||
}
|
}
|
||||||
@@ -7880,7 +7865,7 @@ static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority
|
|||||||
|
|
||||||
static void ma_thread_wait__posix(ma_thread* pThread)
|
static void ma_thread_wait__posix(ma_thread* pThread)
|
||||||
{
|
{
|
||||||
pthread_join(pThread->posix.thread, NULL);
|
pthread_join(pThread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MA_EMSCRIPTEN)
|
#if !defined(MA_EMSCRIPTEN)
|
||||||
|
|||||||
Reference in New Issue
Block a user