summaryrefslogtreecommitdiffstats
path: root/base/platform_thread_posix.cc
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-19 20:34:18 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-19 20:34:18 +0000
commit359d2bf31d2edc43a9ca8b08ee07707038efce09 (patch)
tree10bf00aa3964c73a37bae063a349bd496010ed4b /base/platform_thread_posix.cc
parent1da05ebbe6301142de46ef7cb100b6cc5aaa38c2 (diff)
downloadchromium_src-359d2bf31d2edc43a9ca8b08ee07707038efce09.zip
chromium_src-359d2bf31d2edc43a9ca8b08ee07707038efce09.tar.gz
chromium_src-359d2bf31d2edc43a9ca8b08ee07707038efce09.tar.bz2
Reland 66791 (change was innocent)
Revert 66719 - Reland r65996. Disallows Singletons on non-joinable thread. Test breakages caused by this change have been fixed here or in other changelists. BUG=61753 TEST=none Review URL: http://codereview.chromium.org/5024003 TBR=willchan@chromium.org Review URL: http://codereview.chromium.org/5206005 TBR=willchan@chromium.org Review URL: http://codereview.chromium.org/5242002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66808 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/platform_thread_posix.cc')
-rw-r--r--base/platform_thread_posix.cc33
1 files changed, 26 insertions, 7 deletions
diff --git a/base/platform_thread_posix.cc b/base/platform_thread_posix.cc
index 66f3928..e442e9c 100644
--- a/base/platform_thread_posix.cc
+++ b/base/platform_thread_posix.cc
@@ -7,6 +7,11 @@
#include <errno.h>
#include <sched.h>
+#include "base/logging.h"
+#include "base/safe_strerror_posix.h"
+#include "base/scoped_ptr.h"
+#include "base/thread_restrictions.h"
+
#if defined(OS_MACOSX)
#include <mach/mach.h>
#include <sys/resource.h>
@@ -24,18 +29,27 @@
#include <sys/nacl_syscalls.h>
#endif
-#include "base/logging.h"
-#include "base/safe_strerror_posix.h"
-
#if defined(OS_MACOSX)
namespace base {
void InitThreading();
} // namespace base
#endif
-static void* ThreadFunc(void* closure) {
- PlatformThread::Delegate* delegate =
- static_cast<PlatformThread::Delegate*>(closure);
+namespace {
+
+struct ThreadParams {
+ PlatformThread::Delegate* delegate;
+ bool joinable;
+};
+
+} // namespace
+
+static void* ThreadFunc(void* params) {
+ ThreadParams* thread_params = static_cast<ThreadParams*>(params);
+ PlatformThread::Delegate* delegate = thread_params->delegate;
+ if (!thread_params->joinable)
+ base::ThreadRestrictions::SetSingletonAllowed(false);
+ delete thread_params;
delegate->ThreadMain();
return NULL;
}
@@ -174,9 +188,14 @@ bool CreateThread(size_t stack_size, bool joinable,
if (stack_size > 0)
pthread_attr_setstacksize(&attributes, stack_size);
- success = !pthread_create(thread_handle, &attributes, ThreadFunc, delegate);
+ ThreadParams* params = new ThreadParams;
+ params->delegate = delegate;
+ params->joinable = joinable;
+ success = !pthread_create(thread_handle, &attributes, ThreadFunc, params);
pthread_attr_destroy(&attributes);
+ if (!success)
+ delete params;
return success;
}