| Index: base/threading/simple_thread.cc
|
| diff --git a/base/threading/simple_thread.cc b/base/threading/simple_thread.cc
|
| index 6c64a17d6ab2fea1ec792715ad4697adcc21bd94..48eb56a7ae0b13e055a15e3f17a057677494654c 100644
|
| --- a/base/threading/simple_thread.cc
|
| +++ b/base/threading/simple_thread.cc
|
| @@ -12,53 +12,46 @@
|
| 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(!options_.joinable || HasBeenJoined())
|
| + << "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;
|
| + ThreadRestrictions::ScopedAllowWait allow_wait;
|
| event_.Wait(); // Wait for the thread to complete initialization.
|
| }
|
|
|
| void SimpleThread::Join() {
|
| + DCHECK(options_.joinable) << "A non-joinable thread can't be joined.";
|
| DCHECK(HasBeenStarted()) << "Tried to Join a never-started thread.";
|
| DCHECK(!HasBeenJoined()) << "Tried to Join a thread multiple times.";
|
| PlatformThread::Join(thread_);
|
| + thread_ = PlatformThreadHandle();
|
| joined_ = true;
|
| }
|
|
|
| bool SimpleThread::HasBeenStarted() {
|
| - base::ThreadRestrictions::ScopedAllowWait allow_wait;
|
| + ThreadRestrictions::ScopedAllowWait allow_wait;
|
| return event_.IsSignaled();
|
| }
|
|
|
| @@ -77,24 +70,22 @@ void SimpleThread::ThreadMain() {
|
|
|
| DelegateSimpleThread::DelegateSimpleThread(Delegate* delegate,
|
| const std::string& name_prefix)
|
| - : SimpleThread(name_prefix),
|
| - delegate_(delegate) {
|
| -}
|
| + : DelegateSimpleThread(delegate, name_prefix, Options()) {}
|
|
|
| DelegateSimpleThread::DelegateSimpleThread(Delegate* delegate,
|
| const std::string& name_prefix,
|
| const Options& options)
|
| : SimpleThread(name_prefix, options),
|
| delegate_(delegate) {
|
| + DCHECK(delegate_);
|
| }
|
|
|
| -DelegateSimpleThread::~DelegateSimpleThread() {
|
| -}
|
| +DelegateSimpleThread::~DelegateSimpleThread() = default;
|
|
|
| void DelegateSimpleThread::Run() {
|
| DCHECK(delegate_) << "Tried to call Run without a delegate (called twice?)";
|
| delegate_->Run();
|
| - delegate_ = NULL;
|
| + delegate_ = nullptr;
|
| }
|
|
|
| DelegateSimpleThreadPool::DelegateSimpleThreadPool(
|
|
|