| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 public: | 112 public: |
| 113 explicit Impl(const char* queue_name, | 113 explicit Impl(const char* queue_name, |
| 114 TaskQueue* queue, | 114 TaskQueue* queue, |
| 115 Priority priority = Priority::NORMAL); | 115 Priority priority = Priority::NORMAL); |
| 116 ~Impl() override; | 116 ~Impl() override; |
| 117 | 117 |
| 118 static TaskQueue::Impl* Current(); | 118 static TaskQueue::Impl* Current(); |
| 119 static TaskQueue* CurrentQueue(); | 119 static TaskQueue* CurrentQueue(); |
| 120 | 120 |
| 121 // Used for DCHECKing the current queue. | 121 // Used for DCHECKing the current queue. |
| 122 static bool IsCurrent(const char* queue_name); | |
| 123 bool IsCurrent() const; | 122 bool IsCurrent() const; |
| 124 | 123 |
| 125 void PostTask(std::unique_ptr<QueuedTask> task); | 124 void PostTask(std::unique_ptr<QueuedTask> task); |
| 126 void PostTaskAndReply(std::unique_ptr<QueuedTask> task, | 125 void PostTaskAndReply(std::unique_ptr<QueuedTask> task, |
| 127 std::unique_ptr<QueuedTask> reply, | 126 std::unique_ptr<QueuedTask> reply, |
| 128 TaskQueue::Impl* reply_queue); | 127 TaskQueue::Impl* reply_queue); |
| 129 | 128 |
| 130 void PostDelayedTask(std::unique_ptr<QueuedTask> task, uint32_t milliseconds); | 129 void PostDelayedTask(std::unique_ptr<QueuedTask> task, uint32_t milliseconds); |
| 131 | 130 |
| 132 private: | 131 private: |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 | 329 |
| 331 // static | 330 // static |
| 332 TaskQueue* TaskQueue::Impl::CurrentQueue() { | 331 TaskQueue* TaskQueue::Impl::CurrentQueue() { |
| 333 TaskQueue::Impl* current = Current(); | 332 TaskQueue::Impl* current = Current(); |
| 334 if (current) { | 333 if (current) { |
| 335 return current->queue_; | 334 return current->queue_; |
| 336 } | 335 } |
| 337 return nullptr; | 336 return nullptr; |
| 338 } | 337 } |
| 339 | 338 |
| 340 // static | |
| 341 bool TaskQueue::Impl::IsCurrent(const char* queue_name) { | |
| 342 TaskQueue::Impl* current = Current(); | |
| 343 return current && current->thread_.name().compare(queue_name) == 0; | |
| 344 } | |
| 345 | |
| 346 bool TaskQueue::Impl::IsCurrent() const { | 339 bool TaskQueue::Impl::IsCurrent() const { |
| 347 return IsThreadRefEqual(thread_.GetThreadRef(), CurrentThreadRef()); | 340 return IsThreadRefEqual(thread_.GetThreadRef(), CurrentThreadRef()); |
| 348 } | 341 } |
| 349 | 342 |
| 350 void TaskQueue::Impl::PostTask(std::unique_ptr<QueuedTask> task) { | 343 void TaskQueue::Impl::PostTask(std::unique_ptr<QueuedTask> task) { |
| 351 RTC_DCHECK(task.get()); | 344 RTC_DCHECK(task.get()); |
| 352 // libevent isn't thread safe. This means that we can't use methods such | 345 // libevent isn't thread safe. This means that we can't use methods such |
| 353 // as event_base_once to post tasks to the worker thread from a different | 346 // as event_base_once to post tasks to the worker thread from a different |
| 354 // thread. However, we can use it when posting from the worker thread itself. | 347 // thread. However, we can use it when posting from the worker thread itself. |
| 355 if (IsCurrent()) { | 348 if (IsCurrent()) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 } | 489 } |
| 497 | 490 |
| 498 TaskQueue::~TaskQueue() {} | 491 TaskQueue::~TaskQueue() {} |
| 499 | 492 |
| 500 // static | 493 // static |
| 501 TaskQueue* TaskQueue::Current() { | 494 TaskQueue* TaskQueue::Current() { |
| 502 return TaskQueue::Impl::CurrentQueue(); | 495 return TaskQueue::Impl::CurrentQueue(); |
| 503 } | 496 } |
| 504 | 497 |
| 505 // Used for DCHECKing the current queue. | 498 // Used for DCHECKing the current queue. |
| 506 // static | |
| 507 bool TaskQueue::IsCurrent(const char* queue_name) { | |
| 508 return TaskQueue::Impl::IsCurrent(queue_name); | |
| 509 } | |
| 510 | |
| 511 bool TaskQueue::IsCurrent() const { | 499 bool TaskQueue::IsCurrent() const { |
| 512 return impl_->IsCurrent(); | 500 return impl_->IsCurrent(); |
| 513 } | 501 } |
| 514 | 502 |
| 515 void TaskQueue::PostTask(std::unique_ptr<QueuedTask> task) { | 503 void TaskQueue::PostTask(std::unique_ptr<QueuedTask> task) { |
| 516 return TaskQueue::impl_->PostTask(std::move(task)); | 504 return TaskQueue::impl_->PostTask(std::move(task)); |
| 517 } | 505 } |
| 518 | 506 |
| 519 void TaskQueue::PostTaskAndReply(std::unique_ptr<QueuedTask> task, | 507 void TaskQueue::PostTaskAndReply(std::unique_ptr<QueuedTask> task, |
| 520 std::unique_ptr<QueuedTask> reply, | 508 std::unique_ptr<QueuedTask> reply, |
| 521 TaskQueue* reply_queue) { | 509 TaskQueue* reply_queue) { |
| 522 return TaskQueue::impl_->PostTaskAndReply(std::move(task), std::move(reply), | 510 return TaskQueue::impl_->PostTaskAndReply(std::move(task), std::move(reply), |
| 523 reply_queue->impl_.get()); | 511 reply_queue->impl_.get()); |
| 524 } | 512 } |
| 525 | 513 |
| 526 void TaskQueue::PostTaskAndReply(std::unique_ptr<QueuedTask> task, | 514 void TaskQueue::PostTaskAndReply(std::unique_ptr<QueuedTask> task, |
| 527 std::unique_ptr<QueuedTask> reply) { | 515 std::unique_ptr<QueuedTask> reply) { |
| 528 return TaskQueue::impl_->PostTaskAndReply(std::move(task), std::move(reply), | 516 return TaskQueue::impl_->PostTaskAndReply(std::move(task), std::move(reply), |
| 529 impl_.get()); | 517 impl_.get()); |
| 530 } | 518 } |
| 531 | 519 |
| 532 void TaskQueue::PostDelayedTask(std::unique_ptr<QueuedTask> task, | 520 void TaskQueue::PostDelayedTask(std::unique_ptr<QueuedTask> task, |
| 533 uint32_t milliseconds) { | 521 uint32_t milliseconds) { |
| 534 return TaskQueue::impl_->PostDelayedTask(std::move(task), milliseconds); | 522 return TaskQueue::impl_->PostDelayedTask(std::move(task), milliseconds); |
| 535 } | 523 } |
| 536 | 524 |
| 537 } // namespace rtc | 525 } // namespace rtc |
| OLD | NEW |