mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
Remove an old device job thread object.
This was used by AAudio for dealing with rerouting, but with the new backend architecture it is no longer needed.
This commit is contained in:
-181
@@ -7208,35 +7208,6 @@ typedef enum
|
||||
MA_ATOMIC_SAFE_TYPE_DECL(i32, 4, device_status)
|
||||
|
||||
|
||||
/*
|
||||
Device job thread. This is used by backends that require asynchronous processing of certain
|
||||
operations. It is not used by all backends.
|
||||
|
||||
The device job thread is made up of a thread and a job queue. You can post a job to the thread with
|
||||
ma_device_job_thread_post(). The thread will do the processing of the job.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
ma_bool32 noThread; /* Set this to true if you want to process jobs yourself. */
|
||||
ma_uint32 jobQueueCapacity;
|
||||
ma_uint32 jobQueueFlags;
|
||||
} ma_device_job_thread_config;
|
||||
|
||||
MA_API ma_device_job_thread_config ma_device_job_thread_config_init(void);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ma_thread thread;
|
||||
ma_job_queue jobQueue;
|
||||
ma_bool32 _hasThread;
|
||||
} ma_device_job_thread;
|
||||
|
||||
MA_API ma_result ma_device_job_thread_init(const ma_device_job_thread_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_device_job_thread* pJobThread);
|
||||
MA_API void ma_device_job_thread_uninit(ma_device_job_thread* pJobThread, const ma_allocation_callbacks* pAllocationCallbacks);
|
||||
MA_API ma_result ma_device_job_thread_post(ma_device_job_thread* pJobThread, const ma_job* pJob);
|
||||
MA_API ma_result ma_device_job_thread_next(ma_device_job_thread* pJobThread, ma_job* pJob);
|
||||
|
||||
|
||||
|
||||
typedef enum ma_threading_mode
|
||||
{
|
||||
@@ -40101,7 +40072,6 @@ typedef struct ma_context_state_aaudio
|
||||
MA_PFN_AAudioStream_getFramesPerBurst AAudioStream_getFramesPerBurst;
|
||||
MA_PFN_AAudioStream_requestStart AAudioStream_requestStart;
|
||||
MA_PFN_AAudioStream_requestStop AAudioStream_requestStop;
|
||||
ma_device_job_thread jobThread; /* For processing operations outside of the error callback, specifically device disconnections and rerouting. */
|
||||
} ma_context_state_aaudio;
|
||||
|
||||
typedef struct ma_device_state_aaudio
|
||||
@@ -40248,26 +40218,6 @@ static ma_result ma_context_init__aaudio(ma_context* pContext, const void* pCont
|
||||
}
|
||||
#endif
|
||||
|
||||
/* We need a job thread so we can deal with rerouting. */
|
||||
{
|
||||
ma_result result;
|
||||
ma_device_job_thread_config jobThreadConfig;
|
||||
|
||||
jobThreadConfig = ma_device_job_thread_config_init();
|
||||
|
||||
result = ma_device_job_thread_init(&jobThreadConfig, &pContext->allocationCallbacks, &pContextStateAAudio->jobThread);
|
||||
if (result != MA_SUCCESS) {
|
||||
#if !defined(MA_NO_RUNTIME_LINKING)
|
||||
{
|
||||
ma_dlclose(ma_context_get_log(pContext), pContextStateAAudio->hAAudio);
|
||||
}
|
||||
#endif
|
||||
|
||||
ma_free(pContextStateAAudio, ma_context_get_allocation_callbacks(pContext));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
*ppContextState = pContextStateAAudio;
|
||||
|
||||
return MA_SUCCESS;
|
||||
@@ -40277,8 +40227,6 @@ static void ma_context_uninit__aaudio(ma_context* pContext)
|
||||
{
|
||||
ma_context_state_aaudio* pContextStateAAudio = ma_context_get_backend_state__aaudio(pContext);
|
||||
|
||||
ma_device_job_thread_uninit(&pContextStateAAudio->jobThread, &pContext->allocationCallbacks);
|
||||
|
||||
#if !defined(MA_NO_RUNTIME_LINKING)
|
||||
{
|
||||
ma_dlclose(ma_context_get_log(pContext), pContextStateAAudio->hAAudio);
|
||||
@@ -44352,135 +44300,6 @@ static ma_result ma_context_uninit_backend_apis(ma_context* pContext)
|
||||
}
|
||||
|
||||
|
||||
/* The default capacity doesn't need to be too big. */
|
||||
#ifndef MA_DEFAULT_DEVICE_JOB_QUEUE_CAPACITY
|
||||
#define MA_DEFAULT_DEVICE_JOB_QUEUE_CAPACITY 32
|
||||
#endif
|
||||
|
||||
MA_API ma_device_job_thread_config ma_device_job_thread_config_init(void)
|
||||
{
|
||||
ma_device_job_thread_config config;
|
||||
|
||||
MA_ZERO_OBJECT(&config);
|
||||
config.noThread = MA_FALSE;
|
||||
config.jobQueueCapacity = MA_DEFAULT_DEVICE_JOB_QUEUE_CAPACITY;
|
||||
config.jobQueueFlags = 0;
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
static ma_thread_result MA_THREADCALL ma_device_job_thread_entry(void* pUserData)
|
||||
{
|
||||
ma_device_job_thread* pJobThread = (ma_device_job_thread*)pUserData;
|
||||
MA_ASSERT(pJobThread != NULL);
|
||||
|
||||
for (;;) {
|
||||
ma_result result;
|
||||
ma_job job;
|
||||
|
||||
result = ma_device_job_thread_next(pJobThread, &job);
|
||||
if (result != MA_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (job.toc.breakup.code == MA_JOB_TYPE_QUIT) {
|
||||
break;
|
||||
}
|
||||
|
||||
ma_job_process(&job);
|
||||
}
|
||||
|
||||
return (ma_thread_result)0;
|
||||
}
|
||||
|
||||
MA_API ma_result ma_device_job_thread_init(const ma_device_job_thread_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_device_job_thread* pJobThread)
|
||||
{
|
||||
ma_result result;
|
||||
ma_job_queue_config jobQueueConfig;
|
||||
|
||||
if (pJobThread == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
MA_ZERO_OBJECT(pJobThread);
|
||||
|
||||
if (pConfig == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
|
||||
/* Initialize the job queue before the thread to ensure it's in a valid state. */
|
||||
jobQueueConfig = ma_job_queue_config_init(pConfig->jobQueueFlags, pConfig->jobQueueCapacity);
|
||||
|
||||
result = ma_job_queue_init(&jobQueueConfig, pAllocationCallbacks, &pJobThread->jobQueue);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result; /* Failed to initialize job queue. */
|
||||
}
|
||||
|
||||
|
||||
/* The thread needs to be initialized after the job queue to ensure the thread doesn't try to access it prematurely. */
|
||||
if (pConfig->noThread == MA_FALSE) {
|
||||
result = ma_thread_create(&pJobThread->thread, ma_thread_priority_normal, 0, ma_device_job_thread_entry, pJobThread, pAllocationCallbacks);
|
||||
if (result != MA_SUCCESS) {
|
||||
ma_job_queue_uninit(&pJobThread->jobQueue, pAllocationCallbacks);
|
||||
return result; /* Failed to create the job thread. */
|
||||
}
|
||||
|
||||
pJobThread->_hasThread = MA_TRUE;
|
||||
} else {
|
||||
pJobThread->_hasThread = MA_FALSE;
|
||||
}
|
||||
|
||||
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
MA_API void ma_device_job_thread_uninit(ma_device_job_thread* pJobThread, const ma_allocation_callbacks* pAllocationCallbacks)
|
||||
{
|
||||
if (pJobThread == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* The first thing to do is post a quit message to the job queue. If we're using a thread we'll need to wait for it. */
|
||||
{
|
||||
ma_job job = ma_job_init(MA_JOB_TYPE_QUIT);
|
||||
ma_device_job_thread_post(pJobThread, &job);
|
||||
}
|
||||
|
||||
/* Wait for the thread to terminate naturally. */
|
||||
if (pJobThread->_hasThread) {
|
||||
ma_thread_wait(&pJobThread->thread);
|
||||
}
|
||||
|
||||
/* At this point the thread should be terminated so we can safely uninitialize the job queue. */
|
||||
ma_job_queue_uninit(&pJobThread->jobQueue, pAllocationCallbacks);
|
||||
}
|
||||
|
||||
MA_API ma_result ma_device_job_thread_post(ma_device_job_thread* pJobThread, const ma_job* pJob)
|
||||
{
|
||||
if (pJobThread == NULL || pJob == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
return ma_job_queue_post(&pJobThread->jobQueue, pJob);
|
||||
}
|
||||
|
||||
MA_API ma_result ma_device_job_thread_next(ma_device_job_thread* pJobThread, ma_job* pJob)
|
||||
{
|
||||
if (pJob == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
MA_ZERO_OBJECT(pJob);
|
||||
|
||||
if (pJobThread == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
return ma_job_queue_next(&pJobThread->jobQueue, pJob);
|
||||
}
|
||||
|
||||
|
||||
MA_API ma_bool32 ma_device_id_equal(const ma_device_id* pA, const ma_device_id* pB)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user