mirror of https://github.com/mgba-emu/mgba.git
GBA Thread: Handle the lack of a sync object properly
This commit is contained in:
parent
da3c45a0e7
commit
090048ec06
|
@ -628,18 +628,34 @@ void GBASyncWaitFrameEnd(struct GBASync* sync) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GBASyncDrawingFrame(struct GBASync* sync) {
|
bool GBASyncDrawingFrame(struct GBASync* sync) {
|
||||||
|
if (!sync) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return sync->videoFrameSkip <= 0;
|
return sync->videoFrameSkip <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncSuspendDrawing(struct GBASync* sync) {
|
void GBASyncSuspendDrawing(struct GBASync* sync) {
|
||||||
|
if (!sync) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_changeVideoSync(sync, false);
|
_changeVideoSync(sync, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncResumeDrawing(struct GBASync* sync) {
|
void GBASyncResumeDrawing(struct GBASync* sync) {
|
||||||
|
if (!sync) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_changeVideoSync(sync, true);
|
_changeVideoSync(sync, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncProduceAudio(struct GBASync* sync, bool wait) {
|
void GBASyncProduceAudio(struct GBASync* sync, bool wait) {
|
||||||
|
if (!sync) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (sync->audioWait && wait) {
|
if (sync->audioWait && wait) {
|
||||||
// TODO loop properly in event of spurious wakeups
|
// TODO loop properly in event of spurious wakeups
|
||||||
ConditionWait(&sync->audioRequiredCond, &sync->audioBufferMutex);
|
ConditionWait(&sync->audioRequiredCond, &sync->audioBufferMutex);
|
||||||
|
@ -648,14 +664,26 @@ void GBASyncProduceAudio(struct GBASync* sync, bool wait) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncLockAudio(struct GBASync* sync) {
|
void GBASyncLockAudio(struct GBASync* sync) {
|
||||||
|
if (!sync) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MutexLock(&sync->audioBufferMutex);
|
MutexLock(&sync->audioBufferMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncUnlockAudio(struct GBASync* sync) {
|
void GBASyncUnlockAudio(struct GBASync* sync) {
|
||||||
|
if (!sync) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MutexUnlock(&sync->audioBufferMutex);
|
MutexUnlock(&sync->audioBufferMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncConsumeAudio(struct GBASync* sync) {
|
void GBASyncConsumeAudio(struct GBASync* sync) {
|
||||||
|
if (!sync) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ConditionWake(&sync->audioRequiredCond);
|
ConditionWake(&sync->audioRequiredCond);
|
||||||
MutexUnlock(&sync->audioBufferMutex);
|
MutexUnlock(&sync->audioBufferMutex);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue