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:
committed by
WebRTC LUCI CQ
parent
63b54ec896
commit
b36f6896c8
@ -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
|
||||
|
||||
Reference in New Issue
Block a user