From c5056b00502d27e602cfcd716f92e5f85f97b470 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 30 Dec 2013 22:59:47 +0000 Subject: [PATCH] task_register() conversion: writers --- alsa_write.c | 4 ++-- ao_write.c | 4 ++-- audiod.c | 5 +++-- file_write.c | 4 ++-- oss_write.c | 4 ++-- osx_write.c | 4 ++-- play.c | 10 +++++++--- write.c | 2 +- write.h | 2 +- write_common.c | 14 +++++++------- 10 files changed, 29 insertions(+), 24 deletions(-) diff --git a/alsa_write.c b/alsa_write.c index 3759306e..155d0269 100644 --- a/alsa_write.c +++ b/alsa_write.c @@ -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; diff --git a/ao_write.c b/ao_write.c index 63d18afa..bab5a80e 100644 --- a/ao_write.c +++ b/ao_write.c @@ -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; diff --git a/audiod.c b/audiod.c index c5a88a9d..1d8cc4c1 100644 --- 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; diff --git a/file_write.c b/file_write.c index 7d63469f..97bdafd3 100644 --- a/file_write.c +++ b/file_write.c @@ -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; diff --git a/oss_write.c b/oss_write.c index d547acf7..33cf8c3c 100644 --- a/oss_write.c +++ b/oss_write.c @@ -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; diff --git a/osx_write.c b/osx_write.c index 889854c2..a9c421a6 100644 --- a/osx_write.c +++ b/osx_write.c @@ -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 045f2603..2c6feeda 100644 --- 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 0dc233fc..15bbb4a6 100644 --- 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 0cfcafda..32c437f8 100644 --- 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; }; diff --git a/write_common.c b/write_common.c index e191c49a..4c5ef4bc 100644 --- a/write_common.c +++ b/write_common.c @@ -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); } /** -- 2.39.5