Break all tasks on exit (#11026)

* Break all tasks on exit

* null check in r_cons_context_break()
This commit is contained in:
Florian Märkl 2018-08-11 16:23:27 +02:00 committed by GitHub
parent e08900b9bd
commit cc3c87532a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 1 deletions

View File

@ -670,6 +670,9 @@ R_API bool r_cons_context_is_main() {
}
R_API void r_cons_context_break(RConsContext *context) {
if (!context) {
return;
}
context->breaked = true;
if (context->event_interrupt) {
context->event_interrupt (context->event_interrupt_data);

View File

@ -2241,6 +2241,7 @@ R_API RCore *r_core_fini(RCore *c) {
if (!c) {
return NULL;
}
r_core_task_break_all (c);
r_core_task_join (c, NULL, NULL);
r_core_wait (c);
/* TODO: it leaks as shit */

View File

@ -298,6 +298,11 @@ static int task_run(RCoreTask *task) {
task_wakeup (task);
if (task->cons_context && task->cons_context->breaked) {
// breaked in R_CORE_TASK_STATE_BEFORE_START
goto stillbirth;
}
char *res_str;
int res;
if (task == task->core->main_task) {
@ -317,6 +322,7 @@ static int task_run(RCoreTask *task) {
eprintf ("\nTask %d finished\n", task->id);
}
stillbirth:
task_end (task);
if (task->cb) {
@ -440,7 +446,7 @@ R_API void r_core_task_break(RCore *core, int id) {
tasks_lock_enter (core, &old_sigset);
RCoreTask *task = r_core_task_get (core, id);
if (!task || task->state == R_CORE_TASK_STATE_DONE) {
r_th_lock_leave (core->tasks_lock);
tasks_lock_leave (core, &old_sigset);
return;
}
if (task->cons_context) {
@ -449,6 +455,19 @@ R_API void r_core_task_break(RCore *core, int id) {
tasks_lock_leave (core, &old_sigset);
}
R_API void r_core_task_break_all(RCore *core) {
TASK_SIGSET_T old_sigset;
tasks_lock_enter (core, &old_sigset);
RCoreTask *task;
RListIter *iter;
r_list_foreach (core->tasks, iter, task) {
if (task->state != R_CORE_TASK_STATE_DONE) {
r_cons_context_break (task->cons_context);
}
}
tasks_lock_leave (core, &old_sigset);
}
R_API int r_core_task_del (RCore *core, int id) {
RCoreTask *task;
RListIter *iter;

View File

@ -758,6 +758,7 @@ R_API void r_core_task_continue(RCoreTask *t);
R_API void r_core_task_sleep_begin(RCoreTask *task);
R_API void r_core_task_sleep_end(RCoreTask *task);
R_API void r_core_task_break(RCore *core, int id);
R_API void r_core_task_break_all(RCore *core);
R_API int r_core_task_del(RCore *core, int id);
R_API void r_core_task_del_all_done(RCore *core);
R_API RCoreTask *r_core_task_self(RCore *core);