start sinkscreen thread on first use

we were starting the sinkscreen background thread during vips_init() --
instead, start it on first use

see https://github.com/libvips/libvips/issues/1792
This commit is contained in:
John Cupitt 2020-08-28 17:46:23 +01:00
parent caa1cb9d9b
commit 99423649b9
3 changed files with 11 additions and 4 deletions

View File

@ -114,7 +114,6 @@ void vips__threadpool_init( void );
void vips__cache_init( void );
void vips__sink_screen_init( void );
void vips__print_renders( void );
void vips__type_leak( void );

View File

@ -413,7 +413,6 @@ vips_init( const char *argv0 )
#endif /*HAVE_THREAD_NEW*/
vips__threadpool_init();
vips__sink_screen_init();
vips__buffer_init();
vips__meta_init();

View File

@ -450,6 +450,9 @@ vips__render_shutdown( void )
}
else
g_mutex_unlock( render_dirty_lock );
VIPS_FREEF( vips_g_mutex_free, render_dirty_lock );
vips_semaphore_destroy( &n_render_dirty_sem );
}
}
@ -1027,8 +1030,8 @@ render_thread_main( void *client )
return( NULL );
}
void
vips__sink_screen_init( void )
static void *
vips__sink_screen_init( void *data )
{
g_assert( !render_thread );
g_assert( !render_dirty_lock );
@ -1037,6 +1040,8 @@ vips__sink_screen_init( void )
vips_semaphore_init( &n_render_dirty_sem, 0, "n_render_dirty" );
render_thread = vips_g_thread_new( "sink_screen",
render_thread_main, NULL );
return( NULL );
}
/**
@ -1096,8 +1101,12 @@ vips_sink_screen( VipsImage *in, VipsImage *out, VipsImage *mask,
int priority,
VipsSinkNotify notify_fn, void *a )
{
static GOnce once = G_ONCE_INIT;
Render *render;
VIPS_ONCE( &once, vips__sink_screen_init, NULL );
if( tile_width <= 0 || tile_height <= 0 ||
max_tiles < -1 ) {
vips_error( "vips_sink_screen", "%s", _( "bad parameters" ) );