blob: a850b945dce7b23822294b10d2abebe6b09457d8 [file] [log] [blame]
perkj9c16fe82016-07-12 15:04:07 -07001/*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef RTC_BASE_SEQUENCED_TASK_CHECKER_IMPL_H_
12#define RTC_BASE_SEQUENCED_TASK_CHECKER_IMPL_H_
perkj9c16fe82016-07-12 15:04:07 -070013
Steve Anton10542f22019-01-11 09:11:00 -080014#include "rtc_base/critical_section.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/thread_checker.h"
perkj9c16fe82016-07-12 15:04:07 -070016
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020017namespace rtc {
perkj9c16fe82016-07-12 15:04:07 -070018
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020019class TaskQueue;
20// Real implementation of SequencedTaskChecker, for use in debug mode, or
21// for temporary use in release mode.
22//
23// Note: You should almost always use the SequencedTaskChecker class to get the
24// right version for your build configuration.
25class SequencedTaskCheckerImpl {
26 public:
27 SequencedTaskCheckerImpl();
28 ~SequencedTaskCheckerImpl();
29
30 bool CalledSequentially() const;
31
32 // Changes the task queue or thread that is checked for in IsCurrent. This
33 // may be useful when an object may be created on one task queue / thread and
34 // then used exclusively on another thread.
35 void Detach();
36
37 private:
Tommi10b40ce2018-02-19 13:34:00 +010038 friend class internal::AnnounceOnThread;
39 bool IsCurrent() const { return CalledSequentially(); }
40
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020041 typedef const void* QueueId;
42 CriticalSection lock_;
43 ThreadChecker thread_checker_;
44 mutable bool attached_;
45 mutable QueueId valid_queue_;
46};
47
48} // namespace rtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020049#endif // RTC_BASE_SEQUENCED_TASK_CHECKER_IMPL_H_