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

Side by Side 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: comment on nullptr 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 unified diff | Download patch
« no previous file with comments | « base/threading/platform_thread_win.cc ('k') | base/threading/thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // MessageLoop::Type to TYPE_CUSTOM. 67 // MessageLoop::Type to TYPE_CUSTOM.
68 MessagePumpFactory message_pump_factory; 68 MessagePumpFactory message_pump_factory;
69 69
70 // Specifies the maximum stack size that the thread is allowed to use. 70 // Specifies the maximum stack size that the thread is allowed to use.
71 // This does not necessarily correspond to the thread's initial stack size. 71 // This does not necessarily correspond to the thread's initial stack size.
72 // A value of 0 indicates that the default maximum should be used. 72 // A value of 0 indicates that the default maximum should be used.
73 size_t stack_size = 0; 73 size_t stack_size = 0;
74 74
75 // Specifies the initial thread priority. 75 // Specifies the initial thread priority.
76 ThreadPriority priority = ThreadPriority::NORMAL; 76 ThreadPriority priority = ThreadPriority::NORMAL;
77
78 // If false, the thread will not be joined on destruction. This is intended
79 // for threads that want TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN
80 // semantics. Stop() will not be synchronous and will instead merely have
81 // StopSoon() semantics on such threads.
82 bool joinable = true;
77 }; 83 };
78 84
79 // Constructor. 85 // Constructor.
80 // name is a display string to identify the thread. 86 // name is a display string to identify the thread.
81 explicit Thread(const std::string& name); 87 explicit Thread(const std::string& name);
82 88
83 // Destroys the thread, stopping it if necessary. 89 // Destroys the thread, stopping it if necessary.
84 // 90 //
85 // NOTE: ALL SUBCLASSES OF Thread MUST CALL Stop() IN THEIR DESTRUCTORS (or 91 // NOTE: ALL SUBCLASSES OF Thread MUST CALL Stop() IN THEIR DESTRUCTORS (or
86 // guarantee Stop() is explicitly called before the subclass is destroyed). 92 // guarantee Stop() is explicitly called before the subclass is destroyed).
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // WaitUntilThreadStarted(). 130 // WaitUntilThreadStarted().
125 // Note that using this (instead of Start() or StartWithOptions() causes 131 // Note that using this (instead of Start() or StartWithOptions() causes
126 // jank on the calling thread, should be used only in testing code. 132 // jank on the calling thread, should be used only in testing code.
127 bool StartAndWaitForTesting(); 133 bool StartAndWaitForTesting();
128 134
129 // Blocks until the thread starts running. Called within StartAndWait(). 135 // Blocks until the thread starts running. Called within StartAndWait().
130 // Note that calling this causes jank on the calling thread, must be used 136 // Note that calling this causes jank on the calling thread, must be used
131 // carefully for production code. 137 // carefully for production code.
132 bool WaitUntilThreadStarted() const; 138 bool WaitUntilThreadStarted() const;
133 139
134 // Signals the thread to exit and returns once the thread has exited. After 140 // Signals the thread to exit and returns once the thread has exited (or right
135 // this method returns, the Thread object is completely reset and may be used 141 // away if the thread is non-joinable). For joinable threads only: after this
136 // as if it were newly constructed (i.e., Start may be called again). 142 // method returns, the Thread object is completely reset and may be used as if
143 // it were newly constructed (i.e., Start may be called again) -- non-joinable
144 // threads are not re-usable.
danakj 2016/07/25 18:32:53 Is there some DCHECK that will fire if you try to
gab 2016/07/25 19:18:29 Yes, stopping_ is never reset when not joining (re
137 // 145 //
138 // Stop may be called multiple times and is simply ignored if the thread is 146 // Stop may be called multiple times and is simply ignored if the thread is
139 // already stopped. 147 // already stopped or currently stopping.
140 // 148 //
141 // NOTE: If you are a consumer of Thread, it is not necessary to call this 149 // NOTE: If you are a consumer of Thread, it is not necessary to call this
142 // before deleting your Thread objects, as the destructor will do it. 150 // before deleting your Thread objects, as the destructor will do it.
143 // IF YOU ARE A SUBCLASS OF Thread, YOU MUST CALL THIS IN YOUR DESTRUCTOR. 151 // IF YOU ARE A SUBCLASS OF Thread, YOU MUST CALL THIS IN YOUR DESTRUCTOR.
144 void Stop(); 152 void Stop();
145 153
146 // Signals the thread to exit in the near future. 154 // Signals the thread to exit in the near future.
147 // 155 //
148 // WARNING: This function is not meant to be commonly used. Use at your own 156 // WARNING: This function is not meant to be commonly used. Use at your own
149 // risk. Calling this function will cause message_loop() to become invalid in 157 // risk. Calling this function will cause message_loop() to become invalid in
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // This class is not thread-safe, use this to verify access from the owning 296 // This class is not thread-safe, use this to verify access from the owning
289 // sequence of the Thread. 297 // sequence of the Thread.
290 SequenceChecker owning_sequence_checker_; 298 SequenceChecker owning_sequence_checker_;
291 299
292 DISALLOW_COPY_AND_ASSIGN(Thread); 300 DISALLOW_COPY_AND_ASSIGN(Thread);
293 }; 301 };
294 302
295 } // namespace base 303 } // namespace base
296 304
297 #endif // BASE_THREADING_THREAD_H_ 305 #endif // BASE_THREADING_THREAD_H_
OLDNEW
« no previous file with comments | « base/threading/platform_thread_win.cc ('k') | base/threading/thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698