fix mutex aquire order

This commit is contained in:
vhaudiquet 2023-10-08 18:28:08 +02:00
parent f52699a8bf
commit 89da4e56bb

View File

@ -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);
}
}