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

Unified Diff: base/threading/simple_thread.cc

Issue 2204333003: Add joinable option to SimpleThread::Options as was just done for Thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b1_nonjoinable_thread
Patch Set: Created 4 years, 4 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
Index: base/threading/simple_thread.cc
diff --git a/base/threading/simple_thread.cc b/base/threading/simple_thread.cc
index 6c64a17d6ab2fea1ec792715ad4697adcc21bd94..0f6f08c30dbc7f7a5b7d4630898a8cb5cd89ac37 100644
--- a/base/threading/simple_thread.cc
+++ b/base/threading/simple_thread.cc
@@ -12,39 +12,29 @@
namespace base {
SimpleThread::SimpleThread(const std::string& name_prefix)
- : name_prefix_(name_prefix),
- name_(name_prefix),
- thread_(),
- event_(WaitableEvent::ResetPolicy::MANUAL,
- WaitableEvent::InitialState::NOT_SIGNALED),
- tid_(0),
- joined_(false) {}
+ : SimpleThread(name_prefix, Options()) {}
SimpleThread::SimpleThread(const std::string& name_prefix,
const Options& options)
: name_prefix_(name_prefix),
name_(name_prefix),
options_(options),
- thread_(),
event_(WaitableEvent::ResetPolicy::MANUAL,
- WaitableEvent::InitialState::NOT_SIGNALED),
- tid_(0),
- joined_(false) {}
+ WaitableEvent::InitialState::NOT_SIGNALED) {}
SimpleThread::~SimpleThread() {
DCHECK(HasBeenStarted()) << "SimpleThread was never started.";
- DCHECK(HasBeenJoined()) << "SimpleThread destroyed without being Join()ed.";
+ DCHECK(thread_.is_null()) << "Joinable SimpleThread destroyed without being "
+ << "Join()ed.";
}
void SimpleThread::Start() {
DCHECK(!HasBeenStarted()) << "Tried to Start a thread multiple times.";
- bool success;
- if (options_.priority() == ThreadPriority::NORMAL) {
- success = PlatformThread::Create(options_.stack_size(), this, &thread_);
- } else {
- success = 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);
DCHECK(success);
base::ThreadRestrictions::ScopedAllowWait allow_wait;
event_.Wait(); // Wait for the thread to complete initialization.
@@ -52,8 +42,10 @@ void SimpleThread::Start() {
void SimpleThread::Join() {
DCHECK(HasBeenStarted()) << "Tried to Join a never-started thread.";
+ DCHECK(!thread_.is_null()) << "A non-joinable thread can't be joined.";
Lei Zhang 2016/08/03 23:24:11 Put this before or after the HasBeen twins?
gab 2016/08/04 14:35:00 Done.
DCHECK(!HasBeenJoined()) << "Tried to Join a thread multiple times.";
PlatformThread::Join(thread_);
+ thread_ = PlatformThreadHandle();
joined_ = true;
}

Powered by Google App Engine
This is Rietveld 408576698