Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
4da8834a
Commit
4da8834a
authored
Aug 05, 2018
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor the main loop.
parent
1a6a47af
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
+57
-0
mini_al.h
mini_al.h
+57
-0
No files found.
mini_al.h
View file @
4da8834a
...
@@ -19279,6 +19279,62 @@ mal_thread_result MAL_THREADCALL mal_worker_thread(void* pData)
...
@@ -19279,6 +19279,62 @@ mal_thread_result MAL_THREADCALL mal_worker_thread(void* pData)
mal_CoInitializeEx(pDevice->pContext, NULL, 0); // 0 = COINIT_MULTITHREADED
mal_CoInitializeEx(pDevice->pContext, NULL, 0); // 0 = COINIT_MULTITHREADED
#endif
#endif
#if 1
// When the device is being initialized it's initial state is set to MAL_STATE_UNINITIALIZED. Before returning from
// mal_device_init(), the state needs to be set to something valid. In mini_al the device's default state immediately
// after initialization is stopped, so therefore we need to mark the device as such. mini_al will wait on the worker
// thread to signal an event to know when the worker thread is ready for action.
mal_device__set_state(pDevice, MAL_STATE_STOPPED);
mal_event_signal(&pDevice->stopEvent);
for (;;) {
// We wait on an event to know when something has requested that the device be started and the main loop entered.
mal_event_wait(&pDevice->wakeupEvent);
// Default result code.
pDevice->workResult = MAL_SUCCESS;
// If the reason for the wake up is that we are terminating, just break from the loop.
if (mal_device__get_state(pDevice) == MAL_STATE_UNINITIALIZED) {
break;
}
// Getting to this point means the device is wanting to get started. The function that has requested that the device
// be started will be waiting on an event (pDevice->startEvent) which means we need to make sure we signal the event
// in both the success and error case. It's important that the state of the device is set _before_ signaling the event.
mal_assert(mal_device__get_state(pDevice) == MAL_STATE_STARTING);
pDevice->workResult = pDevice->pContext->onDeviceStart(pDevice);
if (pDevice->workResult != MAL_SUCCESS) {
mal_device__set_state(pDevice, MAL_STATE_STOPPED);
mal_event_signal(&pDevice->startEvent);
continue;
}
// At this point the device should be started.
mal_device__set_state(pDevice, MAL_STATE_STARTED);
mal_event_signal(&pDevice->startEvent);
// Now we just enter the main loop. When the main loop is terminated the device needs to be marked as stopped. This can
// be broken with mal_device__break_main_loop().
pDevice->pContext->onDeviceMainLoop(pDevice);
// Getting here means we have broken from the main loop which happens the application has requested that device be stopped.
pDevice->pContext->onDeviceStop(pDevice);
// After the device has stopped, make sure an event is posted.
mal_stop_proc onStop = pDevice->onStop;
if (onStop) {
onStop(pDevice);
}
// A function somewhere is waiting for the device to have stopped for real so we need to signal an event to allow it to continue.
mal_device__set_state(pDevice, MAL_STATE_STOPPED);
mal_event_signal(&pDevice->stopEvent);
}
#else
// This is only used to prevent posting onStop() when the device is first initialized.
// This is only used to prevent posting onStop() when the device is first initialized.
mal_bool32 skipNextStopEvent = MAL_TRUE;
mal_bool32 skipNextStopEvent = MAL_TRUE;
...
@@ -19330,6 +19386,7 @@ mal_thread_result MAL_THREADCALL mal_worker_thread(void* pData)
...
@@ -19330,6 +19386,7 @@ mal_thread_result MAL_THREADCALL mal_worker_thread(void* pData)
// Now we just enter the main loop. The main loop can be broken with mal_device__break_main_loop().
// Now we just enter the main loop. The main loop can be broken with mal_device__break_main_loop().
pDevice->pContext->onDeviceMainLoop(pDevice);
pDevice->pContext->onDeviceMainLoop(pDevice);
}
}
#endif
// Make sure we aren't continuously waiting on a stop event.
// Make sure we aren't continuously waiting on a stop event.
mal_event_signal(&pDevice->stopEvent); // <-- Is this still needed?
mal_event_signal(&pDevice->stopEvent); // <-- Is this still needed?
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment