fix mutex aquire order

master
vhaudiquet 1 year ago
parent f52699a8bf
commit 89da4e56bb
  1. 6
      src/cpu/rv32cpu.c

@ -650,11 +650,11 @@ void cpu_loop(rv32_cpu_t* cpu)
{ {
// Aquire CPU and memory mutex // Aquire CPU and memory mutex
pthread_mutex_lock(&cpu0_mutex); pthread_mutex_lock(&cpu0_mutex);
pthread_mutex_lock(&memory_mutex);
while(!cpu->sim_ticks_left) while(!cpu->sim_ticks_left)
pthread_cond_wait(&cpu0->sim_condition, &cpu0_mutex); pthread_cond_wait(&cpu0->sim_condition, &cpu0_mutex);
pthread_mutex_lock(&memory_mutex);
// Fetch // Fetch
raw_instruction_t raw_instruction; raw_instruction_t raw_instruction;
if(cpu->pc > memory_size - 4) if(cpu->pc > memory_size - 4)
@ -685,8 +685,8 @@ void cpu_loop(rv32_cpu_t* cpu)
cpu->sim_ticks_left--; cpu->sim_ticks_left--;
// Let go of cpu and memory mutex // Let go of cpu and memory mutex
pthread_mutex_unlock(&cpu0_mutex);
pthread_mutex_unlock(&memory_mutex); pthread_mutex_unlock(&memory_mutex);
pthread_mutex_unlock(&cpu0_mutex);
} }
} }

Loading…
Cancel
Save