Add SequenceChecker on Notifier

Bug: None
Change-Id: I85e80576d92ddae55a3fbd144338d9c57fb80065
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/252520
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Auto-Submit: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36116}
This commit is contained in:
Byoungchan Lee 2022-03-03 05:55:22 +09:00 committed by WebRTC LUCI CQ
parent 63b54ec896
commit b36f6896c8
3 changed files with 16 additions and 2 deletions

View file

@ -116,10 +116,12 @@ rtc_library("media_stream_interface") {
":audio_options_api",
":rtp_parameters",
":scoped_refptr",
":sequence_checker",
":video_track_source_constraints",
"../modules/audio_processing:audio_processing_statistics",
"../rtc_base:checks",
"../rtc_base:refcount",
"../rtc_base/system:no_unique_address",
"../rtc_base/system:rtc_export",
"video:recordable_encoded_frame",
"video:video_frame",

View file

@ -274,6 +274,10 @@ specific_include_rules = {
"+rtc_base/ref_counted_object.h",
],
"notifier\.h": [
"+rtc_base/system/no_unique_address.h",
],
"simulated_network\.h": [
"+rtc_base/random.h",
"+rtc_base/thread_annotations.h",

View file

@ -14,7 +14,9 @@
#include <list>
#include "api/media_stream_interface.h"
#include "api/sequence_checker.h"
#include "rtc_base/checks.h"
#include "rtc_base/system/no_unique_address.h"
namespace webrtc {
@ -23,14 +25,16 @@ namespace webrtc {
template <class T>
class Notifier : public T {
public:
Notifier() {}
Notifier() { sequence_checker_.Detach(); }
virtual void RegisterObserver(ObserverInterface* observer) {
RTC_DCHECK_RUN_ON(&sequence_checker_);
RTC_DCHECK(observer != nullptr);
observers_.push_back(observer);
}
virtual void UnregisterObserver(ObserverInterface* observer) {
RTC_DCHECK_RUN_ON(&sequence_checker_);
for (std::list<ObserverInterface*>::iterator it = observers_.begin();
it != observers_.end(); it++) {
if (*it == observer) {
@ -41,6 +45,7 @@ class Notifier : public T {
}
void FireOnChanged() {
RTC_DCHECK_RUN_ON(&sequence_checker_);
// Copy the list of observers to avoid a crash if the observer object
// unregisters as a result of the OnChanged() call. If the same list is used
// UnregisterObserver will affect the list make the iterator invalid.
@ -52,7 +57,10 @@ class Notifier : public T {
}
protected:
std::list<ObserverInterface*> observers_;
std::list<ObserverInterface*> observers_ RTC_GUARDED_BY(sequence_checker_);
private:
RTC_NO_UNIQUE_ADDRESS SequenceChecker sequence_checker_;
};
} // namespace webrtc