diff --git a/libvips/colour/LabQ2sRGB.c b/libvips/colour/LabQ2sRGB.c index d0dbc20b..f53e409a 100644 --- a/libvips/colour/LabQ2sRGB.c +++ b/libvips/colour/LabQ2sRGB.c @@ -171,8 +171,7 @@ vips_col_make_tables_RGB_8( void ) { static GOnce once = G_ONCE_INIT; - if( G_UNLIKELY( once.status != G_ONCE_STATUS_READY ) ) - (void) g_once( &once, calcul_tables_8, NULL ); + VIPS_ONCE( &once, calcul_tables_8, NULL ); } int @@ -196,8 +195,7 @@ vips_col_make_tables_RGB_16( void ) { static GOnce once = G_ONCE_INIT; - if( G_UNLIKELY( once.status != G_ONCE_STATUS_READY ) ) - (void) g_once( &once, calcul_tables_16, NULL ); + VIPS_ONCE( &once, calcul_tables_16, NULL ); } int @@ -448,7 +446,7 @@ vips_col_make_tables_LabQ2sRGB( void ) { static GOnce once = G_ONCE_INIT; - (void) g_once( &once, build_tables, NULL ); + VIPS_ONCE( &once, build_tables, NULL ); } /* Process a buffer of data. diff --git a/libvips/colour/UCS2LCh.c b/libvips/colour/UCS2LCh.c index 397861a8..e6b46530 100644 --- a/libvips/colour/UCS2LCh.c +++ b/libvips/colour/UCS2LCh.c @@ -228,7 +228,7 @@ vips_col_make_tables_CMC( void ) { static GOnce once = G_ONCE_INIT; - (void) g_once( &once, tables_init, NULL ); + VIPS_ONCE( &once, tables_init, NULL ); } /* Process a buffer of data. diff --git a/libvips/colour/XYZ2Lab.c b/libvips/colour/XYZ2Lab.c index 14a8b488..d9acebd3 100644 --- a/libvips/colour/XYZ2Lab.c +++ b/libvips/colour/XYZ2Lab.c @@ -120,7 +120,7 @@ vips_XYZ2Lab_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width ) int x; - (void) g_once( &once, table_init, NULL ); + VIPS_ONCE( &once, table_init, NULL ); for( x = 0; x < width; x++ ) { float nX, nY, nZ; diff --git a/libvips/create/perlin.c b/libvips/create/perlin.c index 24d0cf1c..5181f365 100644 --- a/libvips/create/perlin.c +++ b/libvips/create/perlin.c @@ -284,7 +284,7 @@ vips_perlin_class_init( VipsPerlinClass *class ) static GOnce once = G_ONCE_INIT; - (void) g_once( &once, vips_perlin_make_tables, NULL ); + VIPS_ONCE( &once, vips_perlin_make_tables, NULL ); gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property; diff --git a/libvips/create/text.c b/libvips/create/text.c index 0c89e295..db27bf75 100644 --- a/libvips/create/text.c +++ b/libvips/create/text.c @@ -408,7 +408,7 @@ vips_text_class_init( VipsTextClass *class ) static GOnce once = G_ONCE_INIT; - (void) g_once( &once, vips_text_make_lock, NULL ); + VIPS_ONCE( &once, vips_text_make_lock, NULL ); gobject_class->dispose = vips_text_dispose; gobject_class->set_property = vips_object_set_property; diff --git a/libvips/foreign/magick7load.c b/libvips/foreign/magick7load.c index 1d483483..98e1a753 100644 --- a/libvips/foreign/magick7load.c +++ b/libvips/foreign/magick7load.c @@ -293,7 +293,7 @@ vips_foreign_load_magick7_genesis( void ) { static GOnce once = G_ONCE_INIT; - (void) g_once( &once, vips_foreign_load_magick7_genesis_cb, NULL ); + VIPS_ONCE( &once, vips_foreign_load_magick7_genesis_cb, NULL ); } static int diff --git a/libvips/include/vips/util.h b/libvips/include/vips/util.h index 413be3bf..aa693183 100644 --- a/libvips/include/vips/util.h +++ b/libvips/include/vips/util.h @@ -86,6 +86,14 @@ extern "C" { #define VIPS_FMIN( A, B ) VIPS_MIN( A, B ) #endif +/* Testing status before the function call saves a lot of time. + */ +#define VIPS_ONCE( ONCE, FUNC, CLIENT ) \ +G_STMT_START { \ + if( G_UNLIKELY( (ONCE)->status != G_ONCE_STATUS_READY ) ) \ + (void) g_once( ONCE, FUNC, CLIENT ); \ +} G_STMT_END + /* VIPS_RINT() does "bankers rounding", it rounds to the nerarest even integer. * For things like image geometry, we want strict nearest int. * diff --git a/libvips/iofuncs/cache.c b/libvips/iofuncs/cache.c index a3d70477..bc841a76 100644 --- a/libvips/iofuncs/cache.c +++ b/libvips/iofuncs/cache.c @@ -462,7 +462,7 @@ vips__cache_init( void ) { static GOnce once = G_ONCE_INIT; - g_once( &once, (GThreadFunc) vips__cache_once_init, NULL ); + VIPS_ONCE( &once, (GThreadFunc) vips__cache_once_init, NULL ); } static void * diff --git a/libvips/iofuncs/gate.c b/libvips/iofuncs/gate.c index 84dcbcc2..0b45ec3e 100644 --- a/libvips/iofuncs/gate.c +++ b/libvips/iofuncs/gate.c @@ -245,7 +245,7 @@ vips__thread_profile_attach( const char *thread_name ) VipsThreadProfile *profile; - g_once( &once, (GThreadFunc) vips__thread_profile_init, NULL ); + VIPS_ONCE( &once, (GThreadFunc) vips__thread_profile_init, NULL ); VIPS_DEBUG_MSG( "vips__thread_profile_attach: %s\n", thread_name ); diff --git a/libvips/iofuncs/memory.c b/libvips/iofuncs/memory.c index 5d0d92d0..2bebd529 100644 --- a/libvips/iofuncs/memory.c +++ b/libvips/iofuncs/memory.c @@ -273,7 +273,7 @@ vips_tracked_init( void ) { static GOnce vips_tracked_once = G_ONCE_INIT; - g_once( &vips_tracked_once, + VIPS_ONCE( &vips_tracked_once, (GThreadFunc) vips_tracked_init_mutex, NULL ); } diff --git a/libvips/iofuncs/object.c b/libvips/iofuncs/object.c index 34c13dbb..9f078c55 100644 --- a/libvips/iofuncs/object.c +++ b/libvips/iofuncs/object.c @@ -2814,7 +2814,7 @@ vips_type_find( const char *basename, const char *nickname ) GType base; GType type; - g_once( &once, (GThreadFunc) vips_class_build_hash, NULL ); + VIPS_ONCE( &once, (GThreadFunc) vips_class_build_hash, NULL ); hit = (NicknameGType *) g_hash_table_lookup( vips__object_nickname_table, diff --git a/libvips/iofuncs/sinkscreen.c b/libvips/iofuncs/sinkscreen.c index 82447667..909cc022 100644 --- a/libvips/iofuncs/sinkscreen.c +++ b/libvips/iofuncs/sinkscreen.c @@ -1081,7 +1081,7 @@ vips_sink_screen( VipsImage *in, VipsImage *out, VipsImage *mask, Render *render; - g_once( &once, (GThreadFunc) vips_sink_screen_init, NULL ); + VIPS_ONCE( &once, (GThreadFunc) vips_sink_screen_init, NULL ); if( tile_width <= 0 || tile_height <= 0 || max_tiles < -1 ) {