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

Unified Diff: base/threading/thread.h

Issue 2135413003: Add |joinable| to Thread::Options (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Init() => InstallMessageLoop() -- Init was already used on Thread::... Created 4 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 side-by-side diff with in-line comments
Download patch
Index: base/threading/thread.h
diff --git a/base/threading/thread.h b/base/threading/thread.h
index 45064240d76f8436ceb7ab51ff205be4646a8485..221fe4e032e4229c1fe9adf58104e25db4883c5d 100644
--- a/base/threading/thread.h
+++ b/base/threading/thread.h
@@ -74,6 +74,12 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
// Specifies the initial thread priority.
ThreadPriority priority = ThreadPriority::NORMAL;
+
+ // If false, the thread will not be joined on destruction. This is intended
+ // for threads that want TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN
+ // semantics. Stop() will not be synchronous and will instead merely have
+ // StopSoon() semantics on such threads.
+ bool joinable = true;
};
// Constructor.
@@ -131,12 +137,14 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
// carefully for production code.
bool WaitUntilThreadStarted() const;
- // 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).
+ // Signals the thread to exit and returns once the thread has exited (or right
+ // away if the thread is non-joinable). For joinable threads only: 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) -- non-joinable
+ // threads are not re-usable.
//
// Stop may be called multiple times and is simply ignored if the thread is
- // already stopped.
+ // already stopped or currently stopping.
//
// NOTE: If you are a consumer of Thread, it is not necessary to call this
// before deleting your Thread objects, as the destructor will do it.
@@ -228,10 +236,8 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
static void SetThreadWasQuitProperly(bool flag);
static bool GetThreadWasQuitProperly();
- void set_message_loop(MessageLoop* message_loop) {
- DCHECK(owning_sequence_checker_.CalledOnValidSequencedThread());
- message_loop_ = message_loop;
- }
+ // Bind this Thread to an existing MessageLoop instead of starting a new one.
+ void SetMessageLoop(MessageLoop* message_loop);
private:
#if defined(OS_WIN)
@@ -275,6 +281,11 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
MessageLoop* message_loop_ = nullptr;
RunLoop* run_loop_ = nullptr;
+ // True only if |message_loop_| was externally provided by |SetMessageLoop()|
+ // in which case this Thread has no underlying |thread_| and should merely
+ // drop |message_loop_| on Stop().
+ bool using_external_message_loop_ = false;
+
// Stores Options::timer_slack_ until the message loop has been bound to
// a thread.
TimerSlack message_loop_timer_slack_ = TIMER_SLACK_NONE;

Powered by Google App Engine
This is Rietveld 408576698