]> git.tue.mpg.de Git - paraslash.git/commitdiff
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 3759306ec2215f0732bba5fcc76d18d011db41e1..155d02697cb90400107b59922e1cb99f917f978e 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 63d18afab387288831e45e50cd33ecfd42801805..bab5a80ef9308b7204bf6294dea8963f89880113 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 c5a88a9d5820a0d61c0b8364af0aced414a32fdb..1d8cc4c1a76c7622a59abd1de2b4b7c678bc4925 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 7d63469f8ef68d9ed9e99531c6b31ab7307612dd..97bdafd3d617602f7afd745ba0371477ff046281 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 d547acf7422e2437a2af0d74f706d477bea8c309..33cf8c3cf1d56b3b0e851e1157279e5351529d3f 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 889854c22a711a167e5bbfa61ac35241c60f8a95..a9c421a6a0a27397afbd69b302c77199c52e768b 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 045f26038b46512f4eebfdf5bf80659c79f4fd87..2c6feeda593771baf5e4213859a1cabae29917ce 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 0dc233fca0a1b77859462959edfbb33c7d826902..15bbb4a6399dd0739b41d3ee6c7b73e4c6af5fbc 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 0cfcafdade93f8334a9b8236656ba967def148ec..32c437f8d175826951f2861f82277cf68ca52461 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 e191c49ad2ec2240534b6c420ac6d146ac3efc49..4c5ef4bca5f6e7975348c74ddd83a4bcb6ebdb33 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);
 }
 
 /**