Skip to content

Commit

Permalink
Merge pull request libvips#1291 from abdollar/set_stack_size_linux
Browse files Browse the repository at this point in the history
provide an option to set the default stack size on linux
  • Loading branch information
jcupitt authored and priyankatapar committed Apr 22, 2019
1 parent 849d244 commit 872d087
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ AC_CHECK_FUNCS([getcwd gettimeofday getwd memset munmap putenv realpath strcasec
AC_CHECK_LIB(m,cbrt,[AC_DEFINE(HAVE_CBRT,1,[have cbrt() in libm.])])
AC_CHECK_LIB(m,hypot,[AC_DEFINE(HAVE_HYPOT,1,[have hypot() in libm.])])
AC_CHECK_LIB(m,atan2,[AC_DEFINE(HAVE_ATAN2,1,[have atan2() in libm.])])
AC_CHECK_LIB([pthread], [pthread_setattr_default_np], [AC_DEFINE(HAVE_PTHREAD_DEFAULT_NP,1,[have pthread_setattr_default_np() in pthread.])])

# have to have these
# need glib 2.6 for GOption
Expand Down
30 changes: 30 additions & 0 deletions libvips/iofuncs/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
#include <vips/vector.h>
#include <vips/vips7compat.h>

#ifdef HAVE_PTHREAD_DEFAULT_NP
#include <pthread.h>
#endif /*HAVE_PTHREAD_DEFAULT_NP*/

/* abort() on the first warning or error.
*/
int vips__fatal = 0;
Expand Down Expand Up @@ -309,6 +313,32 @@ vips_init( const char *argv0 )
(void) _setmaxstdio( 2048 );
#endif /*OS_WIN32*/

#ifdef HAVE_PTHREAD_DEFAULT_NP
{
const char *pstacksize_str;
/* Set the default stack size especially if you use musl
*/
if( (pstacksize_str = g_getenv( "VIPS_MIN_STACK_SIZE" )) ) {
guint64 default_min_stack_size = 1 << 21; // 2MB
guint64 vips_min_stack_size;
guint64 cur_stack_size;
pthread_attr_t attr;
vips_min_stack_size = vips__parse_size(pstacksize_str);
if (vips_min_stack_size == 0) {
vips_min_stack_size = default_min_stack_size;
}
if (pthread_attr_init(&attr) ||
pthread_attr_getstacksize(&attr, &cur_stack_size) ||
(cur_stack_size > vips_min_stack_size) ||
pthread_attr_setstacksize(&attr, vips_min_stack_size) ||
pthread_setattr_default_np(&attr)) {
g_warning("Could not set minimum pthread stack size of %s, current size is %dk",
pstacksize_str, (int) (cur_stack_size / 1024.0) );
}
}
}
#endif /*HAVE_PTHREAD_DEFAULT_NP*/

#ifdef HAVE_TYPE_INIT
/* Before glib 2.36 you have to call this on startup.
*/
Expand Down

0 comments on commit 872d087

Please sign in to comment.