diff options
author | Eric Wong <normalperson@yhbt.net> | 2012-07-12 12:30:20 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2012-07-12 12:30:20 -0700 |
commit | dc05c43b65460d72ae45164f61e327d715a6e954 (patch) | |
tree | 702d1121b19286b8afba2d58e32991b648a7607b /ext/posix_mq/posix_mq.c | |
parent | 73dfbeb1d59fbc1e22651cb4da8ee85f0a6fd9ce (diff) | |
download | ruby_posix_mq-dc05c43b65460d72ae45164f61e327d715a6e954.tar.gz |
Some OSes have ridiculously low boundaries and we don't want mysterious failures on them
Diffstat (limited to 'ext/posix_mq/posix_mq.c')
-rw-r--r-- | ext/posix_mq/posix_mq.c | 18 |
1 files 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; |