From 91a143e5c916de6104f42b7eeaa8d6b51a157e24 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Mon, 8 Jun 2020 16:46:46 +0200 Subject: [PATCH] Swap g_private_set with g_private_replace where possible There's a possibility that the old GDestroyNotify handler is not called when threads are being reused. --- libvips/iofuncs/gate.c | 4 +--- libvips/iofuncs/threadpool.c | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/libvips/iofuncs/gate.c b/libvips/iofuncs/gate.c index 3e42028c..163e1d94 100644 --- a/libvips/iofuncs/gate.c +++ b/libvips/iofuncs/gate.c @@ -245,15 +245,13 @@ vips__thread_profile_attach( const char *thread_name ) VIPS_DEBUG_MSG( "vips__thread_profile_attach: %s\n", thread_name ); - g_assert( !g_private_get( vips_thread_profile_key ) ); - profile = g_new( VipsThreadProfile, 1 ); profile->name = thread_name; profile->gates = g_hash_table_new_full( g_direct_hash, g_str_equal, NULL, (GDestroyNotify) vips_thread_gate_free ); profile->memory = vips_thread_gate_new( "memory" ); - g_private_set( vips_thread_profile_key, profile ); + g_private_replace( vips_thread_profile_key, profile ); } static VipsThreadProfile * diff --git a/libvips/iofuncs/threadpool.c b/libvips/iofuncs/threadpool.c index b22879e7..1e63ceb2 100644 --- a/libvips/iofuncs/threadpool.c +++ b/libvips/iofuncs/threadpool.c @@ -201,7 +201,8 @@ vips_thread_main_loop( gpointer thread_data, gpointer pool_data ) VipsThreadExec *exec = (VipsThreadExec *) thread_data; /* Set this to something (anything) to tag this thread as a vips - * worker. + * worker. No need to call g_private_replace as there is no + * GDestroyNotify handler associated with a worker. */ g_private_set( is_worker_key, thread_data );