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

Unified Diff: base/threading/simple_thread.h

Issue 2664953004: Do not block in SimpleThread::Start(). (Closed)
Patch Set: CR gab #26 (comment) Created 3 years, 10 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
« no previous file with comments | « base/threading/sequenced_worker_pool.cc ('k') | base/threading/simple_thread.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/simple_thread.h
diff --git a/base/threading/simple_thread.h b/base/threading/simple_thread.h
index f9f5e9104595cff04d97730fc17860a971edd0a4..3efce1636a1a813d39e5c61bab874edf4de30c09 100644
--- a/base/threading/simple_thread.h
+++ b/base/threading/simple_thread.h
@@ -30,9 +30,8 @@
// MyThreadRunner runner;
// DelegateSimpleThread thread(&runner, "good_name_here");
// thread.Start();
-// // Start will return after the Thread has been successfully started and
-// // initialized. The newly created thread will invoke runner->Run(), and
-// // run until it returns.
+// // The newly created thread will invoke runner->Run(), and run until it
+// // returns.
// thread.Join(); // Wait until the thread has exited. You *MUST* Join!
// // The SimpleThread object is still valid, however you may not call Join
// // or Start again.
@@ -48,6 +47,7 @@
#include "base/base_export.h"
#include "base/compiler_specific.h"
+#include "base/logging.h"
#include "base/macros.h"
#include "base/synchronization/lock.h"
#include "base/synchronization/waitable_event.h"
@@ -96,14 +96,8 @@ class BASE_EXPORT SimpleThread : public PlatformThread::Delegate {
// Subclasses should override the Run method.
virtual void Run() = 0;
- // Return the thread id, only valid after Start().
- PlatformThreadId tid() { return tid_; }
-
- // Return True if Start() has ever been called.
- bool HasBeenStarted();
-
- // Return True if Join() has ever been called.
- bool HasBeenJoined() { return joined_; }
+ // Return the thread id.
+ PlatformThreadId GetTid() const;
// Overridden from PlatformThread::Delegate:
void ThreadMain() override;
@@ -112,10 +106,20 @@ class BASE_EXPORT SimpleThread : public PlatformThread::Delegate {
const std::string name_prefix_;
std::string name_;
const Options options_;
- PlatformThreadHandle thread_; // PlatformThread handle, reset after Join.
- WaitableEvent event_; // Signaled if Start() was ever called.
- PlatformThreadId tid_ = kInvalidThreadId; // The backing thread's id.
- bool joined_ = false; // True if Join has been called.
+
+ // PlatformThread handle, reset after Join.
+ PlatformThreadHandle thread_;
+
+ // Signaled once |tid_| is set.
+ mutable WaitableEvent id_event_;
+
+ // The backing thread's id.
+ PlatformThreadId tid_ = kInvalidThreadId;
+
+#if DCHECK_IS_ON()
+ bool has_been_started_ = false;
+ bool has_been_joined_ = false;
+#endif
DISALLOW_COPY_AND_ASSIGN(SimpleThread);
};
« no previous file with comments | « base/threading/sequenced_worker_pool.cc ('k') | base/threading/simple_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698