| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // Subclasses should override the Run method. | 91 // Subclasses should override the Run method. |
| 92 virtual void Run() = 0; | 92 virtual void Run() = 0; |
| 93 | 93 |
| 94 // Return the thread name prefix, or "unnamed" if none was supplied. | 94 // Return the thread name prefix, or "unnamed" if none was supplied. |
| 95 std::string name_prefix() { return name_prefix_; } | 95 std::string name_prefix() { return name_prefix_; } |
| 96 | 96 |
| 97 // Return the completed name including TID, only valid after Start(). | 97 // Return the completed name including TID, only valid after Start(). |
| 98 std::string name() { return name_; } | 98 std::string name() { return name_; } |
| 99 | 99 |
| 100 // Return the thread id, only valid after Start(). | 100 // Return the thread id, only valid after Start(). |
| 101 int tid() { return tid_; } | 101 PlatformThreadId tid() { return tid_; } |
| 102 | 102 |
| 103 // Return True if Start() has ever been called. | 103 // Return True if Start() has ever been called. |
| 104 bool HasBeenStarted() { return event_.IsSignaled(); } | 104 bool HasBeenStarted() { return event_.IsSignaled(); } |
| 105 | 105 |
| 106 // Return True if Join() has evern been called. | 106 // Return True if Join() has evern been called. |
| 107 bool HasBeenJoined() { return joined_; } | 107 bool HasBeenJoined() { return joined_; } |
| 108 | 108 |
| 109 private: | 109 private: |
| 110 const std::string name_prefix_; | 110 const std::string name_prefix_; |
| 111 std::string name_; | 111 std::string name_; |
| 112 const Options options_; | 112 const Options options_; |
| 113 PlatformThreadHandle thread_; // PlatformThread handle, invalid after Join! | 113 PlatformThreadHandle thread_; // PlatformThread handle, invalid after Join! |
| 114 WaitableEvent event_; // Signaled if Start() was ever called. | 114 WaitableEvent event_; // Signaled if Start() was ever called. |
| 115 int tid_; // The backing thread's id. | 115 PlatformThreadId tid_; // The backing thread's id. |
| 116 bool joined_; // True if Join has been called. | 116 bool joined_; // True if Join has been called. |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 class DelegateSimpleThread : public SimpleThread { | 119 class DelegateSimpleThread : public SimpleThread { |
| 120 public: | 120 public: |
| 121 class Delegate { | 121 class Delegate { |
| 122 public: | 122 public: |
| 123 Delegate() { } | 123 Delegate() { } |
| 124 virtual ~Delegate() { } | 124 virtual ~Delegate() { } |
| 125 virtual void Run() = 0; | 125 virtual void Run() = 0; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 int num_threads_; | 180 int num_threads_; |
| 181 std::vector<DelegateSimpleThread*> threads_; | 181 std::vector<DelegateSimpleThread*> threads_; |
| 182 std::queue<Delegate*> delegates_; | 182 std::queue<Delegate*> delegates_; |
| 183 Lock lock_; // Locks delegates_ | 183 Lock lock_; // Locks delegates_ |
| 184 WaitableEvent dry_; // Not signaled when there is no work to do. | 184 WaitableEvent dry_; // Not signaled when there is no work to do. |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 } // namespace base | 187 } // namespace base |
| 188 | 188 |
| 189 #endif // BASE_SIMPLE_THREAD_H_ | 189 #endif // BASE_SIMPLE_THREAD_H_ |
| OLD | NEW |