X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=osx_write.c;h=e34f03888c800ba5e157c89a4cc011aa66fc9469;hp=0f9d9605926a81fa5be0c4643ca6565fbe0391c2;hb=1c6fa9aa4483c491c4edf0129bc26478513324ed;hpb=c4bfb18b78b3935b8dbf68f70b219cfb2a192979 diff --git a/osx_write.c b/osx_write.c index 0f9d9605..e34f0388 100644 --- a/osx_write.c +++ b/osx_write.c @@ -43,9 +43,28 @@ struct private_osx_write_data { unsigned sample_format; /** Number of channels of the current audio stream. */ unsigned channels; - /** Serializes access to buffer tree nodes. */ + /** + * Serializes access to buffer tree nodes between the writer and + * the callback which runs in a different thread. + */ int mutex; - /** The btr node of the callback. */ + /** + * The btr node of the callback. + * + * Although access to the btr node is serialized between the writer and + * the callback via the above mutex, this does not stop other buffer + * tree nodes, for example the decoder, to race against the osx + * callback. + * + * However, since all operations on buffer tree nodes are local in the + * sense that they only affect one level in the buffer tree (i.e. + * parent or child nodes, but not the grandparent or the + * grandchildren), we may work around this problem by using another + * buffer tree node for the callback. + * + * The writer grabs the mutex in its post_select method and pushes down + * the buffers to the callback node. + */ struct btr_node *callback_btrn; }; @@ -217,18 +236,18 @@ e0: return ret; } -__malloc static void *osx_write_parse_config_or_die(const char *options) +__malloc static void *osx_write_parse_config_or_die(int argc, char **argv) { struct osx_write_args_info *conf = para_calloc(sizeof(*conf)); /* exits on errors */ - osx_cmdline_parser_string(options, conf, "osx_write"); + osx_write_cmdline_parser(argc, argv, conf); return conf; } static void osx_free_config(void *conf) { - osx_cmdline_parser_free(conf); + osx_write_cmdline_parser_free(conf); } static void osx_write_close(struct writer_node *wn) @@ -309,10 +328,9 @@ static void osx_write_post_select(__a_unused struct sched *s, struct task *t) AudioOutputUnitStop(powd->audio_unit); AudioUnitUninitialize(powd->audio_unit); CloseComponent(powd->audio_unit); - btr_remove_node(powd->callback_btrn); - btr_free_node(powd->callback_btrn); + btr_remove_node(&powd->callback_btrn); remove_btrn: - btr_remove_node(btrn); + btr_remove_node(&wn->btrn); PARA_NOTICE_LOG("%s\n", para_strerror(-ret)); out: t->error = ret; @@ -327,7 +345,7 @@ void osx_write_init(struct writer *w) { struct osx_write_args_info dummy; - osx_cmdline_parser_init(&dummy); + osx_write_cmdline_parser_init(&dummy); w->close = osx_write_close; w->pre_select = osx_write_pre_select; w->post_select = osx_write_post_select; @@ -337,5 +355,5 @@ void osx_write_init(struct writer *w) .short_help = osx_write_args_info_help, .detailed_help = osx_write_args_info_detailed_help }; - osx_cmdline_parser_free(&dummy); + osx_write_cmdline_parser_free(&dummy); }