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

Unified Diff: base/threading/thread.cc

Issue 2135413003: Add |joinable| to Thread::Options (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile Created 4 years, 5 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/threading/thread.h ('k') | base/threading/thread_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/thread.cc
diff --git a/base/threading/thread.cc b/base/threading/thread.cc
index 98610a63c09875878ffceca6417d7af16980ca89..df8f661bc19e50f7d71a3c8fdc0e54351f1f3260 100644
--- a/base/threading/thread.cc
+++ b/base/threading/thread.cc
@@ -28,7 +28,7 @@ namespace {
// because its Stop method was called. This allows us to catch cases where
// MessageLoop::QuitWhenIdle() is called directly, which is unexpected when
// using a Thread to setup and run a MessageLoop.
-base::LazyInstance<base::ThreadLocalBoolean> lazy_tls_bool =
+base::LazyInstance<base::ThreadLocalBoolean>::Leaky lazy_tls_bool =
LAZY_INSTANCE_INITIALIZER;
} // namespace
@@ -74,6 +74,8 @@ bool Thread::StartWithOptions(const Options& options) {
DCHECK(owning_sequence_checker_.CalledOnValidSequencedThread());
DCHECK(!message_loop_);
DCHECK(!IsRunning());
+ DCHECK(!stopping_) << "Starting a non-joinable thread a second time? That's "
+ << "not allowed!";
#if defined(OS_WIN)
DCHECK((com_status_ != STA) ||
(options.message_loop_type == MessageLoop::TYPE_UI));
@@ -100,8 +102,13 @@ bool Thread::StartWithOptions(const Options& options) {
// fixed).
{
AutoLock lock(thread_lock_);
- if (!PlatformThread::CreateWithPriority(options.stack_size, this, &thread_,
- options.priority)) {
+ bool success =
+ options.joinable
+ ? PlatformThread::CreateWithPriority(options.stack_size, this,
+ &thread_, options.priority)
+ : PlatformThread::CreateNonJoinableWithPriority(
+ options.stack_size, this, options.priority);
+ if (!success) {
DLOG(ERROR) << "failed to create thread";
message_loop_ = nullptr;
return false;
@@ -141,11 +148,12 @@ void Thread::Stop() {
// DCHECK(owning_sequence_checker_.CalledOnValidSequencedThread());
AutoLock lock(thread_lock_);
+ StopSoon();
gab 2016/07/25 21:09:00 Note: this is causing try job failures in unittest
+
+ // Can't join if the |thread_| is either already gone or is non-joinable.
if (thread_.is_null())
return;
- StopSoon();
-
// Wait for the thread to exit.
//
// TODO(darin): Unfortunately, we need to keep |message_loop_| around until
« no previous file with comments | « base/threading/thread.h ('k') | base/threading/thread_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698