Add support for RTC_GUARDED_BY to SequencedTaskChecker.

Bug: webrtc:8903
Change-Id: I5121ac8412fd60694ea9b4abf0984bc825c1aa18
Reviewed-on: https://webrtc-review.googlesource.com/54311
Commit-Queue: Tommi <tommi@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22079}
This commit is contained in:
Tommi
2018-02-19 13:34:00 +01:00
committed by Commit Bot
parent da8781fc70
commit 10b40ce771
3 changed files with 36 additions and 1 deletions

View File

@ -22,6 +22,12 @@
#include "rtc_base/thread_annotations.h"
namespace rtc {
namespace internal {
// Forward declaration of the internal implementation of RTC_GUARDED_BY().
// SequencedTaskChecker grants this class access to call its IsCurrent() method.
// See thread_checker.h for more details.
class AnnounceOnThread;
} // namespace internal
// Do nothing implementation, for use in release mode.
//
@ -30,8 +36,11 @@ namespace rtc {
class SequencedTaskCheckerDoNothing {
public:
bool CalledSequentially() const { return true; }
void Detach() {}
private:
friend class internal::AnnounceOnThread;
bool IsCurrent() const { return CalledSequentially(); }
};
// SequencedTaskChecker is a helper class used to help verify that some methods

View File

@ -34,6 +34,9 @@ class SequencedTaskCheckerImpl {
void Detach();
private:
friend class internal::AnnounceOnThread;
bool IsCurrent() const { return CalledSequentially(); }
typedef const void* QueueId;
CriticalSection lock_;
ThreadChecker thread_checker_;

View File

@ -9,15 +9,38 @@
*/
#include "rtc_base/sequenced_task_checker.h"
#include "rtc_base/checks.h"
#include "rtc_base/constructormagic.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/task_queue.h"
#include "rtc_base/thread_checker.h"
#include "test/gtest.h"
namespace rtc {
namespace {
// This class is dead code, but its purpose is to make sure that
// SequencedTaskChecker is compatible with the RTC_GUARDED_BY and RTC_RUN_ON
// attributes that are checked at compile-time.
class CompileTimeTestForGuardedBy {
public:
int CalledOnSequence() RTC_RUN_ON(sequence_checker_) {
return guarded_;
}
void CallMeFromSequence() {
RTC_DCHECK_RUN_ON(&sequence_checker_)
<< "Should be called on sequence";
}
private:
int guarded_ RTC_GUARDED_BY(sequence_checker_);
rtc::SequencedTaskChecker sequence_checker_;
};
// Calls SequencedTaskChecker::CalledSequentially on another thread.
class CallCalledSequentiallyOnThread {
public: