task_register() conversion: audiod status task
authorAndre Noll <maan@systemlinux.org>
Tue, 31 Dec 2013 00:06:28 +0000 (00:06 +0000)
committerAndre Noll <maan@systemlinux.org>
Sun, 25 May 2014 13:39:00 +0000 (15:39 +0200)
audiod.c

index aa75741..461efaf 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -100,7 +100,7 @@ struct sched sched = {.max_fileno = 0};
  */
 struct status_task {
        /** The associated task structure of audiod. */
-       struct task task;
+       struct task *task;
        /** Client data associated with the stat task. */
        struct client_task *ct;
        /** Do not restart client command until this time. */
@@ -1198,7 +1198,7 @@ static void start_stop_decoders(void)
 
 static void status_pre_select(struct sched *s, struct task *t)
 {
-       struct status_task *st = container_of(t, struct status_task, task);
+       struct status_task *st = task_context(t);
        int i, ret, cafn = stat_task->current_audio_format_num;
 
        if (must_start_decoder())
@@ -1230,7 +1230,7 @@ min_delay:
 /* restart the client task if necessary */
 static int status_post_select(struct sched *s, struct task *t)
 {
-       struct status_task *st = container_of(t, struct status_task, task);
+       struct status_task *st = task_context(t);
 
        if (audiod_status == AUDIOD_OFF) {
                if (!st->ct)
@@ -1308,14 +1308,18 @@ out:
 static void init_status_task(struct status_task *st)
 {
        memset(st, 0, sizeof(struct status_task));
-       st->task.pre_select = status_pre_select;
-       st->task.post_select = status_post_select;
        st->sa_time_diff_sign = 1;
        st->clock_diff_count = conf.clock_diff_count_arg;
        st->current_audio_format_num = -1;
-       sprintf(st->task.status, "stat");
        st->btrn = btr_new_node(&(struct btr_node_description)
                EMBRACE(.name = "stat"));
+
+       stat_task->task = task_register(&(struct task_info) {
+               .name = "stat",
+               .pre_select = status_pre_select,
+               .post_select = status_post_select,
+               .context = stat_task,
+       }, &sched);
 }
 
 static void set_initial_status(void)
@@ -1433,7 +1437,6 @@ int main(int argc, char *argv[])
                .context = sig_task,
        }, &sched);
 
-       register_task(&sched, &stat_task->task);
        sched.default_timeout.tv_sec = 2;
        sched.default_timeout.tv_usec = 999 * 1000;
        ret = schedule(&sched);