Alexander Aprelev cebde437a1
Guard the service protocol's global handlers list with a reader/writer lock. (#6900)
* Revert "Revert "Guard the service protocol's global handlers list with a reader/writer lock (#6888) #6895" (#6899)"

This reverts commit b6e93759faa92a96650e326b0e82578a6803c46d and applies fix for tests on Windows.

* Reland guard the service protocol's global handlers list with a reader/writer lock.

* Remove blank line
2018-11-18 14:36:15 -08:00

37 lines
838 B
C++

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_FML_SYNCHRONIZATION_ATOMIC_OBJECT_H_
#define FLUTTER_FML_SYNCHRONIZATION_ATOMIC_OBJECT_H_
#include <mutex>
namespace fml {
// A wrapper for an object instance that can be read or written atomically.
template <typename T>
class AtomicObject {
public:
AtomicObject() = default;
AtomicObject(T object) : object_(object) {}
T Load() const {
std::lock_guard<std::mutex> lock(mutex_);
return object_;
}
void Store(const T& object) {
std::lock_guard<std::mutex> lock(mutex_);
object_ = object;
}
private:
mutable std::mutex mutex_;
T object_;
};
} // namespace fml
#endif // FLUTTER_FML_SYNCHRONIZATION_ATOMIC_OBJECT_H_