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.
This commit is contained in:
Kleis Auke Wolthuizen 2020-06-08 16:46:46 +02:00
parent 8b01104c67
commit 91a143e5c9
2 changed files with 3 additions and 4 deletions

View File

@ -245,15 +245,13 @@ vips__thread_profile_attach( const char *thread_name )
VIPS_DEBUG_MSG( "vips__thread_profile_attach: %s\n", 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 = g_new( VipsThreadProfile, 1 );
profile->name = thread_name; profile->name = thread_name;
profile->gates = g_hash_table_new_full( profile->gates = g_hash_table_new_full(
g_direct_hash, g_str_equal, g_direct_hash, g_str_equal,
NULL, (GDestroyNotify) vips_thread_gate_free ); NULL, (GDestroyNotify) vips_thread_gate_free );
profile->memory = vips_thread_gate_new( "memory" ); 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 * static VipsThreadProfile *

View File

@ -201,7 +201,8 @@ vips_thread_main_loop( gpointer thread_data, gpointer pool_data )
VipsThreadExec *exec = (VipsThreadExec *) thread_data; VipsThreadExec *exec = (VipsThreadExec *) thread_data;
/* Set this to something (anything) to tag this thread as a vips /* 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 ); g_private_set( is_worker_key, thread_data );