From 0a5226b8f6b9131024893f35de615d0b829afe27 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 20 Feb 2011 18:41:02 +0100 Subject: [PATCH] Kill TASK_UNREGISTERED error code. Currently the scheduler sets t->error to -E_TASK_UNREGISTERED when it has unregistered a task. This deprives the applications from doing post-mortem error checking. The condition (task.error != -E_TASK_UNREGISTERED) is now equivalent to task.error >= 0, so use this test everywhere. --- audiod.c | 12 ++++++------ error.h | 2 +- grab_client.c | 2 +- sched.c | 13 ++++++++----- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/audiod.c b/audiod.c index 8b17d95f..486a33ff 100644 --- a/audiod.c +++ b/audiod.c @@ -1097,17 +1097,17 @@ static void try_to_close_slot(int slot_num) if (s->format < 0) return; - if (s->receiver_node && s->receiver_node->task.error != -E_TASK_UNREGISTERED) + if (s->receiver_node && s->receiver_node->task.error >= 0) return; for (i = 0; i < a->num_filters; i++) - if (s->fns && s->fns[i].task.error != -E_TASK_UNREGISTERED) + if (s->fns && s->fns[i].task.error >= 0) return; if (a->num_writers > 0) { for (i = 0; i < a->num_writers; i++) - if (s->wns && s->wns[i].task.error != -E_TASK_UNREGISTERED) + if (s->wns && s->wns[i].task.error >= 0) return; } else { - if (s->wns && s->wns[0].task.error != -E_TASK_UNREGISTERED) + if (s->wns && s->wns[0].task.error >= 0) return; } PARA_INFO_LOG("closing slot %d\n", slot_num); @@ -1188,7 +1188,7 @@ static void status_post_select(__a_unused struct sched *s, struct task *t) kill_btrn(st->ct->btrn, &st->ct->task, -E_AUDIOD_OFF); goto out; } - if (st->ct->task.error != -E_TASK_UNREGISTERED) + if (st->ct->task.error >= 0) goto out; close_stat_pipe(); st->clock_diff_count = conf.clock_diff_count_arg; @@ -1199,7 +1199,7 @@ static void status_post_select(__a_unused struct sched *s, struct task *t) size_t sz; int ret; if (st->ct->task.error < 0) { - if (st->ct->task.error != -E_TASK_UNREGISTERED) + if (st->ct->task.error >= 0) goto out; close_stat_pipe(); goto out; diff --git a/error.h b/error.h index 5a2e39b4..ed905a10 100644 --- a/error.h +++ b/error.h @@ -231,9 +231,9 @@ extern const char **para_errlist[]; #define SCHED_ERRORS \ PARA_ERROR(TASK_KILLED, "task killed"), \ - PARA_ERROR(TASK_UNREGISTERED, "task has been unscheduled"), \ PARA_ERROR(NO_SUCH_TASK, "task not found"), \ PARA_ERROR(NOT_INITIALIZED, "scheduler not yet initialized"), \ + PARA_ERROR(SCHED_SHUTDOWN, "scheduler was shut down"), \ #define NET_ERRORS \ diff --git a/grab_client.c b/grab_client.c index 8e671503..c410b3b9 100644 --- a/grab_client.c +++ b/grab_client.c @@ -156,7 +156,7 @@ void activate_grab_clients(void) struct grab_client *gc, *tmp; list_for_each_entry_safe(gc, tmp, &inactive_grab_client_list, node) { - if (gc->task.error == -E_TASK_UNREGISTERED) { + if (gc->task.error < 0) { list_del(&gc->node); free(gc); continue; diff --git a/sched.c b/sched.c index b0e9ce12..7d91797a 100644 --- a/sched.c +++ b/sched.c @@ -38,16 +38,15 @@ static void unregister_task(struct task *t) { if (!initialized) return; + assert(t->error < 0); PARA_INFO_LOG("unregistering %s (%s)\n", t->status, - t->error <0? para_strerror(-t->error) : "shutdown"); + para_strerror(-t->error)); if (t->pre_select) list_del(&t->pre_select_node); if (t->post_select) list_del(&t->post_select_node); - t->error = -E_TASK_UNREGISTERED; } - static void sched_preselect(struct sched *s) { struct task *t, *tmp; @@ -207,10 +206,14 @@ void sched_shutdown(void) if (!initialized) return; - list_for_each_entry_safe(t, tmp, &pre_select_list, pre_select_node) + list_for_each_entry_safe(t, tmp, &pre_select_list, pre_select_node) { + t->error = -E_SCHED_SHUTDOWN; unregister_task(t); - list_for_each_entry_safe(t, tmp, &post_select_list, post_select_node) + } + list_for_each_entry_safe(t, tmp, &post_select_list, post_select_node) { + t->error = -E_SCHED_SHUTDOWN; unregister_task(t); + } initialized = 0; } -- 2.39.5