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

Side by Side Diff: base/threading/simple_thread.h

Issue 1180693002: Update from https://crrev.com/333737 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 6 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/simple_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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // WARNING: You should probably be using Thread (thread.h) instead. Thread is 5 // WARNING: You should probably be using Thread (thread.h) instead. Thread is
6 // Chrome's message-loop based Thread abstraction, and if you are a 6 // Chrome's message-loop based Thread abstraction, and if you are a
7 // thread running in the browser, there will likely be assumptions 7 // thread running in the browser, there will likely be assumptions
8 // that your thread will have an associated message loop. 8 // that your thread will have an associated message loop.
9 // 9 //
10 // This is a simple thread interface that backs to a native operating system 10 // This is a simple thread interface that backs to a native operating system
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "base/synchronization/waitable_event.h" 52 #include "base/synchronization/waitable_event.h"
53 53
54 namespace base { 54 namespace base {
55 55
56 // This is the base SimpleThread. You can derive from it and implement the 56 // This is the base SimpleThread. You can derive from it and implement the
57 // virtual Run method, or you can use the DelegateSimpleThread interface. 57 // virtual Run method, or you can use the DelegateSimpleThread interface.
58 class BASE_EXPORT SimpleThread : public PlatformThread::Delegate { 58 class BASE_EXPORT SimpleThread : public PlatformThread::Delegate {
59 public: 59 public:
60 class BASE_EXPORT Options { 60 class BASE_EXPORT Options {
61 public: 61 public:
62 Options() : stack_size_(0) { } 62 Options() : stack_size_(0), priority_(ThreadPriority::NORMAL) { }
63 ~Options() { } 63 ~Options() { }
64 64
65 // We use the standard compiler-supplied copy constructor. 65 // We use the standard compiler-supplied copy constructor.
66 66
67 // A custom stack size, or 0 for the system default. 67 // A custom stack size, or 0 for the system default.
68 void set_stack_size(size_t size) { stack_size_ = size; } 68 void set_stack_size(size_t size) { stack_size_ = size; }
69 size_t stack_size() const { return stack_size_; } 69 size_t stack_size() const { return stack_size_; }
70
71 // A custom thread priority.
72 void set_priority(ThreadPriority priority) { priority_ = priority; }
73 ThreadPriority priority() const { return priority_; }
70 private: 74 private:
71 size_t stack_size_; 75 size_t stack_size_;
76 ThreadPriority priority_;
72 }; 77 };
73 78
74 // Create a SimpleThread. |options| should be used to manage any specific 79 // Create a SimpleThread. |options| should be used to manage any specific
75 // configuration involving the thread creation and management. 80 // configuration involving the thread creation and management.
76 // Every thread has a name, in the form of |name_prefix|/TID, for example 81 // Every thread has a name, in the form of |name_prefix|/TID, for example
77 // "my_thread/321". The thread will not be created until Start() is called. 82 // "my_thread/321". The thread will not be created until Start() is called.
78 explicit SimpleThread(const std::string& name_prefix); 83 explicit SimpleThread(const std::string& name_prefix);
79 SimpleThread(const std::string& name_prefix, const Options& options); 84 SimpleThread(const std::string& name_prefix, const Options& options);
80 85
81 ~SimpleThread() override; 86 ~SimpleThread() override;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 int num_threads_; 187 int num_threads_;
183 std::vector<DelegateSimpleThread*> threads_; 188 std::vector<DelegateSimpleThread*> threads_;
184 std::queue<Delegate*> delegates_; 189 std::queue<Delegate*> delegates_;
185 base::Lock lock_; // Locks delegates_ 190 base::Lock lock_; // Locks delegates_
186 WaitableEvent dry_; // Not signaled when there is no work to do. 191 WaitableEvent dry_; // Not signaled when there is no work to do.
187 }; 192 };
188 193
189 } // namespace base 194 } // namespace base
190 195
191 #endif // BASE_THREADING_SIMPLE_THREAD_H_ 196 #endif // BASE_THREADING_SIMPLE_THREAD_H_
OLDNEW
« no previous file with comments | « base/threading/platform_thread_win.cc ('k') | base/threading/simple_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698