task_register() conversion: writers
authorAndre Noll <maan@systemlinux.org>
Mon, 30 Dec 2013 22:59:47 +0000 (22:59 +0000)
committerAndre Noll <maan@systemlinux.org>
Sun, 25 May 2014 13:39:00 +0000 (15:39 +0200)
alsa_write.c
ao_write.c
audiod.c
file_write.c
oss_write.c
osx_write.c
play.c
write.c
write.h
write_common.c

index 3759306..155d026 100644 (file)
@@ -202,7 +202,7 @@ fail:
 static void alsa_write_pre_select(struct sched *s, struct task *t)
 {
        struct pollfd pfd;
-       struct writer_node *wn = container_of(t, struct writer_node, task);
+       struct writer_node *wn = task_context(t);
        struct private_alsa_write_data *pad = wn->private_data;
        int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
 
@@ -251,7 +251,7 @@ static void alsa_close(struct writer_node *wn)
 static int alsa_write_post_select(__a_unused struct sched *s,
                struct task *t)
 {
-       struct writer_node *wn = container_of(t, struct writer_node, task);
+       struct writer_node *wn = task_context(t);
        struct private_alsa_write_data *pad = wn->private_data;
        struct btr_node *btrn = wn->btrn;
        char *data;
index 63d18af..bab5a80 100644 (file)
@@ -48,7 +48,7 @@ static void aow_close(struct writer_node *wn)
 
 static void aow_pre_select(struct sched *s, struct task *t)
 {
-       struct writer_node *wn = container_of(t, struct writer_node, task);
+       struct writer_node *wn = task_context(t);
        struct private_aow_data *pawd = wn->private_data;
        int ret;
 
@@ -311,7 +311,7 @@ fail:
 static int aow_post_select(__a_unused struct sched *s,
                struct task *t)
 {
-       struct writer_node *wn = container_of(t, struct writer_node, task);
+       struct writer_node *wn = task_context(t);
        struct private_aow_data *pawd = wn->private_data;
        int ret;
 
index c5a88a9..1d8cc4c 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -408,6 +408,7 @@ static void writer_cleanup(struct writer_node *wn)
        PARA_INFO_LOG("closing %s\n", writer_names[wn->writer_num]);
        w->close(wn);
        btr_remove_node(&wn->btrn);
+       task_reap(&wn->task);
 }
 
 static void close_writers(struct slot_info *s)
@@ -1118,10 +1119,10 @@ static bool must_close_slot(int slot_num)
                        return false;
        if (a->num_writers > 0) {
                for (i = 0; i < a->num_writers; i++)
-                       if (s->wns && s->wns[i].task.error >= 0)
+                       if (s->wns && s->wns[i].task->error >= 0)
                                return false;
        } else {
-               if (s->wns && s->wns[0].task.error >= 0)
+               if (s->wns && s->wns[0].task->error >= 0)
                        return false;
        }
        return true;
index 7d63469..97bdafd 100644 (file)
@@ -76,7 +76,7 @@ out:
 
 static void file_write_pre_select(struct sched *s, struct task *t)
 {
-       struct writer_node *wn = container_of(t, struct writer_node, task);
+       struct writer_node *wn = task_context(t);
        struct private_file_write_data *pfwd = wn->private_data;
        int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
 
@@ -100,7 +100,7 @@ static void file_write_close(struct writer_node *wn)
 static int file_write_post_select(__a_unused struct sched *s,
                struct task *t)
 {
-       struct writer_node *wn = container_of(t, struct writer_node, task);
+       struct writer_node *wn = task_context(t);
        struct private_file_write_data *pfwd = wn->private_data;
        struct btr_node *btrn = wn->btrn;
        int ret;
index d547acf..33cf8c3 100644 (file)
@@ -46,7 +46,7 @@ static int get_oss_format(enum sample_format sf)
 
 static void oss_pre_select(struct sched *s, struct task *t)
 {
-       struct writer_node *wn = container_of(t, struct writer_node, task);
+       struct writer_node *wn = task_context(t);
        struct private_oss_write_data *powd = wn->private_data;
        int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
 
@@ -160,7 +160,7 @@ err_free:
 static int oss_post_select(__a_unused struct sched *s,
                struct task *t)
 {
-       struct writer_node *wn = container_of(t, struct writer_node, task);
+       struct writer_node *wn = task_context(t);
        struct private_oss_write_data *powd = wn->private_data;
        struct btr_node *btrn = wn->btrn;
        size_t frames, bytes;
index 889854c..a9c421a 100644 (file)
@@ -276,7 +276,7 @@ static inline bool need_drain_delay(struct private_osx_write_data *powd)
 
 static void osx_write_pre_select(struct sched *s, struct task *t)
 {
-       struct writer_node *wn = container_of(t, struct writer_node, task);
+       struct writer_node *wn = task_context(t);
        struct private_osx_write_data *powd = wn->private_data;
        int ret;
        bool drain_delay_nec = false;
@@ -303,7 +303,7 @@ static void osx_write_pre_select(struct sched *s, struct task *t)
 
 static int osx_write_post_select(__a_unused struct sched *s, struct task *t)
 {
-       struct writer_node *wn = container_of(t, struct writer_node, task);
+       struct writer_node *wn = task_context(t);
        struct private_osx_write_data *powd = wn->private_data;
        struct btr_node *btrn = wn->btrn;
        int ret;
diff --git a/play.c b/play.c
index 045f260..2c6feed 100644 (file)
--- a/play.c
+++ b/play.c
@@ -243,8 +243,11 @@ static void wipe_receiver_node(struct play_task *pt)
 /* returns: 0 not eof, 1: eof, < 0: fatal error.  */
 static int get_playback_error(struct play_task *pt)
 {
-       int err = pt->wn.task.error;
+       int err;
 
+       if (!pt->wn.task)
+               return 0;
+       err = pt->wn.task->error;
        if (err >= 0)
                return 0;
        if (pt->fn.task->error >= 0)
@@ -267,6 +270,7 @@ static int eof_cleanup(struct play_task *pt)
        if (ret == 0)
                return ret;
        PARA_NOTICE_LOG("cleaning up wn/fn nodes\n");
+       task_reap(&pt->wn.task);
        w->close(&pt->wn);
        btr_remove_node(&pt->wn.btrn);
        w->free_config(pt->wn.conf);
@@ -397,7 +401,6 @@ static int load_file(struct play_task *pt)
 
        /* setup default writer */
        pt->wn.conf = check_writer_arg_or_die(NULL, &pt->wn.writer_num);
-       pt->wn.task.error = 0;
 
        /* success, register tasks */
        pt->rn.task = task_register(
@@ -460,7 +463,8 @@ again:
 
 static void kill_stream(struct play_task *pt)
 {
-       task_notify(&pt->wn.task, E_EOF);
+       if (pt->wn.task)
+               task_notify(pt->wn.task, E_EOF);
 }
 
 #ifdef HAVE_READLINE
diff --git a/write.c b/write.c
index 0dc233f..15bbb4a 100644 (file)
--- a/write.c
+++ b/write.c
@@ -125,7 +125,7 @@ static int setup_and_schedule(void)
        if (ret >= 0) {
                int j;
                for (j = 0; j < i; j++) {
-                       struct task *t = &wns[j].task;
+                       struct task *t = wns[j].task;
                        assert(t->error < 0);
                        if (t->error != -E_WRITE_COMMON_EOF
                                        && t->error != -E_BTR_EOF) {
diff --git a/write.h b/write.h
index 0cfcafd..32c437f 100644 (file)
--- a/write.h
+++ b/write.h
@@ -22,7 +22,7 @@ struct writer_node {
        /** The buffer tree node associated with this writer node. */
        struct btr_node *btrn;
        /** The task of this writer node. */
-       struct task task;
+       struct task *task;
        /** The minimal input queue size (size of one audio sample). */
        size_t min_iqs;
 };
index e191c49..4c5ef4b 100644 (file)
@@ -107,16 +107,16 @@ void register_writer_node(struct writer_node *wn, struct btr_node *parent,
                struct sched *s)
 {
        struct writer *w = writers + wn->writer_num;
-       char *name = make_message("%s writer", writer_names[wn->writer_num]);
 
        wn->btrn = btr_new_node(&(struct btr_node_description)
-               EMBRACE(.name = name, .parent = parent,
+               EMBRACE(.name = writer_names[wn->writer_num], .parent = parent,
                .handler = w->execute, .context = wn));
-       strcpy(wn->task.status, name);
-       free(name);
-       wn->task.pre_select = w->pre_select;
-       wn->task.post_select = w->post_select;
-       register_task(s, &wn->task);
+       wn->task = task_register(&(struct task_info) {
+               .name = writer_names[wn->writer_num],
+               .pre_select = w->pre_select,
+               .post_select = w->post_select,
+               .context = wn,
+       }, s);
 }
 
 /**