NV2A : Construct unique_lock mutex wrappers once (and avoid any other use of the mutex'es)

This commit is contained in:
patrickvl 2018-02-04 16:21:11 +01:00 committed by PatrickvL
parent e3151892e6
commit b146b0569f
5 changed files with 19 additions and 17 deletions

View File

@ -540,7 +540,7 @@ void TriggerPendingConnectedInterrupts()
{ {
for (int i = 0; i < MAX_BUS_INTERRUPT_LEVEL; i++) { for (int i = 0; i < MAX_BUS_INTERRUPT_LEVEL; i++) {
// If the interrupt is pending and connected, process it // 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]); HalSystemInterrupts[i].Trigger(EmuInterruptList[i]);
} }
} }

View File

@ -362,10 +362,8 @@ int pfifo_puller_thread(NV2AState *d)
while (true) { while (true) {
state->cache_lock.lock(); state->cache_lock.lock();
std::unique_lock<std::mutex> _cache_lock(state->cache_lock); // TODO : Is this correct??
while (state->cache.empty() || !state->pull_enabled) { 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 // Copy cache to working_cache

View File

@ -713,10 +713,8 @@ static void pgraph_method(NV2AState *d,
pg->lock.lock(); pg->lock.lock();
qemu_mutex_unlock_iothread(); qemu_mutex_unlock_iothread();
std::unique_lock<std::mutex> _lock(pg->lock); // TODO : Is this correct??
while (pg->pending_interrupts & NV_PGRAPH_INTR_ERROR) { while (pg->pending_interrupts & NV_PGRAPH_INTR_ERROR) {
pg->interrupt_cond.wait(_lock); pg->interrupt_cond.wait(pg->lock);
} }
} }
break; break;
@ -786,9 +784,8 @@ static void pgraph_method(NV2AState *d,
!= GET_MASK(s, NV_PGRAPH_SURFACE_WRITE_3D)) { != GET_MASK(s, NV_PGRAPH_SURFACE_WRITE_3D)) {
break; break;
} }
std::unique_lock<std::mutex> _lock(pg->lock); // TODO : Is this correct??
pg->flip_3d.wait(_lock); pg->flip_3d.wait(pg->lock);
} }
NV2A_DPRINTF("flip stall done\n"); NV2A_DPRINTF("flip stall done\n");
break; break;
@ -2602,19 +2599,15 @@ static void pgraph_context_switch(NV2AState *d, unsigned int channel_id)
d->pgraph.lock.lock(); d->pgraph.lock.lock();
qemu_mutex_unlock_iothread(); qemu_mutex_unlock_iothread();
std::unique_lock<std::mutex> _lock(d->pgraph.lock); // TODO : Is this correct??
while (d->pgraph.pending_interrupts & NV_PGRAPH_INTR_CONTEXT_SWITCH) { 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) { static void pgraph_wait_fifo_access(NV2AState *d) {
std::unique_lock<std::mutex> _lock(d->pgraph.lock); // TODO : Is this correct??
while (!d->pgraph.fifo_access) { while (!d->pgraph.fifo_access) {
d->pgraph.fifo_access_cond.wait(_lock); d->pgraph.fifo_access_cond.wait(d->pgraph.lock);
} }
} }

View File

@ -615,6 +615,12 @@ void CxbxReserveNV2AMemory(NV2AState *d)
/* NV2ADevice */ /* NV2ADevice */
NV2ADevice::NV2ADevice()
{
m_nv2a_state.pfifo.cache1.cache_lock = std::unique_lock<std::mutex>(m_nv2a_state.pfifo.cache1._cache_lock, std::defer_lock);
m_nv2a_state.pgraph.lock = std::unique_lock<std::mutex>(m_nv2a_state.pgraph._lock, std::defer_lock);
}
// PCI Device functions // PCI Device functions
void NV2ADevice::Init() void NV2ADevice::Init()

View File

@ -293,7 +293,8 @@ typedef struct GraphicsContext {
typedef struct PGRAPHState { typedef struct PGRAPHState {
std::mutex lock; // std::unique_lock<std::mutex>(lock, std::defer_lock); std::mutex _lock;
std::unique_lock<std::mutex> lock;
uint32_t pending_interrupts; uint32_t pending_interrupts;
uint32_t enabled_interrupts; uint32_t enabled_interrupts;
@ -436,7 +437,8 @@ typedef struct Cache1State {
enum FIFOEngine last_engine; enum FIFOEngine last_engine;
/* The actual command queue */ /* The actual command queue */
std::mutex cache_lock; // std::unique_lock<std::mutex>(cache_lock, std::defer_lock); std::mutex _cache_lock;
std::unique_lock<std::mutex> cache_lock;
std::condition_variable cache_cond; std::condition_variable cache_cond;
std::queue<CacheEntry*> cache; std::queue<CacheEntry*> cache;
std::queue<CacheEntry*> working_cache; std::queue<CacheEntry*> working_cache;
@ -611,6 +613,9 @@ void InitOpenGLContext();
class NV2ADevice : public PCIDevice { class NV2ADevice : public PCIDevice {
public: public:
// constructor
NV2ADevice();
// PCI Device functions // PCI Device functions
void Init(); void Init();
void Reset(); void Reset();