Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: base/platform_thread_posix.cc

Issue 40133: Adding support for non joinable threads to PlatformThread (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/platform_thread.h ('k') | base/platform_thread_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/platform_thread_posix.cc
===================================================================
--- base/platform_thread_posix.cc (revision 11032)
+++ base/platform_thread_posix.cc (working copy)
@@ -68,9 +68,11 @@
// 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 @@
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,7 +96,25 @@
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);
}
« no previous file with comments | « base/platform_thread.h ('k') | base/platform_thread_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698