summaryrefslogtreecommitdiff
path: root/thread_pthread.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-03 03:35:11 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-03 03:35:11 +0000
commitfb15c0f16c8b1f6a9a9edd9aa9f81e61b0f5ba92 (patch)
treea675b671d294d598e90bd1b3ad6ce6ff1d73f1ca /thread_pthread.c
parent22ba8368ae2a4eadccc87c8de394662ce74003b9 (diff)
* thread_pthread.c (ruby_init_stack): use pthread_get_attr_np
to get the stack size of the main thread on FreeBSD. * thread_pthread.c: include pthread_np.h on FreeBSD. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index af0b28644a..14da80b9f7 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -12,6 +12,9 @@
#ifdef THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION
#include "gc.h"
+#ifdef __FreeBSD__
+#include <pthread_np.h>
+#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
@@ -292,18 +295,24 @@ ruby_init_stack(volatile VALUE *addr
native_main_thread.register_stack_start = (VALUE*)bsp;
}
#endif
-#ifdef HAVE_GETRLIMIT
{
+ size_t size = 0, space = 0;
+#ifdef __FreeBSD__
+ pthread_attr_t attr;
+ if (pthread_attr_init(&attr) == 0) {
+ pthread_attr_get_np(native_main_thread.id, &attr) ||
+ pthread_attr_getstacksize(&attr, &size);
+ pthread_attr_destroy(&attr);
+ }
+#elif defined(HAVE_GETRLIMIT)
struct rlimit rlim;
-
if (getrlimit(RLIMIT_STACK, &rlim) == 0) {
- size_t space = (size_t)(rlim.rlim_cur/5);
-
- if (space > 1024*1024) space = 1024*1024;
- native_main_thread.stack_maxsize = (size_t)rlim.rlim_cur - space;
+ size = (size_t)rlim.rlim_cur;
}
- }
#endif
+ space = size > 5 * 1024 * 1024 ? 1024 * 1024 : size / 5;
+ native_main_thread.stack_maxsize = size - space;
+ }
}
#define CHECK_ERR(expr) \