From 1cfa33e4fb4c227c16582c6740046fb2e6263889 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 15 Aug 2011 16:24:46 +0100 Subject: [PATCH] better termination handling setting and detecting ->kill is now treated more like a message ... you can now cancel calculation in nip2 without breaking calculation --- ChangeLog | 1 + libvips/iofuncs/image.c | 25 +++++++++++++++++++++---- libvips/iofuncs/sink.c | 5 +++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index a48305d0..290657e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 10/8/11 started 7.26.3 - don't use G_VALUE_COLLECT_INIT(), many platforms do not have a glib this recent +- don't leave image->kill set when we detect termination 10/8/11 started 7.26.2 - oops, im_benchmark.c had some stuff turned off diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index 328d2b6f..3a0aff70 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -1348,20 +1348,33 @@ vips_image_set_progress( VipsImage *image, gboolean progress ) gboolean vips_image_get_kill( VipsImage *image ) { + gboolean kill; + + kill = image->kill; + /* Has kill been set for this image? If yes, abort evaluation. */ - if( image->kill ) + if( image->kill ) { + VIPS_DEBUG_MSG( "vips_image_get_kill: %s (%p) killed\n", + image->filename, image ); vips_error( "VipsImage", _( "killed for image \"%s\"" ), image->filename ); - return( image->kill ); + /* We've picked up the kill message, it's now our caller's + * responsibility to pass the message up the chain. + */ + vips_image_set_kill( image, FALSE ); + } + + return( kill ); } void vips_image_set_kill( VipsImage *image, gboolean kill ) { - if( !image->kill ) - VIPS_DEBUG_MSG( "vips_image_set_kill: %s\n", image->filename ); + if( image->kill != kill ) + VIPS_DEBUG_MSG( "vips_image_set_kill: %s (%p) %d\n", + image->filename, image, kill ); image->kill = kill; } @@ -1880,6 +1893,10 @@ vips_image_write_line( VipsImage *image, int ypos, PEL *linebuffer ) /* Is this the start of eval? */ if( ypos == 0 ) { + /* Always clear kill before we start looping. See the + * call to vips_image_get_kill() below. + */ + vips_image_set_kill( image, FALSE ); vips__image_write_prepare( image ); vips_image_preeval( image ); } diff --git a/libvips/iofuncs/sink.c b/libvips/iofuncs/sink.c index 0106d8e8..81741231 100644 --- a/libvips/iofuncs/sink.c +++ b/libvips/iofuncs/sink.c @@ -203,6 +203,11 @@ sink_free( Sink *sink ) void vips_sink_base_init( SinkBase *sink_base, VipsImage *image ) { + /* Always clear kill before we start looping. See the + * call to vips_image_get_kill() below. + */ + vips_image_set_kill( image, FALSE ); + sink_base->im = image; sink_base->x = 0; sink_base->y = 0;