From 3b5f41028b9627b6f474c2c3aee2b1d85718dfa5 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Fri, 15 Dec 2017 13:15:13 +0000 Subject: [PATCH] allocator_thread: use bigger stacksize for Mac OS X --- src/allocator_thread.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/allocator_thread.c b/src/allocator_thread.c index d488454..3877484 100644 --- a/src/allocator_thread.c +++ b/src/allocator_thread.c @@ -1,3 +1,8 @@ +#undef _GNU_SOURCE +#define _GNU_SOURCE +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#include #include #include #include @@ -151,7 +156,6 @@ struct at_msghdr { }; static pthread_t allocator_thread; -static pthread_attr_t allocator_thread_attr; int req_pipefd[2]; int resp_pipefd[2]; @@ -309,6 +313,15 @@ static void initpipe(int* fds) { } } +#ifndef MAX +#define MAX(x, y) ((x) > (y) ? (x) : (y)) +#endif + +#if !defined(PTHREAD_STACK_MIN) || defined(__APPLE__) +/* MAC says its min is 8KB, but then crashes in our face. thx hunkOLard */ +#define PTHREAD_STACK_MIN 64*1024 +#endif + /* initialize with pointers to shared memory. these will * be used to place responses and arguments */ void at_init(void) { @@ -318,9 +331,11 @@ void at_init(void) { memset(internal_ips, 0, sizeof *internal_ips); initpipe(req_pipefd); initpipe(resp_pipefd); + pthread_attr_t allocator_thread_attr; pthread_attr_init(&allocator_thread_attr); - pthread_attr_setstacksize(&allocator_thread_attr, 16 * 1024); + pthread_attr_setstacksize(&allocator_thread_attr, MAX(16 * 1024, PTHREAD_STACK_MIN)); pthread_create(&allocator_thread, &allocator_thread_attr, threadfunc, 0); + pthread_attr_destroy(&allocator_thread_attr); } void at_close(void) { @@ -332,6 +347,5 @@ void at_close(void) { close(req_pipefd[1]); close(resp_pipefd[0]); close(resp_pipefd[1]); - pthread_attr_destroy(&allocator_thread_attr); MUTEX_DESTROY(&internal_ips_lock); }