GBA Video: Recover proxy thread cleanly
Jeffrey Pfau jeffrey@endrift.com
Wed, 17 Aug 2016 22:17:20 -0700
1 files changed,
14 insertions(+),
2 deletions(-)
jump to
M
src/gba/renderers/thread-proxy.c
→
src/gba/renderers/thread-proxy.c
@@ -124,6 +124,19 @@
mappedMemoryFree(proxyRenderer->vramProxy, SIZE_VRAM); } +void _proxyThreadRecover(struct GBAVideoThreadProxyRenderer* proxyRenderer) { + MutexLock(&proxyRenderer->mutex); + while (proxyRenderer->threadState != PROXY_THREAD_STOPPED) { + MutexUnlock(&proxyRenderer->mutex); + return; + } + RingFIFOClear(&proxyRenderer->dirtyQueue); + MutexUnlock(&proxyRenderer->mutex); + ThreadJoin(proxyRenderer->thread); + proxyRenderer->threadState = PROXY_THREAD_IDLE; + ThreadCreate(&proxyRenderer->thread, _proxyThread, proxyRenderer); +} + static bool _writeData(struct GBAVideoThreadProxyRenderer* proxyRenderer, void* data, size_t length) { while (!RingFIFOWrite(&proxyRenderer->dirtyQueue, data, length)) { mLOG(GBA_VIDEO, WARN, "Can't write 0x%zu bytes. Proxy thread asleep?", length);@@ -245,8 +258,7 @@ void GBAVideoThreadProxyRendererFinishFrame(struct GBAVideoRenderer* renderer) {
struct GBAVideoThreadProxyRenderer* proxyRenderer = (struct GBAVideoThreadProxyRenderer*) renderer; if (proxyRenderer->threadState == PROXY_THREAD_STOPPED) { mLOG(GBA_VIDEO, ERROR, "Proxy thread stopped prematurely!"); - GBAVideoThreadProxyRendererDeinit(renderer); - GBAVideoThreadProxyRendererInit(renderer); + _proxyThreadRecover(proxyRenderer); return; } MutexLock(&proxyRenderer->mutex);