diff options
-rw-r--r-- | cpp/include/IceUtil/Thread.h | 2 | ||||
-rw-r--r-- | cpp/src/IceUtil/Thread.cpp | 40 |
2 files changed, 34 insertions, 8 deletions
diff --git a/cpp/include/IceUtil/Thread.h b/cpp/include/IceUtil/Thread.h index d0a4a56193b..f13965a56f1 100644 --- a/cpp/include/IceUtil/Thread.h +++ b/cpp/include/IceUtil/Thread.h @@ -124,7 +124,7 @@ public: virtual void run() = 0; - ThreadControl start(); + ThreadControl start(size_t = 0); ThreadControl getThreadControl() const; diff --git a/cpp/src/IceUtil/Thread.cpp b/cpp/src/IceUtil/Thread.cpp index 1e3e32c0bb0..5011bfa5a7e 100644 --- a/cpp/src/IceUtil/Thread.cpp +++ b/cpp/src/IceUtil/Thread.cpp @@ -213,7 +213,7 @@ startHook(void* arg) #include <process.h> IceUtil::ThreadControl -IceUtil::Thread::start() +IceUtil::Thread::start(size_t stackSize) { // // Keep this alive for the duration of start @@ -238,7 +238,7 @@ IceUtil::Thread::start() // __incRef(); - _handle->handle = (HANDLE)_beginthreadex(0, 0, (unsigned int (__stdcall*)(void*))startHook, (LPVOID)this, 0, &_id); + _handle->handle = (HANDLE)_beginthreadex(0, stack_size, (unsigned int (__stdcall*)(void*))startHook, (LPVOID)this, 0, &_id); if(_handle->handle == 0) { __decRef(); @@ -499,7 +499,7 @@ startHook(void* arg) } IceUtil::ThreadControl -IceUtil::Thread::start() +IceUtil::Thread::start(size_t stackSize) { // // Keep this alive for the duration of start @@ -523,11 +523,37 @@ IceUtil::Thread::start() // __decRef(). // __incRef(); - int rc = pthread_create(&_id, 0, startHook, this); - if(rc != 0) + + if(stackSize > 0) { - __decRef(); - throw ThreadSyscallException(__FILE__, __LINE__, rc); + pthread_attr_t attr; + int rc = pthread_attr_init(&attr); + if(rc != 0) + { + __decRef(); + throw ThreadSyscallException(__FILE__, __LINE__, rc); + } + rc = pthread_attr_setstacksize(&attr, stackSize); + if(rc != 0) + { + __decRef(); + throw ThreadSyscallException(__FILE__, __LINE__, rc); + } + rc = pthread_create(&_id, &attr, startHook, this); + if(rc != 0) + { + __decRef(); + throw ThreadSyscallException(__FILE__, __LINE__, rc); + } + } + else + { + int rc = pthread_create(&_id, 0, startHook, this); + if(rc != 0) + { + __decRef(); + throw ThreadSyscallException(__FILE__, __LINE__, rc); + } } _started = true; |