diff --git a/ChangeLog b/ChangeLog index 6cae5f3b..20819463 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,8 @@ - tilecache speedups - add vips_heifload(), vips_heifsave() - add heif thumbnail support to vips_thumbnail() +- free threadpool earlier, reducing mem growth for some long-running + processes [jtorresfabra] 4/1/19 started 8.7.4 - magickload with magick6 API did not chain exceptions correctly causing a diff --git a/libvips/iofuncs/threadpool.c b/libvips/iofuncs/threadpool.c index 3793018f..b815d605 100644 --- a/libvips/iofuncs/threadpool.c +++ b/libvips/iofuncs/threadpool.c @@ -21,6 +21,8 @@ * 23/4/17 * - add ->stall * - don't depend on image width when setting n_lines + * 27/2/19 jtorresfabra + * - free threadpool earlier */ /* @@ -579,9 +581,8 @@ vips_thread_free( VipsThread *thr ) VIPS_FREEF( g_object_unref, thr->state ); thr->pool = NULL; - /* Free the thread memory - */ - g_free(thr); + + VIPS_FREE( thr ); } static int @@ -591,10 +592,9 @@ vips_thread_allocate( VipsThread *thr ) g_assert( !pool->stop ); - if( !thr->state ) { - if( !(thr->state = pool->start( pool->im, pool->a )) ) - return( -1 ); - } + if( !thr->state && + !(thr->state = pool->start( pool->im, pool->a )) ) + return( -1 ); if( pool->allocate( thr->state, pool->a, &pool->stop ) ) return( -1 ); @@ -728,7 +728,8 @@ vips_thread_new( VipsThreadpool *pool ) return( thr ); } -/* Kill all threads in a threadpool, if there are any. +/* Kill all threads in a threadpool, if there are any. Can be called multiple + * times. */ static void vips_threadpool_kill_threads( VipsThreadpool *pool ) @@ -737,23 +738,14 @@ vips_threadpool_kill_threads( VipsThreadpool *pool ) int i; for( i = 0; i < pool->nthr; i++ ) - if( pool->thr[i] ) { - vips_thread_free( pool->thr[i] ); - pool->thr[i] = NULL; - } - /* Free the thread array - */ - g_free(pool->thr); - pool->thr = NULL; + VIPS_FREEF( vips_thread_free, pool->thr[i] ); VIPS_DEBUG_MSG( "vips_threadpool_kill_threads: " "killed %d threads\n", pool->nthr ); } } -/* This can be called multiple times, careful. - */ -static int +static void vips_threadpool_free( VipsThreadpool *pool ) { VIPS_DEBUG_MSG( "vips_threadpool_free: \"%s\" (%p)\n", @@ -763,16 +755,8 @@ vips_threadpool_free( VipsThreadpool *pool ) VIPS_FREEF( vips_g_mutex_free, pool->allocate_lock ); vips_semaphore_destroy( &pool->finish ); vips_semaphore_destroy( &pool->tick ); - /* Free pool memory - */ - g_free(pool); - return( 0 ); -} - -static void -vips_threadpool_new_cb( VipsImage *im, VipsThreadpool *pool ) -{ - vips_threadpool_free( pool ); + VIPS_FREE( pool->thr ); + VIPS_FREE( pool ); } static VipsThreadpool *