Index: base/threading/thread.h |
diff --git a/base/threading/thread.h b/base/threading/thread.h |
index 5010f0ec428bdcc69e54a9fdfe723862cacd75aa..976550fc938d0593dbef232ff254c91a6b153830 100644 |
--- a/base/threading/thread.h |
+++ b/base/threading/thread.h |
@@ -13,11 +13,13 @@ |
#include "base/message_loop/message_loop.h" |
#include "base/message_loop/message_loop_proxy.h" |
#include "base/message_loop/timer_slack.h" |
+#include "base/synchronization/lock.h" |
#include "base/threading/platform_thread.h" |
namespace base { |
class MessagePump; |
+class WaitableEvent; |
// A simple thread abstraction that establishes a MessageLoop on a new thread. |
// The consumer uses the MessageLoop of the thread to cause code to execute on |
@@ -45,7 +47,7 @@ class BASE_EXPORT Thread : PlatformThread::Delegate { |
// This is ignored if message_pump_factory.is_null() is false. |
MessageLoop::Type message_loop_type; |
- // Specify timer slack for thread message loop. |
+ // Specifies timer slack for thread message loop. |
TimerSlack timer_slack; |
// Used to create the MessagePump for the MessageLoop. The callback is Run() |
@@ -103,6 +105,16 @@ class BASE_EXPORT Thread : PlatformThread::Delegate { |
// callback. |
bool StartWithOptions(const Options& options); |
+ // Starts the thread and wait for the thread to start and run initialization |
+ // before returning. It's same as calling Start() and then |
+ // WaitUntilThreadStarted(). |
+ // Note that using this (instead of Start() or StartWithOptions() causes |
+ // jank on the calling thread, and must be used carefully for production code. |
+ bool StartAndWait(); |
+ |
+ // Blocks until the thread starts running. Supposed to be used for testing. |
+ bool WaitUntilThreadStarted(); |
+ |
// Signals the thread to exit and returns once the thread has exited. After |
// this method returns, the Thread object is completely reset and may be used |
// as if it were newly constructed (i.e., Start may be called again). |
@@ -203,6 +215,9 @@ class BASE_EXPORT Thread : PlatformThread::Delegate { |
// PlatformThread::Delegate methods: |
void ThreadMain() override; |
+ // Returns true while inside of Run(). |
+ bool IsInRunLoop() const; |
+ |
#if defined(OS_WIN) |
// Whether this thread needs to initialize COM, and if so, in what mode. |
ComStatus com_status_; |
@@ -216,12 +231,9 @@ class BASE_EXPORT Thread : PlatformThread::Delegate { |
bool stopping_; |
// True while inside of Run(). |
+ mutable base::Lock running_lock_; |
bool running_; |
- // Used to pass data to ThreadMain. |
- struct StartupData; |
- StartupData* startup_data_; |
- |
// The thread's handle. |
PlatformThreadHandle thread_; |
@@ -235,6 +247,8 @@ class BASE_EXPORT Thread : PlatformThread::Delegate { |
// The name of the thread. Used for debugging purposes. |
std::string name_; |
+ scoped_ptr<WaitableEvent> start_event_; |
+ |
friend void ThreadQuitHelper(); |
DISALLOW_COPY_AND_ASSIGN(Thread); |