From 5795a84c4fbd61685690a8cd6d43969efc083614 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Fri, 14 Aug 2020 18:05:15 +0100 Subject: [PATCH] clean up stacksize selection macros it's not good style to override libc provided macros, so let's use our own one instead. also get rid of the gratuitous variable assignment. --- sockssrv.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sockssrv.c b/sockssrv.c index 17ec819..afe7073 100644 --- a/sockssrv.c +++ b/sockssrv.c @@ -40,13 +40,18 @@ #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 */ -#undef PTHREAD_STACK_MIN -#define PTHREAD_STACK_MIN 64*1024 +#ifdef PTHREAD_STACK_MIN +#define THREAD_STACK_SIZE MAX(8*1024, PTHREAD_STACK_MIN) +#else +#define THREAD_STACK_SIZE 64*1024 +#endif + +#if defined(__APPLE__) +#undef THREAD_STACK_SIZE +#define THREAD_STACK_SIZE 64*1024 #elif defined(__GLIBC__) || defined(__FreeBSD__) -#undef PTHREAD_STACK_MIN -#define PTHREAD_STACK_MIN 32*1024 +#undef THREAD_STACK_SIZE +#define THREAD_STACK_SIZE 32*1024 #endif static const char* auth_user; @@ -424,7 +429,6 @@ int main(int argc, char** argv) { return 1; } server = &s; - size_t stacksz = MAX(8192, PTHREAD_STACK_MIN); /* 4KB for us, 4KB for libc */ while(1) { collect(threads); @@ -445,7 +449,7 @@ int main(int argc, char** argv) { pthread_attr_t *a = 0, attr; if(pthread_attr_init(&attr) == 0) { a = &attr; - pthread_attr_setstacksize(a, stacksz); + pthread_attr_setstacksize(a, THREAD_STACK_SIZE); } if(pthread_create(&curr->pt, a, clientthread, curr) != 0) dolog("pthread_create failed. OOM?\n"); -- 2.11.4.GIT