From 57776c90275fdc6e23167679f6400095080404ad Mon Sep 17 00:00:00 2001 From: PatrickvL Date: Fri, 2 Feb 2018 17:37:23 +0100 Subject: [PATCH] NV2A : Trying to fix locking (not very successful atm) --- src/devices/video/EmuNV2A_PFIFO.cpp | 5 ++++- src/devices/video/EmuNV2A_PGRAPH.cpp | 18 +++++++++++++----- src/devices/video/nv2a.cpp | 1 - src/devices/video/nv2a.h | 6 +++--- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/devices/video/EmuNV2A_PFIFO.cpp b/src/devices/video/EmuNV2A_PFIFO.cpp index 5f2738d8d..4b39c4f13 100644 --- a/src/devices/video/EmuNV2A_PFIFO.cpp +++ b/src/devices/video/EmuNV2A_PFIFO.cpp @@ -361,8 +361,11 @@ int pfifo_puller_thread(NV2AState *d) while (true) { state->cache_lock.lock(); + + std::unique_lock _cache_lock(state->cache_lock); // TODO : Is this correct?? + while (state->cache.empty() || !state->pull_enabled) { - state->cache_cond.wait(state->cache_lock); + state->cache_cond.wait(_cache_lock); } // Copy cache to working_cache diff --git a/src/devices/video/EmuNV2A_PGRAPH.cpp b/src/devices/video/EmuNV2A_PGRAPH.cpp index 794097c62..ca5bd0756 100644 --- a/src/devices/video/EmuNV2A_PGRAPH.cpp +++ b/src/devices/video/EmuNV2A_PGRAPH.cpp @@ -713,8 +713,10 @@ static void pgraph_method(NV2AState *d, pg->lock.lock(); qemu_mutex_unlock_iothread(); + std::unique_lock _lock(pg->lock); // TODO : Is this correct?? + while (pg->pending_interrupts & NV_PGRAPH_INTR_ERROR) { - pg->interrupt_cond.wait(pg->lock); + pg->interrupt_cond.wait(_lock); } } break; @@ -784,7 +786,9 @@ static void pgraph_method(NV2AState *d, != GET_MASK(s, NV_PGRAPH_SURFACE_WRITE_3D)) { break; } - pg->flip_3d.wait(pg->lock); + std::unique_lock _lock(pg->lock); // TODO : Is this correct?? + + pg->flip_3d.wait(_lock); } NV2A_DPRINTF("flip stall done\n"); break; @@ -2598,15 +2602,19 @@ static void pgraph_context_switch(NV2AState *d, unsigned int channel_id) d->pgraph.lock.lock(); qemu_mutex_unlock_iothread(); + std::unique_lock _lock(d->pgraph.lock); // TODO : Is this correct?? + while (d->pgraph.pending_interrupts & NV_PGRAPH_INTR_CONTEXT_SWITCH) { - d->pgraph.interrupt_cond.wait(d->pgraph.lock); + d->pgraph.interrupt_cond.wait(_lock); } } } static void pgraph_wait_fifo_access(NV2AState *d) { - while (!d->pgraph.fifo_access) { - d->pgraph.fifo_access_cond.wait(d->pgraph.lock); + std::unique_lock _lock(d->pgraph.lock); // TODO : Is this correct?? + + while (!d->pgraph.fifo_access) { + d->pgraph.fifo_access_cond.wait(_lock); } } diff --git a/src/devices/video/nv2a.cpp b/src/devices/video/nv2a.cpp index ad189ce47..b5112c3ae 100644 --- a/src/devices/video/nv2a.cpp +++ b/src/devices/video/nv2a.cpp @@ -704,7 +704,6 @@ uint32_t NV2ADevice::MMIORead(int barIndex, uint32_t addr, unsigned size) } } - // TODO : Log unexpected bar access EmuWarning("NV2ADevice::MMIORead: Unhandled barIndex %d, addr %08X, size %d", barIndex, addr, size); return 0; } diff --git a/src/devices/video/nv2a.h b/src/devices/video/nv2a.h index d2d728cea..a7e03eb7f 100644 --- a/src/devices/video/nv2a.h +++ b/src/devices/video/nv2a.h @@ -293,7 +293,7 @@ typedef struct GraphicsContext { typedef struct PGRAPHState { - std::unique_lock lock; + std::mutex lock; // std::unique_lock(lock, std::defer_lock); uint32_t pending_interrupts; uint32_t enabled_interrupts; @@ -436,7 +436,7 @@ typedef struct Cache1State { enum FIFOEngine last_engine; /* The actual command queue */ - std::unique_lock cache_lock; + std::mutex cache_lock; // std::unique_lock(cache_lock, std::defer_lock); std::condition_variable cache_cond; std::queue cache; std::queue working_cache; @@ -528,7 +528,7 @@ typedef struct NV2AState { uint8_t cr[256]; /* CRT registers */ } prmcio; // Not in xqemu/openxbox? - std::mutex io_lock; // TODO ? std::unique_lock + std::mutex io_lock; //SDL_Window *sdl_window; } NV2AState;