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:
@ -22,6 +22,12 @@
|
|||||||
#include "rtc_base/thread_annotations.h"
|
#include "rtc_base/thread_annotations.h"
|
||||||
|
|
||||||
namespace rtc {
|
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.
|
// Do nothing implementation, for use in release mode.
|
||||||
//
|
//
|
||||||
@ -30,8 +36,11 @@ namespace rtc {
|
|||||||
class SequencedTaskCheckerDoNothing {
|
class SequencedTaskCheckerDoNothing {
|
||||||
public:
|
public:
|
||||||
bool CalledSequentially() const { return true; }
|
bool CalledSequentially() const { return true; }
|
||||||
|
|
||||||
void Detach() {}
|
void Detach() {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class internal::AnnounceOnThread;
|
||||||
|
bool IsCurrent() const { return CalledSequentially(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
// SequencedTaskChecker is a helper class used to help verify that some methods
|
// SequencedTaskChecker is a helper class used to help verify that some methods
|
||||||
|
|||||||
@ -34,6 +34,9 @@ class SequencedTaskCheckerImpl {
|
|||||||
void Detach();
|
void Detach();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class internal::AnnounceOnThread;
|
||||||
|
bool IsCurrent() const { return CalledSequentially(); }
|
||||||
|
|
||||||
typedef const void* QueueId;
|
typedef const void* QueueId;
|
||||||
CriticalSection lock_;
|
CriticalSection lock_;
|
||||||
ThreadChecker thread_checker_;
|
ThreadChecker thread_checker_;
|
||||||
|
|||||||
@ -9,15 +9,38 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "rtc_base/sequenced_task_checker.h"
|
#include "rtc_base/sequenced_task_checker.h"
|
||||||
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/constructormagic.h"
|
#include "rtc_base/constructormagic.h"
|
||||||
#include "rtc_base/platform_thread.h"
|
#include "rtc_base/platform_thread.h"
|
||||||
#include "rtc_base/task_queue.h"
|
#include "rtc_base/task_queue.h"
|
||||||
|
#include "rtc_base/thread_checker.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
|
|
||||||
namespace {
|
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.
|
// Calls SequencedTaskChecker::CalledSequentially on another thread.
|
||||||
class CallCalledSequentiallyOnThread {
|
class CallCalledSequentiallyOnThread {
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user