From dc05c43b65460d72ae45164f61e327d715a6e954 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 12 Jul 2012 12:30:20 -0700 Subject: [PATCH] notify: set lower bound for notify stack size Some OSes have ridiculously low boundaries and we don't want mysterious failures on them --- ext/posix_mq/posix_mq.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ext/posix_mq/posix_mq.c b/ext/posix_mq/posix_mq.c index df667e3..66f3f99 100644 --- a/ext/posix_mq/posix_mq.c +++ b/ext/posix_mq/posix_mq.c @@ -850,6 +850,19 @@ static void my_mq_notify(mqd_t des, struct sigevent *not) } } +static void lower_stack_size(pthread_attr_t *attr) +{ +/* some OSes have ridiculously small stack sizes */ +#ifdef PTHREAD_STACK_MIN + size_t stack_size = PTHREAD_STACK_MIN; + size_t min_size = 4096; + + if (stack_size < min_size) + stack_size = min_size; + pthread_attr_setstacksize(attr, stack_size); +#endif +} + /* :nodoc: */ static VALUE setnotify_exec(VALUE self, VALUE io, VALUE thr) { @@ -864,10 +877,7 @@ static VALUE setnotify_exec(VALUE self, VALUE io, VALUE thr) errno = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (errno) rb_sys_fail("pthread_attr_setdetachstate"); -#ifdef PTHREAD_STACK_MIN - (void)pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN); -#endif - + lower_stack_size(&attr); not.sigev_notify = SIGEV_THREAD; not.sigev_notify_function = thread_notify_fd; not.sigev_notify_attributes = &attr; -- 2.11.4.GIT