diff --git a/src/CxbxKrnl/CxbxKrnl.cpp b/src/CxbxKrnl/CxbxKrnl.cpp index f8426ae13..2c1cda78f 100644 --- a/src/CxbxKrnl/CxbxKrnl.cpp +++ b/src/CxbxKrnl/CxbxKrnl.cpp @@ -540,7 +540,7 @@ void TriggerPendingConnectedInterrupts() { for (int i = 0; i < MAX_BUS_INTERRUPT_LEVEL; i++) { // If the interrupt is pending and connected, process it - if (HalSystemInterrupts[i].IsPending() && EmuInterruptList[i]->Connected) { + if (HalSystemInterrupts[i].IsPending() && EmuInterruptList[i] && EmuInterruptList[i]->Connected) { HalSystemInterrupts[i].Trigger(EmuInterruptList[i]); } } diff --git a/src/devices/video/EmuNV2A_PFIFO.cpp b/src/devices/video/EmuNV2A_PFIFO.cpp index 4b39c4f13..8392c6644 100644 --- a/src/devices/video/EmuNV2A_PFIFO.cpp +++ b/src/devices/video/EmuNV2A_PFIFO.cpp @@ -362,10 +362,8 @@ 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(_cache_lock); + state->cache_cond.wait(state->cache_lock); } // Copy cache to working_cache diff --git a/src/devices/video/EmuNV2A_PGRAPH.cpp b/src/devices/video/EmuNV2A_PGRAPH.cpp index ca5bd0756..9c990334f 100644 --- a/src/devices/video/EmuNV2A_PGRAPH.cpp +++ b/src/devices/video/EmuNV2A_PGRAPH.cpp @@ -713,10 +713,8 @@ 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(_lock); + pg->interrupt_cond.wait(pg->lock); } } break; @@ -786,9 +784,8 @@ static void pgraph_method(NV2AState *d, != GET_MASK(s, NV_PGRAPH_SURFACE_WRITE_3D)) { break; } - std::unique_lock _lock(pg->lock); // TODO : Is this correct?? - pg->flip_3d.wait(_lock); + pg->flip_3d.wait(pg->lock); } NV2A_DPRINTF("flip stall done\n"); break; @@ -2602,19 +2599,15 @@ 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(_lock); + d->pgraph.interrupt_cond.wait(d->pgraph.lock); } } } static void pgraph_wait_fifo_access(NV2AState *d) { - std::unique_lock _lock(d->pgraph.lock); // TODO : Is this correct?? - while (!d->pgraph.fifo_access) { - d->pgraph.fifo_access_cond.wait(_lock); + d->pgraph.fifo_access_cond.wait(d->pgraph.lock); } } diff --git a/src/devices/video/nv2a.cpp b/src/devices/video/nv2a.cpp index 3ee75cf9e..1a2cef98c 100644 --- a/src/devices/video/nv2a.cpp +++ b/src/devices/video/nv2a.cpp @@ -615,6 +615,12 @@ void CxbxReserveNV2AMemory(NV2AState *d) /* NV2ADevice */ +NV2ADevice::NV2ADevice() +{ + m_nv2a_state.pfifo.cache1.cache_lock = std::unique_lock(m_nv2a_state.pfifo.cache1._cache_lock, std::defer_lock); + m_nv2a_state.pgraph.lock = std::unique_lock(m_nv2a_state.pgraph._lock, std::defer_lock); +} + // PCI Device functions void NV2ADevice::Init() diff --git a/src/devices/video/nv2a.h b/src/devices/video/nv2a.h index a7e03eb7f..d2bed2545 100644 --- a/src/devices/video/nv2a.h +++ b/src/devices/video/nv2a.h @@ -293,7 +293,8 @@ typedef struct GraphicsContext { typedef struct PGRAPHState { - std::mutex lock; // std::unique_lock(lock, std::defer_lock); + std::mutex _lock; + std::unique_lock lock; uint32_t pending_interrupts; uint32_t enabled_interrupts; @@ -436,7 +437,8 @@ typedef struct Cache1State { enum FIFOEngine last_engine; /* The actual command queue */ - std::mutex cache_lock; // std::unique_lock(cache_lock, std::defer_lock); + std::mutex _cache_lock; + std::unique_lock cache_lock; std::condition_variable cache_cond; std::queue cache; std::queue working_cache; @@ -611,6 +613,9 @@ void InitOpenGLContext(); class NV2ADevice : public PCIDevice { public: + // constructor + NV2ADevice(); + // PCI Device functions void Init(); void Reset();