all repos — mgba @ 041113b09cb8ac12b132cd2be03d3489966376d3

mGBA Game Boy Advance Emulator

GBA Video: Recover proxy thread cleanly
Jeffrey Pfau jeffrey@endrift.com
Wed, 17 Aug 2016 22:17:20 -0700
commit

041113b09cb8ac12b132cd2be03d3489966376d3

parent

f5a7fa627eb238052007d63b1eb061a6b6bc2075

1 files changed, 14 insertions(+), 2 deletions(-)

jump to
M src/gba/renderers/thread-proxy.csrc/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);