diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-05 23:23:59 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-05 23:23:59 +0000 |
commit | 7bb813b123af8c00374b97c738712cd3629644ec (patch) | |
tree | c21de2bd74dbbfe50c11fa19d4d9f9f82c1297d1 /base/platform_thread_posix.cc | |
parent | c915560f44ab7a7a9dce6fef15cb16eea736cffa (diff) | |
download | chromium_src-7bb813b123af8c00374b97c738712cd3629644ec.zip chromium_src-7bb813b123af8c00374b97c738712cd3629644ec.tar.gz chromium_src-7bb813b123af8c00374b97c738712cd3629644ec.tar.bz2 |
Added a new method CreateNonJoinable() to PlatformThread. Added the windows and posix implementations.
Review URL: http://codereview.chromium.org/40133
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11053 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/platform_thread_posix.cc')
-rw-r--r-- | base/platform_thread_posix.cc | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/base/platform_thread_posix.cc b/base/platform_thread_posix.cc index 4cd56d9..3789715 100644 --- a/base/platform_thread_posix.cc +++ b/base/platform_thread_posix.cc @@ -68,9 +68,11 @@ void PlatformThread::SetName(const char* name) { // structure would be useful for debugging or not. } -// static -bool PlatformThread::Create(size_t stack_size, Delegate* delegate, - PlatformThreadHandle* thread_handle) { +namespace { + +bool CreateThread(size_t stack_size, bool joinable, + PlatformThread::Delegate* delegate, + PlatformThreadHandle* thread_handle) { #if defined(OS_MACOSX) base::InitThreading(); #endif // OS_MACOSX @@ -79,8 +81,11 @@ bool PlatformThread::Create(size_t stack_size, Delegate* delegate, pthread_attr_t attributes; pthread_attr_init(&attributes); - // Pthreads are joinable by default, so we don't need to specify any special - // attributes to be able to call pthread_join later. + // Pthreads are joinable by default, so only specify the detached attribute if + // the thread should be non-joinable. + if (!joinable) { + pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_DETACHED); + } if (stack_size > 0) pthread_attr_setstacksize(&attributes, stack_size); @@ -91,6 +96,24 @@ bool PlatformThread::Create(size_t stack_size, Delegate* delegate, return success; } +} // anonymous namespace + +// static +bool PlatformThread::Create(size_t stack_size, Delegate* delegate, + PlatformThreadHandle* thread_handle) { + return CreateThread(stack_size, true /* joinable thread */, + delegate, thread_handle); +} + +// static +bool PlatformThread::CreateNonJoinable(size_t stack_size, Delegate* delegate) { + PlatformThreadHandle unused; + + bool result = CreateThread(stack_size, false /* non-joinable thread */, + delegate, &unused); + return result; +} + // static void PlatformThread::Join(PlatformThreadHandle thread_handle) { pthread_join(thread_handle, NULL); |