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

Unified Diff: base/threading/simple_thread.h

Issue 2685533003: Revert of Do not block in SimpleThread::Start(). (Closed)
Patch Set: 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 3efce1636a1a813d39e5c61bab874edf4de30c09..f9f5e9104595cff04d97730fc17860a971edd0a4 100644
--- a/base/threading/simple_thread.h
+++ b/base/threading/simple_thread.h
@@ -30,8 +30,9 @@
// MyThreadRunner runner;
// DelegateSimpleThread thread(&runner, "good_name_here");
// thread.Start();
-// // The newly created thread will invoke runner->Run(), and run until it
-// // returns.
+// // 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.
// 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.
@@ -47,7 +48,6 @@
#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,8 +96,14 @@
// Subclasses should override the Run method.
virtual void Run() = 0;
- // Return the thread id.
- PlatformThreadId GetTid() const;
+ // 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_; }
// Overridden from PlatformThread::Delegate:
void ThreadMain() override;
@@ -106,20 +112,10 @@
const std::string name_prefix_;
std::string name_;
const Options options_;
-
- // 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
+ 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.
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