Skip to content

Commit 6946c3b

Browse files
committed
start up threadpool later
might help php and ruby web frameworks see eg. libvips/php-vips-ext#42
1 parent ee86525 commit 6946c3b

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

ChangeLog

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
14/8/20 started 8.11.2
1+
14/7/21 started 8.11.3
2+
- build threadpool later [kleisauke]
3+
4+
15/6/20 started 8.11.2
25
- better libdir guessing [remi]
36
- fix tiff pyramid creation with jp2k compression (was broken by 8.11.1)
47
- don't load modules if we're built without modules
58

6-
14/8/20 started 8.11.1
9+
18/6/21 started 8.11.1
710
- add more example code to C docs
811
- update libtool support in configure.ac
912
- more startup info if VIPS_INFO is set

configure.ac

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# also update the version number in the m4 macros below
44

5-
AC_INIT([vips],[8.11.2],[vipsip@jiscmail.ac.uk])
5+
AC_INIT([vips],[8.11.3],[vipsip@jiscmail.ac.uk])
66
# required for gobject-introspection
77
AC_PREREQ([2.69])
88

@@ -18,7 +18,7 @@ AC_CONFIG_MACRO_DIR([m4])
1818
# user-visible library versioning
1919
m4_define([vips_major_version], [8])
2020
m4_define([vips_minor_version], [11])
21-
m4_define([vips_micro_version], [2])
21+
m4_define([vips_micro_version], [3])
2222
m4_define([vips_version],
2323
[vips_major_version.vips_minor_version.vips_micro_version])
2424

@@ -43,7 +43,7 @@ VIPS_LIBS=""
4343
# binary interface changes not backwards compatible?: reset age to 0
4444

4545
LIBRARY_CURRENT=55
46-
LIBRARY_REVISION=1
46+
LIBRARY_REVISION=2
4747
LIBRARY_AGE=13
4848

4949
# patched into include/vips/version.h

libvips/iofuncs/threadpool.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,19 @@ vips_task_free( VipsTask *task )
731731
VIPS_FREE( task );
732732
}
733733

734+
static void *
735+
vips__thread_once_init( void *data )
736+
{
737+
/* We can have many more than vips__concurrency threads -- each active
738+
* pipeline will make vips__concurrency more, see
739+
* vips_threadpool_run().
740+
*/
741+
vips__pool = g_thread_pool_new( vips_thread_main_loop, NULL,
742+
-1, FALSE, NULL );
743+
744+
return( NULL );
745+
}
746+
734747
/**
735748
* vips__thread_execute:
736749
* @name: a name for the thread
@@ -747,10 +760,14 @@ vips_task_free( VipsTask *task )
747760
int
748761
vips__thread_execute( const char *name, GFunc func, gpointer data )
749762
{
763+
static GOnce once = G_ONCE_INIT;
764+
750765
VipsThreadExec *exec;
751766
GError *error = NULL;
752767
gboolean result;
753768

769+
VIPS_ONCE( &once, vips__thread_once_init, NULL );
770+
754771
exec = g_new( VipsThreadExec, 1 );
755772
exec->name = name;
756773
exec->func = func;
@@ -948,12 +965,12 @@ vips__threadpool_init( void )
948965
if( vips__concurrency == 0 )
949966
vips__concurrency = vips__concurrency_get_default();
950967

951-
/* We can have many more than vips__concurrency threads -- each active
952-
* pipeline will make vips__concurrency more, see
953-
* vips_threadpool_run().
968+
/* The threadpool is built in the first vips__thread_execute()
969+
* call, since we want thread creation to happen as late as possible.
970+
*
971+
* Many web platforms start up in a base environment, then fork() for
972+
* each request. We must not make the threadpool before the fork.
954973
*/
955-
vips__pool = g_thread_pool_new( vips_thread_main_loop, NULL,
956-
-1, FALSE, NULL );
957974

958975
VIPS_DEBUG_MSG( "vips__threadpool_init: (%p)\n", vips__pool );
959976
}

0 commit comments

Comments
 (0)