OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 RTC_DISALLOW_COPY_AND_ASSIGN(ThreadManager); | 71 RTC_DISALLOW_COPY_AND_ASSIGN(ThreadManager); |
72 }; | 72 }; |
73 | 73 |
74 struct _SendMessage { | 74 struct _SendMessage { |
75 _SendMessage() {} | 75 _SendMessage() {} |
76 Thread *thread; | 76 Thread *thread; |
77 Message msg; | 77 Message msg; |
78 bool *ready; | 78 bool *ready; |
79 }; | 79 }; |
80 | 80 |
81 enum ThreadPriority { | |
82 PRIORITY_IDLE = -1, | |
83 PRIORITY_NORMAL = 0, | |
84 PRIORITY_ABOVE_NORMAL = 1, | |
85 PRIORITY_HIGH = 2, | |
86 }; | |
87 | |
88 class Runnable { | 81 class Runnable { |
89 public: | 82 public: |
90 virtual ~Runnable() {} | 83 virtual ~Runnable() {} |
91 virtual void Run(Thread* thread) = 0; | 84 virtual void Run(Thread* thread) = 0; |
92 | 85 |
93 protected: | 86 protected: |
94 Runnable() {} | 87 Runnable() {} |
95 | 88 |
96 private: | 89 private: |
97 RTC_DISALLOW_COPY_AND_ASSIGN(Runnable); | 90 RTC_DISALLOW_COPY_AND_ASSIGN(Runnable); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // Sleeps the calling thread for the specified number of milliseconds, during | 123 // Sleeps the calling thread for the specified number of milliseconds, during |
131 // which time no processing is performed. Returns false if sleeping was | 124 // which time no processing is performed. Returns false if sleeping was |
132 // interrupted by a signal (POSIX only). | 125 // interrupted by a signal (POSIX only). |
133 static bool SleepMs(int millis); | 126 static bool SleepMs(int millis); |
134 | 127 |
135 // Sets the thread's name, for debugging. Must be called before Start(). | 128 // Sets the thread's name, for debugging. Must be called before Start(). |
136 // If |obj| is non-NULL, its value is appended to |name|. | 129 // If |obj| is non-NULL, its value is appended to |name|. |
137 const std::string& name() const { return name_; } | 130 const std::string& name() const { return name_; } |
138 bool SetName(const std::string& name, const void* obj); | 131 bool SetName(const std::string& name, const void* obj); |
139 | 132 |
140 // Sets the thread's priority. Must be called before Start(). | |
141 ThreadPriority priority() const { return priority_; } | |
142 bool SetPriority(ThreadPriority priority); | |
143 | |
144 // Starts the execution of the thread. | 133 // Starts the execution of the thread. |
145 bool Start(Runnable* runnable = NULL); | 134 bool Start(Runnable* runnable = NULL); |
146 | 135 |
147 // Tells the thread to stop and waits until it is joined. | 136 // Tells the thread to stop and waits until it is joined. |
148 // Never call Stop on the current thread. Instead use the inherited Quit | 137 // Never call Stop on the current thread. Instead use the inherited Quit |
149 // function which will exit the base MessageQueue without terminating the | 138 // function which will exit the base MessageQueue without terminating the |
150 // underlying OS thread. | 139 // underlying OS thread. |
151 virtual void Stop(); | 140 virtual void Stop(); |
152 | 141 |
153 // By default, Thread::Run() calls ProcessMessages(kForever). To do other | 142 // By default, Thread::Run() calls ProcessMessages(kForever). To do other |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 // The caller must lock |crit_| before calling. | 253 // The caller must lock |crit_| before calling. |
265 // Returns true if there is such a message. | 254 // Returns true if there is such a message. |
266 bool PopSendMessageFromThread(const Thread* source, _SendMessage* msg); | 255 bool PopSendMessageFromThread(const Thread* source, _SendMessage* msg); |
267 | 256 |
268 // Used for tracking performance of Invoke calls. | 257 // Used for tracking performance of Invoke calls. |
269 void InvokeBegin(); | 258 void InvokeBegin(); |
270 void InvokeEnd(); | 259 void InvokeEnd(); |
271 | 260 |
272 std::list<_SendMessage> sendlist_; | 261 std::list<_SendMessage> sendlist_; |
273 std::string name_; | 262 std::string name_; |
274 ThreadPriority priority_; | |
275 Event running_; // Signalled means running. | 263 Event running_; // Signalled means running. |
276 | 264 |
277 #if defined(WEBRTC_POSIX) | 265 #if defined(WEBRTC_POSIX) |
278 pthread_t thread_; | 266 pthread_t thread_; |
279 #endif | 267 #endif |
280 | 268 |
281 #if defined(WEBRTC_WIN) | 269 #if defined(WEBRTC_WIN) |
282 HANDLE thread_; | 270 HANDLE thread_; |
283 DWORD thread_id_; | 271 DWORD thread_id_; |
284 #endif | 272 #endif |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 | 320 |
333 private: | 321 private: |
334 SocketServer* old_ss_; | 322 SocketServer* old_ss_; |
335 | 323 |
336 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SocketServerScope); | 324 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(SocketServerScope); |
337 }; | 325 }; |
338 | 326 |
339 } // namespace rtc | 327 } // namespace rtc |
340 | 328 |
341 #endif // WEBRTC_BASE_THREAD_H_ | 329 #endif // WEBRTC_BASE_THREAD_H_ |
OLD | NEW |