[qwaq] Use an actual condition variable for control

I think I wasn't sure at the time whether the simple variable was
required for pthread_cond_wait (and friends) to work properly, but it
is: the time between the target posting the debug event and the target
waiting on the condition variable turns out to sometimes be enough for
the debugger to handle the event and signal the target to continue,
resulting in the target waiting on a signal that will never come because
another debug event will not be sent by the target until AFTER it has
exited from the debug handler.
This commit is contained in:
Bill Currie 2020-07-03 21:46:09 +09:00
parent 1910941426
commit 225ee0ed3c

View file

@ -59,6 +59,7 @@ typedef struct qwaq_target_s {
prdebug_t event;
void *param;
rwcond_t run_cond;
int run_command;
} qwaq_target_t;
typedef struct qwaq_debug_s {
@ -130,7 +131,10 @@ qwaq_debug_handler (prdebug_t debug_event, void *param, void *data)
Sys_Error ("event queue broke");
}
pthread_mutex_lock (&target->run_cond.mut);
pthread_cond_wait (&target->run_cond.rcond, &target->run_cond.mut);
while (!target->run_command) {
pthread_cond_wait (&target->run_cond.rcond, &target->run_cond.mut);
}
target->run_command = 0;
pthread_mutex_unlock (&target->run_cond.mut);
if (debug_event == prd_runerror || debug_event == prd_error) {
pthread_exit (param);
@ -185,6 +189,7 @@ qwaq_target_load (progs_t *pr)
target->debugger = qwaq_debug_data;
target->handle = target_index (qwaq_debug_data, target);
qwaq_init_cond (&target->run_cond);
target->run_command = 0;
pr->debug_handler = qwaq_debug_handler;
pr->debug_data = target;
@ -280,6 +285,7 @@ qdb_continue (progs_t *pr)
qwaq_target_t *target = get_target (debug, __FUNCTION__, handle);
pthread_mutex_lock (&target->run_cond.mut);
target->run_command = 1;
pthread_cond_signal (&target->run_cond.rcond);
pthread_mutex_unlock (&target->run_cond.mut);
}