summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2f5884c)
raw | patch | inline | side by side (parent: 2f5884c)
author | Yifan Hong <elsk@google.com> | |
Tue, 2 Oct 2018 21:06:51 +0000 (14:06 -0700) | ||
committer | Yifan Hong <elsk@google.com> | |
Tue, 2 Oct 2018 21:30:03 +0000 (14:30 -0700) |
Need to use an reentrant lock.
Bug: 117167903
Test: vts
Change-Id: I25a366e06ed9d983823f7276668b7f45ddcf1c2b
Bug: 117167903
Test: vts
Change-Id: I25a366e06ed9d983823f7276668b7f45ddcf1c2b
health/2.0/default/Health.cpp | patch | blob | history | |
health/2.0/default/include/health2/Health.h | patch | blob | history |
index e02bfa98df0f0e0e39cd19fb2d83fd6475466642..4a4bee06fb510cc849363e7b5d015ed2181e97a4 100644 (file)
}
{
- std::lock_guard<std::mutex> _lock(callbacks_lock_);
+ std::lock_guard<decltype(callbacks_lock_)> lock(callbacks_lock_);
callbacks_.push_back(callback);
// unlock
}
if (callback == nullptr) return false;
bool removed = false;
- std::lock_guard<std::mutex> _lock(callbacks_lock_);
+ std::lock_guard<decltype(callbacks_lock_)> lock(callbacks_lock_);
for (auto it = callbacks_.begin(); it != callbacks_.end();) {
if (interfacesEqual(*it, callback)) {
it = callbacks_.erase(it);
healthInfo->diskStats = stats;
healthInfo->storageInfos = info;
- std::lock_guard<std::mutex> _lock(callbacks_lock_);
+ std::lock_guard<decltype(callbacks_lock_)> lock(callbacks_lock_);
for (auto it = callbacks_.begin(); it != callbacks_.end();) {
auto ret = (*it)->healthInfoChanged(*healthInfo);
if (!ret.isOk() && ret.isDeadObject()) {
diff --git a/health/2.0/default/include/health2/Health.h b/health/2.0/default/include/health2/Health.h
index 134cdc6e696b71d3244c2ee46002c6750992c9c2..b960358bfd77e8f679a987cff2b7db5586f63810 100644 (file)
// Should only be called by implementation itself (-impl, -service).
// Clients should not call this function. Instead, initInstance() initializes and returns the
// global instance that has fewer functions.
- // TODO(b/62229583): clean up and hide these functions after update() logic is simplified.
static sp<Health> getImplementation();
Health(struct healthd_config* c);
- // TODO(b/62229583): clean up and hide these functions after update() logic is simplified.
void notifyListeners(HealthInfo* info);
// Methods from IHealth follow.
private:
static sp<Health> instance_;
- std::mutex callbacks_lock_;
+ std::recursive_mutex callbacks_lock_;
std::vector<sp<IHealthInfoCallback>> callbacks_;
std::unique_ptr<BatteryMonitor> battery_monitor_;