Reimplement Backend_Delay to fix threads freezing
So our workaround for making usleep thread-safe mostly worked in that it fixed one of the things making it thread-unsafe, but it seems that sigsuspend, which usleep uses, is also not thread-safe, since sometimes one of our two threads would freeze, stuck inside sigsuspend. So instead of usleep, we're using a trick that Stacken member map suggested: using select. Calling select with no file descriptors to work on will have it block on the kernel level until its timeout is hit. This acts as a sleep. As it turns out, this seems to completely solve our sleep-related problems, and massively reduces the amount of audio buffer underruns as a nice bonus!
This commit is contained in:
parent
108b0282bb
commit
a4479f9c07
1 changed files with 5 additions and 1 deletions
|
@ -158,5 +158,9 @@ unsigned long Backend_GetTicks(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend_Delay(unsigned int ticks) {
|
void Backend_Delay(unsigned int ticks) {
|
||||||
usleep(ticks * 1000);
|
struct timeval timeout;
|
||||||
|
timeout.tv_sec = ticks / 1000;
|
||||||
|
timeout.tv_usec = (ticks * 1000) % 1000000;
|
||||||
|
|
||||||
|
select(0, NULL, NULL, NULL, &timeout);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue