Fixed the data race in ObserverList

PiperOrigin-RevId: 528638464
This commit is contained in:
Guogang Li
2023-05-01 19:11:52 -07:00
committed by Copybara-Service
parent 8741eb6c71
commit 9ea2c9fd8e
+5
View File
@@ -28,6 +28,11 @@ class ObserverList {
using const_iterator =
typename absl::flat_hash_set<ObserverType*>::const_iterator;
~ObserverList() ABSL_LOCKS_EXCLUDED(mutex_) {
MutexLock lock(&mutex_);
observers_.clear();
}
void AddObserver(ObserverType* observer) ABSL_LOCKS_EXCLUDED(mutex_) {
MutexLock lock(&mutex_);
observers_.insert(observer);