Properly respect the WAIT_INIT flag.

This commit is contained in:
David Reid
2021-06-06 07:16:09 +10:00
parent 7d00be85d7
commit b2cabfbe8d
+17 -1
View File
@@ -7565,12 +7565,24 @@ static ma_result ma_resource_manager_data_buffer_init_internal(ma_resource_manag
/* Loading synchronously or the data has already been fully loaded. We can just initialize the connector from here without a job. */ /* Loading synchronously or the data has already been fully loaded. We can just initialize the connector from here without a job. */
result = ma_resource_manager_data_buffer_init_connector(pDataBuffer, NULL); result = ma_resource_manager_data_buffer_init_connector(pDataBuffer, NULL);
c89atomic_exchange_i32(&pDataBuffer->result, result); c89atomic_exchange_i32(&pDataBuffer->result, result);
if (pNotification != NULL) {
ma_async_notification_signal(pNotification, (result == MA_SUCCESS) ? MA_NOTIFICATION_COMPLETE : MA_NOTIFICATION_FAILED);
}
} else { } else {
/* The node's data supply isn't initialized yet. The caller has requested that we load asynchronously so we need to post a job to do this. */ /* The node's data supply isn't initialized yet. The caller has requested that we load asynchronously so we need to post a job to do this. */
ma_job job = ma_job_init(MA_JOB_LOAD_DATA_BUFFER); ma_job job;
ma_resource_manager_inline_notification initNotification; /* Used when the WAIT_INIT flag is set. */
if ((flags & MA_DATA_SOURCE_FLAG_WAIT_INIT) != 0) {
ma_resource_manager_inline_notification_init(pResourceManager, &initNotification);
}
job = ma_job_init(MA_JOB_LOAD_DATA_BUFFER);
job.order = ma_resource_manager_data_buffer_next_execution_order(pDataBuffer); job.order = ma_resource_manager_data_buffer_next_execution_order(pDataBuffer);
job.loadDataBuffer.pDataBuffer = pDataBuffer; job.loadDataBuffer.pDataBuffer = pDataBuffer;
job.loadDataBuffer.pCompletedNotification = pNotification; job.loadDataBuffer.pCompletedNotification = pNotification;
job.loadDataBuffer.pInitNotification = ((flags & MA_DATA_SOURCE_FLAG_WAIT_INIT) != 0) ? &initNotification : NULL;
result = ma_resource_manager_post_job(pResourceManager, &job); result = ma_resource_manager_post_job(pResourceManager, &job);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
@@ -7580,6 +7592,10 @@ static ma_result ma_resource_manager_data_buffer_init_internal(ma_resource_manag
} else { } else {
/* The job has been posted, so make sure the buffer's status is set to busy. The worker thread will */ /* The job has been posted, so make sure the buffer's status is set to busy. The worker thread will */
c89atomic_exchange_i32(&pDataBuffer->result, MA_BUSY); c89atomic_exchange_i32(&pDataBuffer->result, MA_BUSY);
if ((flags & MA_DATA_SOURCE_FLAG_WAIT_INIT) != 0) {
ma_resource_manager_inline_notification_wait_and_uninit(&initNotification);
}
} }
} }