diff options
Diffstat (limited to 'util/message_server_port.cpp')
-rw-r--r-- | util/message_server_port.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/util/message_server_port.cpp b/util/message_server_port.cpp index 76bd78d..409b0c7 100644 --- a/util/message_server_port.cpp +++ b/util/message_server_port.cpp @@ -26,6 +26,10 @@ #include "../db/lasterror.h" #include "../db/stats/counters.h" +#ifdef __linux__ +# include <sys/resource.h> +#endif + namespace mongo { namespace pms { @@ -105,7 +109,36 @@ namespace mongo { } try { +#ifndef __linux__ // TODO: consider making this ifdef _WIN32 boost::thread thr( boost::bind( &pms::threadRun , p ) ); +#else + pthread_attr_t attrs; + pthread_attr_init(&attrs); + pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED); + + static const size_t STACK_SIZE = 4*1024*1024; + + struct rlimit limits; + assert(getrlimit(RLIMIT_STACK, &limits) == 0); + if (limits.rlim_cur > STACK_SIZE) { + pthread_attr_setstacksize(&attrs, (DEBUG_BUILD + ? (STACK_SIZE / 2) + : STACK_SIZE)); + } + else if (limits.rlim_cur < 1024*1024) { + warning() << "Stack size set to " << (limits.rlim_cur/1024) << "KB. We suggest at least 1MB" << endl; + } + + pthread_t thread; + int failed = pthread_create(&thread, &attrs, (void*(*)(void*)) &pms::threadRun, p); + + pthread_attr_destroy(&attrs); + + if (failed) { + log() << "pthread_create failed: " << errnoWithDescription(failed) << endl; + throw boost::thread_resource_error(); // for consistency with boost::thread + } +#endif } catch ( boost::thread_resource_error& ) { connTicketHolder.release(); |