Use queue label as id in SequencedTaskChecker when not running on TaskQueue

This is intended to make SequencedTaskChecker work for native dispatch queues
on iOS and macOS. These labels can be compared by their pointers to determine
if a task is running on the same queue.

BUG=webrtc:6643

Review-Url: https://codereview.webrtc.org/2464383002
Cr-Commit-Position: refs/heads/master@{#14900}
This commit is contained in:
kthelgason 2016-11-02 10:28:20 -07:00 committed by Commit bot
parent b4bc65b4e9
commit 44e0efe0e6
2 changed files with 13 additions and 2 deletions

View File

@ -10,6 +10,10 @@
#include "webrtc/base/sequenced_task_checker_impl.h"
#if defined(WEBRTC_MAC)
#include <dispatch/dispatch.h>
#endif
#include "webrtc/base/platform_thread.h"
#include "webrtc/base/sequenced_task_checker.h"
#include "webrtc/base/task_queue.h"
@ -22,7 +26,13 @@ SequencedTaskCheckerImpl::SequencedTaskCheckerImpl()
SequencedTaskCheckerImpl::~SequencedTaskCheckerImpl() {}
bool SequencedTaskCheckerImpl::CalledSequentially() const {
TaskQueue* current_queue = TaskQueue::Current();
QueueId current_queue = TaskQueue::Current();
#if defined(WEBRTC_MAC)
// If we're not running on a TaskQueue, use the system dispatch queue
// label as an identifier.
if (current_queue == nullptr)
current_queue = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL);
#endif
CritScope scoped_lock(&lock_);
if (!attached_) { // true if previously detached.
valid_queue_ = current_queue;

View File

@ -34,10 +34,11 @@ class SequencedTaskCheckerImpl {
void Detach();
private:
typedef const void* QueueId;
CriticalSection lock_;
ThreadChecker thread_checker_;
mutable bool attached_;
mutable TaskQueue* valid_queue_;
mutable QueueId valid_queue_;
};
} // namespace rtc