From: Andre Date: Tue, 23 May 2006 21:45:42 +0000 (+0200) Subject: simplify sched: nuke PRE_EOF_IS_ERROR X-Git-Tag: v0.2.14~101^2~28 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=148c7c722fd5795228f586b6ef8d953662b68224;p=paraslash.git simplify sched: nuke PRE_EOF_IS_ERROR Much too simple to get it wrong. Instead, treat zero as success and make all tasks return negative if they wish to have their error handler called. A subsequent patch will rename error_handler to event_handler. --- diff --git a/error.h b/error.h index 84f42798..a53531b7 100644 --- a/error.h +++ b/error.h @@ -88,6 +88,7 @@ extern const char **para_errlist[]; #define STDIN_ERRORS \ PARA_ERROR(STDIN_READ, "failed to read from stdin"), \ + PARA_ERROR(STDIN_EOF, "end of file"), \ #define SCHED_ERRORS \ @@ -351,7 +352,9 @@ extern const char **para_errlist[]; PARA_ERROR(WRITE_OVERRUN, "buffer overrun"), \ PARA_ERROR(PREMATURE_END, "premature end of audio file"), \ PARA_ERROR(NO_WAV_HEADER, "wave header not found"), \ + PARA_ERROR(WAV_HEADER_SUCCESS, "successfully read wave header"), \ PARA_ERROR(NO_DELAY, "no initial delay"), \ + PARA_ERROR(DELAY_TIMEOUT, "initial delay timeout"), \ #define ALSA_WRITER_ERRORS \ @@ -383,6 +386,7 @@ extern const char **para_errlist[]; #define WRITE_COMMON_ERRORS \ PARA_ERROR(WRITE_COMMON_SYNTAX, "syntax error in write option"), \ + PARA_ERROR(WNG_EOF, "wng: end of file"), \ #define AACDEC_ERRORS \ diff --git a/sched.c b/sched.c index fad70132..6233e40b 100644 --- a/sched.c +++ b/sched.c @@ -18,13 +18,6 @@ again: t->pre_select(s, t); if (t->ret > 0 || !t->error_handler) continue; - if (t->ret < 0) { - t->error_handler(t); - goto again; - } - if (!(t->flags & PRE_EOF_IS_ERROR)) - continue; - t->ret = -E_PRE_EOF; t->error_handler(t); goto again; } @@ -38,13 +31,6 @@ static void sched_post_select(struct sched *s) t->post_select(s, t); if (t->ret > 0 || !t->error_handler) continue; - if (t->ret < 0) { - t->error_handler(t); - continue; - } - if (!(t->flags & POST_EOF_IS_ERROR)) - continue; - t->ret = -E_POST_EOF; t->error_handler(t); } } @@ -72,7 +58,7 @@ again: void *register_task(struct task *t) { - PARA_INFO_LOG("registering task %p\n", t); + PARA_INFO_LOG("registering %s (%p)\n", t->status, t); if (t->pre_select) { PARA_DEBUG_LOG("pre_select: %p\n", &t->pre_select); if (t->flags & PRE_ADD_TAIL) @@ -92,7 +78,7 @@ void *register_task(struct task *t) void unregister_task(struct task *t) { - PARA_INFO_LOG("unregistering task %p\n", t); + PARA_INFO_LOG("unregistering %s (%p)\n", t->status, t); if (t->pre_select) list_del(&t->pre_select_node); if (t->post_select) diff --git a/sched.h b/sched.h index 3de5e1cc..8ed4cd12 100644 --- a/sched.h +++ b/sched.h @@ -21,8 +21,6 @@ struct task { enum task_flags { PRE_ADD_TAIL = 1, POST_ADD_TAIL = 2, - PRE_EOF_IS_ERROR = 4, - POST_EOF_IS_ERROR = 8, }; void *register_task(struct task *t); diff --git a/stdin.c b/stdin.c index 6b9c8098..299c326e 100644 --- a/stdin.c +++ b/stdin.c @@ -31,10 +31,7 @@ void stdin_post_select(struct sched *s, struct task *t) sit->loaded += ret; t->ret = ret; } else - t->ret = 0; - if (ret <= 0) + t->ret = -E_STDIN_EOF; + if (t->ret < 0) sit->eof = 1; - sprintf(t->status, - "%p stdin reader: loaded = %d, ret = %d", - sit, sit->loaded, t->ret); } diff --git a/write.c b/write.c index 7e6d47a5..3e5a97e8 100644 --- a/write.c +++ b/write.c @@ -74,7 +74,7 @@ static void check_wav_pre_select(struct sched *s, struct task *t) cwt->sample_rate = a[24] + (a[25] << 8) + (a[26] << 16) + (a[27] << 24); *cwt->loaded -= WAV_HEADER_LEN; memmove(cwt->buf, cwt->buf + WAV_HEADER_LEN, *cwt->loaded); - t->ret = 0; + t->ret = -E_WAV_HEADER_SUCCESS; PARA_INFO_LOG("channels: %d, sample_rate: %d\n", cwt->channels, cwt->sample_rate); } @@ -83,11 +83,10 @@ static void initial_delay_pre_select(struct sched *s, struct task *t) struct initial_delay_task *idt = t->private_data; struct timeval diff; - PARA_ERROR_LOG("task %p, ret: %d\n", t, t->ret); t->ret = -E_NO_DELAY; if (!idt->start_time.tv_sec && !idt->start_time.tv_usec) return; - t->ret = 0; /* timeout */ + t->ret = -E_DELAY_TIMEOUT; if (tv_diff(&s->now, &idt->start_time, &diff) > 0) return; t->ret = 1; @@ -146,6 +145,8 @@ static struct writer_node_group *check_args(void) if (ret < 0) goto out; wng->writer_nodes[i].writer = &writers[ret]; + sprintf(wng->writer_nodes[i].task.status, "%s", + writer_names[ret]); } ret = 1; out: @@ -158,12 +159,14 @@ out: static void idt_error_handler(struct task *t) { - PARA_ERROR_LOG("task %p, ret: %d\n", t, t->ret); int ret; + + PARA_INFO_LOG("%s\n", PARA_STRERROR(-t->ret)); unregister_task(t); wng->buf = sit.buf; wng->loaded = &sit.loaded; wng->eof = &sit.eof; + sprintf(wng->task.status, "%s", "writer node group"); ret = wng_open(wng); if (ret < 0) { PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); @@ -173,29 +176,29 @@ static void idt_error_handler(struct task *t) static void cwt_error_handler(struct task *t) { - PARA_ERROR_LOG("task %p, ret: %d\n", t, t->ret); - if (t->ret < 0) { + if (t->ret != -E_NO_WAV_HEADER && t->ret != -E_WAV_HEADER_SUCCESS) { PARA_ERROR_LOG("%s\n", PARA_STRERROR(-t->ret)); - if (t->ret != -E_NO_WAV_HEADER && t->ret != -E_PRE_EOF) - exit(EXIT_FAILURE); - if (t->ret == -E_PRE_EOF) { - conf.channels_arg = cwt.channels; - conf.sample_rate_arg = cwt.sample_rate; - } + exit(EXIT_FAILURE); } + PARA_INFO_LOG("%s\n", PARA_STRERROR(-t->ret)); unregister_task(t); + if (t->ret == -E_WAV_HEADER_SUCCESS) { + conf.channels_arg = cwt.channels; + conf.sample_rate_arg = cwt.sample_rate; + } idt.task.pre_select = initial_delay_pre_select; idt.task.private_data = &idt; idt.task.error_handler = idt_error_handler; - idt.task.flags = PRE_EOF_IS_ERROR; + sprintf(idt.task.status, "initial_delay"); register_task(&idt.task); } static void stdin_error_handler(struct task *t) { unregister_task(t); - PARA_INFO_LOG("task %p, ret: %d\n", t, t->ret); - if (t->ret < 0) + if (t->ret != -E_STDIN_EOF) + PARA_ERROR_LOG("%s\n", PARA_STRERROR(-t->ret)); + else PARA_ERROR_LOG("%s\n", PARA_STRERROR(-t->ret)); } @@ -217,8 +220,8 @@ int main(int argc, char *argv[]) sit.task.pre_select = stdin_pre_select; sit.task.post_select = stdin_post_select; sit.task.error_handler = stdin_error_handler; - sit.task.flags = POST_EOF_IS_ERROR; sit.task.private_data = &sit; + sprintf(sit.task.status, "stdin reader"); register_task(&sit.task); cwt.task.pre_select = check_wav_pre_select; @@ -227,7 +230,7 @@ int main(int argc, char *argv[]) cwt.buf = sit.buf; cwt.loaded = &sit.loaded; cwt.eof = &sit.eof; - cwt.task.flags = PRE_EOF_IS_ERROR; + sprintf(cwt.task.status, "check wav"); register_task(&cwt.task); s.default_timeout.tv_sec = 1; diff --git a/write_common.c b/write_common.c index 2cb0eafd..7622c020 100644 --- a/write_common.c +++ b/write_common.c @@ -46,7 +46,7 @@ static void wng_post_select(struct sched *s, struct task *t) } *g->loaded -= min_written; if (!*g->loaded && *g->eof) - t->ret = 0; + t->ret = -E_WNG_EOF; else t->ret = 1; if (*g->loaded && min_written) @@ -70,7 +70,6 @@ int wng_open(struct writer_node_group *g) wn->task.pre_select = wn->writer->pre_select; wn->task.post_select = wn->writer->post_select; wn->task.private_data = wn; - wn->task.flags = POST_EOF_IS_ERROR; register_task(&wn->task); } register_task(&g->task); @@ -102,7 +101,7 @@ static void wng_error_handler(struct task *t) { struct writer_node_group *g = t->private_data; - PARA_INFO_LOG("%p: ret = %d\n", t, t->ret); + PARA_INFO_LOG("%s\n", PARA_STRERROR(-t->ret)); unregister_task(t); wng_close(g); wng_destroy(g); @@ -118,7 +117,7 @@ struct writer_node_group *wng_new(unsigned num_writers) g->task.private_data = g; g->task.post_select = wng_post_select; g->task.error_handler = wng_error_handler; - g->task.flags = POST_ADD_TAIL | POST_EOF_IS_ERROR; + g->task.flags = POST_ADD_TAIL; return g; } @@ -158,6 +157,8 @@ struct writer_node_group *setup_default_wng(void) else default_writer = 1; wng->writer_nodes[0].writer = &writers[default_writer]; + sprintf(wng->writer_nodes[0].task.status, "%s", + writer_names[default_writer]); PARA_INFO_LOG("using default writer: %s\n", writer_names[default_writer]); return wng;