Kill TASK_UNREGISTERED error code.
authorAndre Noll <maan@systemlinux.org>
Sun, 20 Feb 2011 17:41:02 +0000 (18:41 +0100)
committerAndre Noll <maan@systemlinux.org>
Sat, 5 Mar 2011 12:34:54 +0000 (13:34 +0100)
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
error.h
grab_client.c
sched.c

index 8b17d95..486a33f 100644 (file)
--- 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 5a2e39b..ed905a1 100644 (file)
--- 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 \
index 8e67150..c410b3b 100644 (file)
@@ -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 b0e9ce1..7d91797 100644 (file)
--- 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;
 }