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

Side by Side Diff: base/simple_thread.cc

Issue 3522004: FBTF: Move ctors/dtors into implementation files. Adds ctors/dtors to non-POD structs. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 years, 2 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/simple_thread.h" 5 #include "base/simple_thread.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/platform_thread.h" 8 #include "base/platform_thread.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 10
(...skipping 19 matching lines...) Expand all
30 name_.push_back('/'); 30 name_.push_back('/');
31 name_.append(IntToString(tid_)); 31 name_.append(IntToString(tid_));
32 PlatformThread::SetName(name_.c_str()); 32 PlatformThread::SetName(name_.c_str());
33 33
34 // We've initialized our new thread, signal that we're done to Start(). 34 // We've initialized our new thread, signal that we're done to Start().
35 event_.Signal(); 35 event_.Signal();
36 36
37 Run(); 37 Run();
38 } 38 }
39 39
40 SimpleThread::SimpleThread(const std::string& name_prefix)
41 : name_prefix_(name_prefix), name_(name_prefix),
42 thread_(), event_(true, false), tid_(0), joined_(false) {
43 }
44
45 SimpleThread::SimpleThread(const std::string& name_prefix,
46 const Options& options)
47 : name_prefix_(name_prefix), name_(name_prefix), options_(options),
48 thread_(), event_(true, false), tid_(0), joined_(false) {
49 }
50
40 SimpleThread::~SimpleThread() { 51 SimpleThread::~SimpleThread() {
41 DCHECK(HasBeenStarted()) << "SimpleThread was never started."; 52 DCHECK(HasBeenStarted()) << "SimpleThread was never started.";
42 DCHECK(HasBeenJoined()) << "SimpleThread destroyed without being Join()ed."; 53 DCHECK(HasBeenJoined()) << "SimpleThread destroyed without being Join()ed.";
43 } 54 }
44 55
56 DelegateSimpleThread::DelegateSimpleThread(Delegate* delegate,
57 const std::string& name_prefix)
58 : SimpleThread(name_prefix),
59 delegate_(delegate) {
60 }
61
62 DelegateSimpleThread::DelegateSimpleThread(Delegate* delegate,
63 const std::string& name_prefix,
64 const Options& options)
65 : SimpleThread(name_prefix, options),
66 delegate_(delegate) {
67 }
68
69 DelegateSimpleThread::~DelegateSimpleThread() {
70 }
71
45 void DelegateSimpleThread::Run() { 72 void DelegateSimpleThread::Run() {
46 DCHECK(delegate_) << "Tried to call Run without a delegate (called twice?)"; 73 DCHECK(delegate_) << "Tried to call Run without a delegate (called twice?)";
47 delegate_->Run(); 74 delegate_->Run();
48 delegate_ = NULL; 75 delegate_ = NULL;
49 } 76 }
50 77
78 DelegateSimpleThreadPool::DelegateSimpleThreadPool(
79 const std::string& name_prefix,
80 int num_threads)
81 : name_prefix_(name_prefix),
82 num_threads_(num_threads),
83 dry_(true, false) {
84 }
85
51 DelegateSimpleThreadPool::~DelegateSimpleThreadPool() { 86 DelegateSimpleThreadPool::~DelegateSimpleThreadPool() {
52 DCHECK(threads_.empty()); 87 DCHECK(threads_.empty());
53 DCHECK(delegates_.empty()); 88 DCHECK(delegates_.empty());
54 DCHECK(!dry_.IsSignaled()); 89 DCHECK(!dry_.IsSignaled());
55 } 90 }
56 91
57 void DelegateSimpleThreadPool::Start() { 92 void DelegateSimpleThreadPool::Start() {
58 DCHECK(threads_.empty()) << "Start() called with outstanding threads."; 93 DCHECK(threads_.empty()) << "Start() called with outstanding threads.";
59 for (int i = 0; i < num_threads_; ++i) { 94 for (int i = 0; i < num_threads_; ++i) {
60 DelegateSimpleThread* thread = new DelegateSimpleThread(this, name_prefix_); 95 DelegateSimpleThread* thread = new DelegateSimpleThread(this, name_prefix_);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 143
109 // A NULL delegate pointer signals us to quit. 144 // A NULL delegate pointer signals us to quit.
110 if (!work) 145 if (!work)
111 break; 146 break;
112 147
113 work->Run(); 148 work->Run();
114 } 149 }
115 } 150 }
116 151
117 } // namespace base 152 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698