diff options
author | nfullagar@chromium.org <nfullagar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-20 21:14:59 +0000 |
---|---|---|
committer | nfullagar@chromium.org <nfullagar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-20 21:14:59 +0000 |
commit | 86bd4e740dc1213dbb3fb2debb54acf10b23e7b3 (patch) | |
tree | bb89869fe446cbb3d0816b9b802cf9688de96b89 /ppapi | |
parent | 2eb12c294d86e05a47d0fbe08683b86da3bfa845 (diff) | |
download | chromium_src-86bd4e740dc1213dbb3fb2debb54acf10b23e7b3.zip chromium_src-86bd4e740dc1213dbb3fb2debb54acf10b23e7b3.tar.gz chromium_src-86bd4e740dc1213dbb3fb2debb54acf10b23e7b3.tar.bz2 |
Provide alternate constructor for specifying a simple thread's stacksize.
For Native Client builds, make default stack size 2MB regardless of
newlib or glibc.
TEST=try bots
BUG=none
Review URL: https://chromiumcodereview.appspot.com/12259018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183618 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/utility/threading/simple_thread.cc | 26 | ||||
-rw-r--r-- | ppapi/utility/threading/simple_thread.h | 4 |
2 files changed, 27 insertions, 3 deletions
diff --git a/ppapi/utility/threading/simple_thread.cc b/ppapi/utility/threading/simple_thread.cc index 783be38..02bf49b 100644 --- a/ppapi/utility/threading/simple_thread.cc +++ b/ppapi/utility/threading/simple_thread.cc @@ -12,6 +12,14 @@ namespace pp { namespace { +// Use 2MB default stack size for Native Client, otherwise use system default. +#if defined(__native_client__) +const size_t kDefaultStackSize = 2 * 1024 * 1024; +#else +const size_t kDefaultStackSize = 0; +#endif + + struct ThreadData { MessageLoop message_loop; @@ -41,6 +49,15 @@ void* RunThread(void* void_data) { SimpleThread::SimpleThread(const InstanceHandle& instance) : instance_(instance), message_loop_(instance), + stacksize_(kDefaultStackSize), + thread_(0) { +} + +SimpleThread::SimpleThread(const InstanceHandle& instance, + size_t stacksize) + : instance_(instance), + message_loop_(instance), + stacksize_(stacksize), thread_(0) { } @@ -82,10 +99,15 @@ bool SimpleThread::StartWithFunction(ThreadFunc func, void* user_data) { data->user_data = user_data; #ifdef WIN32 - thread_ = CreateThread(NULL, 0, &RunThread, data, 0, NULL); + thread_ = CreateThread(NULL, stacksize_, &RunThread, data, 0, NULL); if (!thread_) { #else - if (pthread_create(&thread_, NULL, &RunThread, data) != 0) { + pthread_attr_t attr; + pthread_attr_init(&attr); + int setval = 0; + if (stacksize_ > 0) + setval = pthread_attr_setstacksize(&attr, stacksize_); + if (setval != 0 || pthread_create(&thread_, &attr, &RunThread, data) != 0) { #endif delete data; return false; diff --git a/ppapi/utility/threading/simple_thread.h b/ppapi/utility/threading/simple_thread.h index b3ccd9b..5410cf8 100644 --- a/ppapi/utility/threading/simple_thread.h +++ b/ppapi/utility/threading/simple_thread.h @@ -29,6 +29,7 @@ class SimpleThread { typedef void (*ThreadFunc)(MessageLoop&, void* user_data); explicit SimpleThread(const InstanceHandle& instance); + explicit SimpleThread(const InstanceHandle& instance, size_t stacksize); ~SimpleThread(); // Starts a thread and runs a message loop in it. If you need control over @@ -52,11 +53,12 @@ class SimpleThread { private: InstanceHandle instance_; MessageLoop message_loop_; - + const size_t stacksize_; ThreadHandle thread_; // Disallow (not implemented). SimpleThread(const SimpleThread&); + SimpleThread(const SimpleThread&, size_t stacksize); SimpleThread& operator=(const SimpleThread&); }; |