|
90 | 90 | #include <vips/vector.h>
|
91 | 91 | #include <vips/vips7compat.h>
|
92 | 92 |
|
| 93 | +#ifdef HAVE_PTHREAD_DEFAULT_NP |
| 94 | +#include <pthread.h> |
| 95 | +#endif /*HAVE_PTHREAD_DEFAULT_NP*/ |
| 96 | + |
93 | 97 | /* abort() on the first warning or error.
|
94 | 98 | */
|
95 | 99 | int vips__fatal = 0;
|
@@ -309,6 +313,32 @@ vips_init( const char *argv0 )
|
309 | 313 | (void) _setmaxstdio( 2048 );
|
310 | 314 | #endif /*OS_WIN32*/
|
311 | 315 |
|
| 316 | +#ifdef HAVE_PTHREAD_DEFAULT_NP |
| 317 | +{ |
| 318 | + const char *pstacksize_str; |
| 319 | + /* Set the default stack size especially if you use musl |
| 320 | + */ |
| 321 | + if( (pstacksize_str = g_getenv( "VIPS_MIN_STACK_SIZE" )) ) { |
| 322 | + guint64 default_min_stack_size = 1 << 21; // 2MB |
| 323 | + guint64 vips_min_stack_size; |
| 324 | + guint64 cur_stack_size; |
| 325 | + pthread_attr_t attr; |
| 326 | + vips_min_stack_size = vips__parse_size(pstacksize_str); |
| 327 | + if (vips_min_stack_size == 0) { |
| 328 | + vips_min_stack_size = default_min_stack_size; |
| 329 | + } |
| 330 | + if (pthread_attr_init(&attr) || |
| 331 | + pthread_attr_getstacksize(&attr, &cur_stack_size) || |
| 332 | + (cur_stack_size > vips_min_stack_size) || |
| 333 | + pthread_attr_setstacksize(&attr, vips_min_stack_size) || |
| 334 | + pthread_setattr_default_np(&attr)) { |
| 335 | + g_warning("Could not set minimum pthread stack size of %s, current size is %dk", |
| 336 | + pstacksize_str, (int) (cur_stack_size / 1024.0) ); |
| 337 | + } |
| 338 | + } |
| 339 | +} |
| 340 | +#endif /*HAVE_PTHREAD_DEFAULT_NP*/ |
| 341 | + |
312 | 342 | #ifdef HAVE_TYPE_INIT
|
313 | 343 | /* Before glib 2.36 you have to call this on startup.
|
314 | 344 | */
|
|
0 commit comments