Avoiding to start writer thread if iso_write_opts_set_will_cancel() is set to 1.

This commit is contained in:
Thomas Schmitt 2010-12-06 17:05:35 +01:00
parent 27e69c38ab
commit dcc6ffd184
3 changed files with 35 additions and 10 deletions

View File

@ -1732,6 +1732,8 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img)
target->empty_file_block = 0; target->empty_file_block = 0;
target->wthread_is_running = 0;
for (i = 0; i < ISO_MAX_PARTITIONS; i++) { for (i = 0; i < ISO_MAX_PARTITIONS; i++) {
target->appended_partitions[i] = NULL; target->appended_partitions[i] = NULL;
if (opts->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 */ /* This was possibly altered by above overwrite buffer production */
target->vol_space_size = target->curblock - target->ms_block; 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 */ /* 4. Create and start writing thread */
if (target->md5_session_checksum) { if (target->md5_session_checksum) {
/* After any fake writes are done: Initialize image checksum context */ /* 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; ret = ISO_THREAD_ERROR;
goto target_cleanup; goto target_cleanup;
} }
target->wthread_is_running= 1;
/* /*
* Notice that once we reach this point, target belongs to the writer * 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); iso_ring_buffer_reader_close(target->buffer, 0);
/* wait until writer thread finishes */ /* wait until writer thread finishes */
pthread_join(target->wthread, NULL); if (target->wthread_is_running) {
iso_msg_debug(target->image->id, "Writer thread joined"); 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, iso_msg_debug(target->image->id,
@ -2179,9 +2199,11 @@ int bs_cancel(struct burn_source *bs)
} }
/* wait until writer thread finishes */ /* wait until writer thread finishes */
pthread_join(target->wthread, NULL); if (target->wthread_is_running) {
pthread_join(target->wthread, NULL);
iso_msg_debug(target->image->id, "Writer thread joined"); target->wthread_is_running = 0;
iso_msg_debug(target->image->id, "Writer thread joined");
}
return ISO_SUCCESS; return ISO_SUCCESS;
} }

View File

@ -586,6 +586,7 @@ struct ecma119_image
/* writer thread descriptor */ /* writer thread descriptor */
pthread_t wthread; pthread_t wthread;
int wthread_is_running;
pthread_attr_t th_attr; pthread_attr_t th_attr;
/* User settable PVD time stamps */ /* User settable PVD time stamps */

View File

@ -1206,11 +1206,13 @@ int iso_write_opts_new(IsoWriteOpts **opts, int profile);
void iso_write_opts_free(IsoWriteOpts *opts); void iso_write_opts_free(IsoWriteOpts *opts);
/** /**
* Announce that only the image size is desired and that the write thread * Announce that only the image size is desired, that the struct burn_source
* will be cancelled by the .cancel() method of the struct burn_source that * which is set to consume the image output stream will stay inactive,
* consumes the image output stream. * and that the write thread will be cancelled anyway by the .cancel() method
* This avoids to generate a MISHAP event when the effect of .cancel() * of the struct burn_source.
* reaches the image generator thread. * 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 * @param opts
* The option set to be manipulated. * The option set to be manipulated.