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

Side by Side Diff: base/threading/simple_thread.cc

Issue 2032603002: Migrate WaitableEvent to enum-based constructor in base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@WEvent_enums
Patch Set: undo incorrect template change Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/threading/simple_thread.h" 5 #include "base/threading/simple_thread.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
11 11
12 namespace base { 12 namespace base {
13 13
14 SimpleThread::SimpleThread(const std::string& name_prefix) 14 SimpleThread::SimpleThread(const std::string& name_prefix)
15 : name_prefix_(name_prefix), name_(name_prefix), 15 : name_prefix_(name_prefix),
16 thread_(), event_(true, false), tid_(0), joined_(false) { 16 name_(name_prefix),
17 } 17 thread_(),
18 event_(WaitableEvent::ResetPolicy::MANUAL,
19 WaitableEvent::InitialState::NOT_SIGNALED),
20 tid_(0),
21 joined_(false) {}
18 22
19 SimpleThread::SimpleThread(const std::string& name_prefix, 23 SimpleThread::SimpleThread(const std::string& name_prefix,
20 const Options& options) 24 const Options& options)
21 : name_prefix_(name_prefix), name_(name_prefix), options_(options), 25 : name_prefix_(name_prefix),
22 thread_(), event_(true, false), tid_(0), joined_(false) { 26 name_(name_prefix),
23 } 27 options_(options),
28 thread_(),
29 event_(WaitableEvent::ResetPolicy::MANUAL,
30 WaitableEvent::InitialState::NOT_SIGNALED),
31 tid_(0),
32 joined_(false) {}
24 33
25 SimpleThread::~SimpleThread() { 34 SimpleThread::~SimpleThread() {
26 DCHECK(HasBeenStarted()) << "SimpleThread was never started."; 35 DCHECK(HasBeenStarted()) << "SimpleThread was never started.";
27 DCHECK(HasBeenJoined()) << "SimpleThread destroyed without being Join()ed."; 36 DCHECK(HasBeenJoined()) << "SimpleThread destroyed without being Join()ed.";
28 } 37 }
29 38
30 void SimpleThread::Start() { 39 void SimpleThread::Start() {
31 DCHECK(!HasBeenStarted()) << "Tried to Start a thread multiple times."; 40 DCHECK(!HasBeenStarted()) << "Tried to Start a thread multiple times.";
32 bool success; 41 bool success;
33 if (options_.priority() == ThreadPriority::NORMAL) { 42 if (options_.priority() == ThreadPriority::NORMAL) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 DCHECK(delegate_) << "Tried to call Run without a delegate (called twice?)"; 95 DCHECK(delegate_) << "Tried to call Run without a delegate (called twice?)";
87 delegate_->Run(); 96 delegate_->Run();
88 delegate_ = NULL; 97 delegate_ = NULL;
89 } 98 }
90 99
91 DelegateSimpleThreadPool::DelegateSimpleThreadPool( 100 DelegateSimpleThreadPool::DelegateSimpleThreadPool(
92 const std::string& name_prefix, 101 const std::string& name_prefix,
93 int num_threads) 102 int num_threads)
94 : name_prefix_(name_prefix), 103 : name_prefix_(name_prefix),
95 num_threads_(num_threads), 104 num_threads_(num_threads),
96 dry_(true, false) { 105 dry_(WaitableEvent::ResetPolicy::MANUAL,
97 } 106 WaitableEvent::InitialState::NOT_SIGNALED) {}
98 107
99 DelegateSimpleThreadPool::~DelegateSimpleThreadPool() { 108 DelegateSimpleThreadPool::~DelegateSimpleThreadPool() {
100 DCHECK(threads_.empty()); 109 DCHECK(threads_.empty());
101 DCHECK(delegates_.empty()); 110 DCHECK(delegates_.empty());
102 DCHECK(!dry_.IsSignaled()); 111 DCHECK(!dry_.IsSignaled());
103 } 112 }
104 113
105 void DelegateSimpleThreadPool::Start() { 114 void DelegateSimpleThreadPool::Start() {
106 DCHECK(threads_.empty()) << "Start() called with outstanding threads."; 115 DCHECK(threads_.empty()) << "Start() called with outstanding threads.";
107 for (int i = 0; i < num_threads_; ++i) { 116 for (int i = 0; i < num_threads_; ++i) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 165
157 // A NULL delegate pointer signals us to quit. 166 // A NULL delegate pointer signals us to quit.
158 if (!work) 167 if (!work)
159 break; 168 break;
160 169
161 work->Run(); 170 work->Run();
162 } 171 }
163 } 172 }
164 173
165 } // namespace base 174 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/sequenced_worker_pool_unittest.cc ('k') | base/threading/simple_thread_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698