OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // | 151 // |
152 // A note on destruction: | 152 // A note on destruction: |
153 // | 153 // |
154 // When a TaskQueue is deleted, pending tasks will not be executed but they will | 154 // When a TaskQueue is deleted, pending tasks will not be executed but they will |
155 // be deleted. The deletion of tasks may happen asynchronously after the | 155 // be deleted. The deletion of tasks may happen asynchronously after the |
156 // TaskQueue itself has been deleted or it may happen synchronously while the | 156 // TaskQueue itself has been deleted or it may happen synchronously while the |
157 // TaskQueue instance is being deleted. This may vary from one OS to the next | 157 // TaskQueue instance is being deleted. This may vary from one OS to the next |
158 // so assumptions about lifetimes of pending tasks should not be made. | 158 // so assumptions about lifetimes of pending tasks should not be made. |
159 class LOCKABLE TaskQueue { | 159 class LOCKABLE TaskQueue { |
160 public: | 160 public: |
161 explicit TaskQueue(const char* queue_name); | 161 // TaskQueue priority levels. On some platforms these will map to thread |
162 // TODO(tommi): Implement move semantics? | 162 // priorities, on others such as Mac and iOS, GCD queue priorities. |
| 163 enum Priority { |
| 164 NORMAL = 0, |
| 165 HIGH, |
| 166 LOW, |
| 167 }; |
| 168 |
| 169 explicit TaskQueue(const char* queue_name, Priority priority = NORMAL); |
163 ~TaskQueue(); | 170 ~TaskQueue(); |
164 | 171 |
165 static TaskQueue* Current(); | 172 static TaskQueue* Current(); |
166 | 173 |
167 // Used for DCHECKing the current queue. | 174 // Used for DCHECKing the current queue. |
168 static bool IsCurrent(const char* queue_name); | 175 static bool IsCurrent(const char* queue_name); |
169 bool IsCurrent() const; | 176 bool IsCurrent() const; |
170 | 177 |
171 // TODO(tommi): For better debuggability, implement RTC_FROM_HERE. | 178 // TODO(tommi): For better debuggability, implement RTC_FROM_HERE. |
172 | 179 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 #elif defined(WEBRTC_WIN) | 269 #elif defined(WEBRTC_WIN) |
263 class MultimediaTimer; | 270 class MultimediaTimer; |
264 typedef std::unordered_map<UINT_PTR, std::unique_ptr<QueuedTask>> | 271 typedef std::unordered_map<UINT_PTR, std::unique_ptr<QueuedTask>> |
265 DelayedTasks; | 272 DelayedTasks; |
266 static void ThreadMain(void* context); | 273 static void ThreadMain(void* context); |
267 static bool ProcessQueuedMessages(DelayedTasks* delayed_tasks, | 274 static bool ProcessQueuedMessages(DelayedTasks* delayed_tasks, |
268 std::vector<MultimediaTimer>* timers); | 275 std::vector<MultimediaTimer>* timers); |
269 | 276 |
270 class WorkerThread : public PlatformThread { | 277 class WorkerThread : public PlatformThread { |
271 public: | 278 public: |
272 WorkerThread(ThreadRunFunction func, void* obj, const char* thread_name) | 279 WorkerThread(ThreadRunFunction func, |
273 : PlatformThread(func, obj, thread_name) {} | 280 void* obj, |
| 281 const char* thread_name, |
| 282 ThreadPriority priority) |
| 283 : PlatformThread(func, obj, thread_name, priority) {} |
274 | 284 |
275 bool QueueAPC(PAPCFUNC apc_function, ULONG_PTR data) { | 285 bool QueueAPC(PAPCFUNC apc_function, ULONG_PTR data) { |
276 return PlatformThread::QueueAPC(apc_function, data); | 286 return PlatformThread::QueueAPC(apc_function, data); |
277 } | 287 } |
278 }; | 288 }; |
279 WorkerThread thread_; | 289 WorkerThread thread_; |
280 #else | 290 #else |
281 #error not supported. | 291 #error not supported. |
282 #endif | 292 #endif |
283 | 293 |
284 RTC_DISALLOW_COPY_AND_ASSIGN(TaskQueue); | 294 RTC_DISALLOW_COPY_AND_ASSIGN(TaskQueue); |
285 }; | 295 }; |
286 | 296 |
287 } // namespace rtc | 297 } // namespace rtc |
288 | 298 |
289 #endif // WEBRTC_BASE_TASK_QUEUE_H_ | 299 #endif // WEBRTC_BASE_TASK_QUEUE_H_ |
OLD | NEW |