rawmidi: Use a background thread rather than a subprocess

This removes the last usage of fork() in xystem35.
This commit is contained in:
kichikuou
2021-11-13 12:51:14 +09:00
parent d0ad06e7c5
commit d8513d78e4
5 changed files with 192 additions and 296 deletions
+23
View File
@@ -70,3 +70,26 @@ void *msgq_dequeue(struct msgq *q) {
free(e);
return msg;
}
void *msgq_dequeue_timeout(struct msgq *q, uint32_t timeout_ms) {
SDL_LockMutex(q->mutex);
while (!q->head && SDL_CondWaitTimeout(q->cond_nonempty, q->mutex, timeout_ms) == 0)
;
if (!q->head) { // timed out
SDL_UnlockMutex(q->mutex);
return NULL;
}
struct msgq_elem *e = q->head;
q->head = e->next;
if (!e->next)
q->last = NULL;
SDL_UnlockMutex(q->mutex);
void *msg = e->msg;
free(e);
return msg;
}