Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide an option to set the default stack size on linux #1291

Merged
merged 1 commit into from
Apr 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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