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

Side by Side Diff: base/threading/thread.h

Issue 1207823004: PlatformThreadHandle: remove public id() interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [rebase and try] Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef BASE_THREADING_THREAD_H_ 5 #ifndef BASE_THREADING_THREAD_H_
6 #define BASE_THREADING_THREAD_H_ 6 #define BASE_THREADING_THREAD_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 scoped_refptr<SingleThreadTaskRunner> task_runner() const { 163 scoped_refptr<SingleThreadTaskRunner> task_runner() const {
164 return message_loop_ ? message_loop_->task_runner() : nullptr; 164 return message_loop_ ? message_loop_->task_runner() : nullptr;
165 } 165 }
166 166
167 // Returns the name of this thread (for display in debugger too). 167 // Returns the name of this thread (for display in debugger too).
168 const std::string& thread_name() const { return name_; } 168 const std::string& thread_name() const { return name_; }
169 169
170 // The native thread handle. 170 // The native thread handle.
171 PlatformThreadHandle thread_handle() { return thread_; } 171 PlatformThreadHandle thread_handle() { return thread_; }
172 172
173 // The thread ID. 173 // The thread ID. Only valid after this Thread was started.
174 PlatformThreadId thread_id() const; 174 PlatformThreadId thread_id() const;
175 175
176 // Returns true if the thread has been started, and not yet stopped. 176 // Returns true if the thread has been started, and not yet stopped.
177 bool IsRunning() const; 177 bool IsRunning() const;
178 178
179 protected: 179 protected:
180 // Called just prior to starting the message loop 180 // Called just prior to starting the message loop
181 virtual void Init() {} 181 virtual void Init() {}
182 182
183 // Called to start the message loop 183 // Called to start the message loop
(...skipping 21 matching lines...) Expand all
205 // PlatformThread::Delegate methods: 205 // PlatformThread::Delegate methods:
206 void ThreadMain() override; 206 void ThreadMain() override;
207 207
208 #if defined(OS_WIN) 208 #if defined(OS_WIN)
209 // Whether this thread needs to initialize COM, and if so, in what mode. 209 // Whether this thread needs to initialize COM, and if so, in what mode.
210 ComStatus com_status_; 210 ComStatus com_status_;
211 #endif 211 #endif
212 212
213 // If true, we're in the middle of stopping, and shouldn't access 213 // If true, we're in the middle of stopping, and shouldn't access
214 // |message_loop_|. It may non-NULL and invalid. 214 // |message_loop_|. It may non-NULL and invalid.
215 // Should be written on the thread that creates this thread. Also read data
216 // could be wrong on other threads.
215 bool stopping_; 217 bool stopping_;
216 218
217 // True while inside of Run(). 219 // True while inside of Run().
218 bool running_; 220 bool running_;
219 mutable base::Lock running_lock_; // Protects running_.
220 221
221 // The thread's handle. 222 // The thread's handle.
222 PlatformThreadHandle thread_; 223 PlatformThreadHandle thread_;
223 mutable base::Lock thread_lock_; // Protects thread_. 224
225 // The thread's id once it was started.
226 PlatformThreadId id_;
227
228 // Protects |running_|, |thread_|, and |id_|.
kinuko 2015/07/16 00:50:37 nit: This no longer protects thread_? nit: Unless
Takashi Toyoshima 2015/07/16 05:07:31 Ah, good catch. It's true from the last patch set.
Takashi Toyoshima 2015/07/16 08:12:38 So one reason to use a separate lock for id_ is th
229 mutable base::Lock lock_;
224 230
225 // The thread's message loop. Valid only while the thread is alive. Set 231 // The thread's message loop. Valid only while the thread is alive. Set
226 // by the created thread. 232 // by the created thread.
227 MessageLoop* message_loop_; 233 MessageLoop* message_loop_;
228 234
229 // Stores Options::timer_slack_ until the message loop has been bound to 235 // Stores Options::timer_slack_ until the message loop has been bound to
230 // a thread. 236 // a thread.
231 TimerSlack message_loop_timer_slack_; 237 TimerSlack message_loop_timer_slack_;
232 238
233 // The name of the thread. Used for debugging purposes. 239 // The name of the thread. Used for debugging purposes.
234 std::string name_; 240 std::string name_;
235 241
236 // Non-null if the thread has successfully started. 242 // Non-null if the thread has successfully started.
237 scoped_ptr<WaitableEvent> start_event_; 243 scoped_ptr<WaitableEvent> start_event_;
238 244
239 friend void ThreadQuitHelper(); 245 friend void ThreadQuitHelper();
240 246
241 DISALLOW_COPY_AND_ASSIGN(Thread); 247 DISALLOW_COPY_AND_ASSIGN(Thread);
242 }; 248 };
243 249
244 } // namespace base 250 } // namespace base
245 251
246 #endif // BASE_THREADING_THREAD_H_ 252 #endif // BASE_THREADING_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698