From dcc6ffd1841506b34bf494d032ec895c64e48787 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Mon, 6 Dec 2010 17:05:35 +0100 Subject: [PATCH] Avoiding to start writer thread if iso_write_opts_set_will_cancel() is set to 1. --- libisofs/ecma119.c | 32 +++++++++++++++++++++++++++----- libisofs/ecma119.h | 1 + libisofs/libisofs.h | 12 +++++++----- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/libisofs/ecma119.c b/libisofs/ecma119.c index a25c08d..5b915e0 100644 --- a/libisofs/ecma119.c +++ b/libisofs/ecma119.c @@ -1732,6 +1732,8 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) target->empty_file_block = 0; + target->wthread_is_running = 0; + for (i = 0; i < ISO_MAX_PARTITIONS; i++) { target->appended_partitions[i] = NULL; if (opts->appended_partitions[i] != NULL) { @@ -2049,6 +2051,20 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) /* This was possibly altered by above overwrite buffer production */ target->vol_space_size = target->curblock - target->ms_block; +/* +*/ +#define Libisofs_print_size_no_forK 1 + +#ifdef Libisofs_print_size_no_forK + if (opts->will_cancel) { + iso_msg_debug(target->image->id, + "Will not start write thread because of iso_write_opts_set_will_cancel"); + *img = target; + return ISO_SUCCESS; + } +#endif + + /* 4. Create and start writing thread */ if (target->md5_session_checksum) { /* After any fake writes are done: Initialize image checksum context */ @@ -2090,6 +2106,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) ret = ISO_THREAD_ERROR; goto target_cleanup; } + target->wthread_is_running= 1; /* * Notice that once we reach this point, target belongs to the writer @@ -2146,8 +2163,11 @@ static void bs_free_data(struct burn_source *bs) iso_ring_buffer_reader_close(target->buffer, 0); /* wait until writer thread finishes */ - pthread_join(target->wthread, NULL); - iso_msg_debug(target->image->id, "Writer thread joined"); + if (target->wthread_is_running) { + pthread_join(target->wthread, NULL); + target->wthread_is_running = 0; + iso_msg_debug(target->image->id, "Writer thread joined"); + } } iso_msg_debug(target->image->id, @@ -2179,9 +2199,11 @@ int bs_cancel(struct burn_source *bs) } /* wait until writer thread finishes */ - pthread_join(target->wthread, NULL); - - iso_msg_debug(target->image->id, "Writer thread joined"); + if (target->wthread_is_running) { + pthread_join(target->wthread, NULL); + target->wthread_is_running = 0; + iso_msg_debug(target->image->id, "Writer thread joined"); + } return ISO_SUCCESS; } diff --git a/libisofs/ecma119.h b/libisofs/ecma119.h index 3f0cf22..46dfe96 100644 --- a/libisofs/ecma119.h +++ b/libisofs/ecma119.h @@ -586,6 +586,7 @@ struct ecma119_image /* writer thread descriptor */ pthread_t wthread; + int wthread_is_running; pthread_attr_t th_attr; /* User settable PVD time stamps */ diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index 2771455..f49c297 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -1206,11 +1206,13 @@ int iso_write_opts_new(IsoWriteOpts **opts, int profile); void iso_write_opts_free(IsoWriteOpts *opts); /** - * Announce that only the image size is desired and that the write thread - * will be cancelled by the .cancel() method of the struct burn_source that - * consumes the image output stream. - * This avoids to generate a MISHAP event when the effect of .cancel() - * reaches the image generator thread. + * Announce that only the image size is desired, that the struct burn_source + * which is set to consume the image output stream will stay inactive, + * and that the write thread will be cancelled anyway by the .cancel() method + * of the struct burn_source. + * This avoids to create a write thread which would begin production of the + * image stream and would generate a MISHAP event when burn_source.cancel() + * gets into effect. * * @param opts * The option set to be manipulated.