fix mutex aquire order
This commit is contained in:
		| @@ -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); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user