Refactor CPU mutex code
This commit is contained in:
+13
-13
@@ -203,7 +203,7 @@ void gdbstub_thread_gdb()
|
||||
char resp[32 * 8 + 8 + 1] = {0};
|
||||
|
||||
// Obtain CPU0 mutex
|
||||
pthread_mutex_lock(&cpu0_mutex);
|
||||
pthread_mutex_lock(&cpu0->mutex);
|
||||
|
||||
// All general purpose registers in host byte order as chars
|
||||
for(size_t i = 0; i < 32; i++)
|
||||
@@ -217,7 +217,7 @@ void gdbstub_thread_gdb()
|
||||
snprintf(resp + 32 * 8, 9, "%08x", pc);
|
||||
|
||||
// Let go of CPU0 mutex
|
||||
pthread_mutex_unlock(&cpu0_mutex);
|
||||
pthread_mutex_unlock(&cpu0->mutex);
|
||||
|
||||
// Final packet size, send packet
|
||||
size_t size = 32 * 8 + 8;
|
||||
@@ -228,7 +228,7 @@ void gdbstub_thread_gdb()
|
||||
// G : write all registers -> read and set all registers
|
||||
|
||||
// Obtain CPU0 mutex
|
||||
pthread_mutex_lock(&cpu0_mutex);
|
||||
pthread_mutex_lock(&cpu0->mutex);
|
||||
|
||||
// All general purpose registers in host byte order as chars
|
||||
for(size_t i = 1; i < 32; i++)
|
||||
@@ -247,7 +247,7 @@ void gdbstub_thread_gdb()
|
||||
cpu0->pc = pc;
|
||||
|
||||
// Let go of CPU0 Mutex
|
||||
pthread_mutex_unlock(&cpu0_mutex);
|
||||
pthread_mutex_unlock(&cpu0->mutex);
|
||||
|
||||
gdbstub_send_packet("OK", 2);
|
||||
}
|
||||
@@ -296,9 +296,9 @@ void gdbstub_thread_gdb()
|
||||
send(gdb_socket, "+", 1, 0);
|
||||
|
||||
// Continue simulation, for 1 tick
|
||||
pthread_mutex_lock(&cpu0_mutex);
|
||||
pthread_mutex_lock(&cpu0->mutex);
|
||||
cpu0->sim_ticks_left = 1;
|
||||
pthread_mutex_unlock(&cpu0_mutex);
|
||||
pthread_mutex_unlock(&cpu0->mutex);
|
||||
pthread_cond_signal(&cpu0->sim_condition);
|
||||
}
|
||||
else if(packet[0] == 'c')
|
||||
@@ -309,9 +309,9 @@ void gdbstub_thread_gdb()
|
||||
send(gdb_socket, "+", 1, 0);
|
||||
|
||||
// Continue simulation
|
||||
pthread_mutex_lock(&cpu0_mutex);
|
||||
pthread_mutex_lock(&cpu0->mutex);
|
||||
cpu0->sim_ticks_left = -1;
|
||||
pthread_mutex_unlock(&cpu0_mutex);
|
||||
pthread_mutex_unlock(&cpu0->mutex);
|
||||
pthread_cond_signal(&cpu0->sim_condition);
|
||||
}
|
||||
else gdbstub_send_unsupported();
|
||||
@@ -322,8 +322,8 @@ void gdbstub_cpu_watcher_thread()
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
pthread_mutex_lock(&cpu0_mutex);
|
||||
pthread_cond_wait(&cpu0->sim_condition, &cpu0_mutex);
|
||||
pthread_mutex_lock(&cpu0->mutex);
|
||||
pthread_cond_wait(&cpu0->sim_condition, &cpu0->mutex);
|
||||
if(!cpu0->sim_ticks_left && cpu0->sim_ticks_done > 0)
|
||||
{
|
||||
// Send back halt reason
|
||||
@@ -331,7 +331,7 @@ void gdbstub_cpu_watcher_thread()
|
||||
char* resp = "S05";
|
||||
gdbstub_send_packet(resp, 3);
|
||||
}
|
||||
pthread_mutex_unlock(&cpu0_mutex);
|
||||
pthread_mutex_unlock(&cpu0->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ void gdbstub_cpu_watcher_thread()
|
||||
static void gdbstub_handle_ctrlc()
|
||||
{
|
||||
// Halt the simulation
|
||||
pthread_mutex_lock(&cpu0_mutex);
|
||||
pthread_mutex_lock(&cpu0->mutex);
|
||||
cpu0->sim_ticks_left = 0;
|
||||
pthread_mutex_unlock(&cpu0_mutex);
|
||||
pthread_mutex_unlock(&cpu0->mutex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user