From 89da4e56bbf6a5a649f97c5daf4dbe7a3ff63537 Mon Sep 17 00:00:00 2001 From: vhaudiquet Date: Sun, 8 Oct 2023 18:28:08 +0200 Subject: [PATCH] fix mutex aquire order --- src/cpu/rv32cpu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cpu/rv32cpu.c b/src/cpu/rv32cpu.c index 8cc68c1..a85dae9 100644 --- a/src/cpu/rv32cpu.c +++ b/src/cpu/rv32cpu.c @@ -650,11 +650,11 @@ void cpu_loop(rv32_cpu_t* cpu) { // Aquire CPU and memory mutex pthread_mutex_lock(&cpu0_mutex); - pthread_mutex_lock(&memory_mutex); - while(!cpu->sim_ticks_left) pthread_cond_wait(&cpu0->sim_condition, &cpu0_mutex); + pthread_mutex_lock(&memory_mutex); + // Fetch raw_instruction_t raw_instruction; if(cpu->pc > memory_size - 4) @@ -685,8 +685,8 @@ void cpu_loop(rv32_cpu_t* cpu) cpu->sim_ticks_left--; // Let go of cpu and memory mutex - pthread_mutex_unlock(&cpu0_mutex); pthread_mutex_unlock(&memory_mutex); + pthread_mutex_unlock(&cpu0_mutex); } }