diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-05-19 01:32:44 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-05-19 01:32:44 +0000 |
commit | 04c944cf478ff5d962706f77f8e3376b1428cf29 (patch) | |
tree | 58f4265a2ea55ca40beecec1786d2479435c9bb7 | |
parent | b26e3628e2fca19642275f7c178733121022a4a1 (diff) | |
parent | 5f268dda3aa5170a957a2368a084a47261480e2d (diff) |
Snap for 10162339 from 5f268dda3aa5170a957a2368a084a47261480e2d to udc-release
Change-Id: I44cf7e772dfeeb6804bfdb451f2e87e0fc3c3835
-rw-r--r-- | common/init.pixel.rc | 7 | ||||
-rw-r--r-- | thermal/Thermal.cpp | 41 | ||||
-rw-r--r-- | thermal/Thermal.h | 21 |
3 files changed, 51 insertions, 18 deletions
diff --git a/common/init.pixel.rc b/common/init.pixel.rc index 640212c..1296e73 100644 --- a/common/init.pixel.rc +++ b/common/init.pixel.rc @@ -8,10 +8,3 @@ on property:ota.warm_reset=1 on property:ota.warm_reset=0 write /sys/module/msm_poweroff/parameters/warm_reset 0 - -on init - copy_per_line /dev/cpuctl/tasks /dev/cpuctl/system/tasks - -# Migrate tasks again in case kernel threads are created during boot -on property:sys.boot_completed=1 - copy_per_line /dev/cpuctl/tasks /dev/cpuctl/system/tasks diff --git a/thermal/Thermal.cpp b/thermal/Thermal.cpp index c78c910..74ea266 100644 --- a/thermal/Thermal.cpp +++ b/thermal/Thermal.cpp @@ -163,8 +163,6 @@ ndk::ScopedAStatus Thermal::unregisterThermalChangedCallback( ndk::ScopedAStatus Thermal::registerThermalChangedCallback( const std::shared_ptr<IThermalChangedCallback> &callback, bool filterType, TemperatureType type) { - std::vector<Temperature> temperatures; - ATRACE_CALL(); if (callback == nullptr) { return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT, @@ -184,17 +182,21 @@ ndk::ScopedAStatus Thermal::registerThermalChangedCallback( LOG(INFO) << "a callback has been registered to ThermalHAL, isFilter: " << c.is_filter_type << " Type: " << toString(c.type); // Send notification right away after successful thermal callback registration - if (thermal_helper_.fillCurrentTemperatures(filterType, true, type, &temperatures)) { - for (const auto &t : temperatures) { - if (!filterType || t.type == type) { - LOG(INFO) << "Sending notification: " - << " Type: " << toString(t.type) << " Name: " << t.name - << " CurrentValue: " << t.value - << " ThrottlingStatus: " << toString(t.throttlingStatus); - c.callback->notifyThrottling(t); + std::function<void()> handler = [this, c, filterType, type]() { + std::vector<Temperature> temperatures; + if (thermal_helper_.fillCurrentTemperatures(filterType, true, type, &temperatures)) { + for (const auto &t : temperatures) { + if (!filterType || t.type == type) { + LOG(INFO) << "Sending notification: " + << " Type: " << toString(t.type) << " Name: " << t.name + << " CurrentValue: " << t.value + << " ThrottlingStatus: " << toString(t.throttlingStatus); + c.callback->notifyThrottling(t); + } } } - } + }; + looper_.addEvent(Looper::Event{handler}); return ndk::ScopedAStatus::ok(); } @@ -763,6 +765,23 @@ binder_status_t Thermal::dump(int fd, const char **args, uint32_t numArgs) { return STATUS_BAD_VALUE; } +void Thermal::Looper::addEvent(const Thermal::Looper::Event &e) { + std::unique_lock<std::mutex> lock(mutex_); + events_.push(e); + cv_.notify_all(); +} + +void Thermal::Looper::loop() { + while (true) { + std::unique_lock<std::mutex> lock(mutex_); + cv_.wait(lock, [&] { return !events_.empty(); }); + Event event = events_.front(); + events_.pop(); + lock.unlock(); + event.handler(); + } +} + } // namespace implementation } // namespace thermal } // namespace hardware diff --git a/thermal/Thermal.h b/thermal/Thermal.h index e41bf05..74449c4 100644 --- a/thermal/Thermal.h +++ b/thermal/Thermal.h @@ -68,9 +68,30 @@ class Thermal : public BnThermal { void sendThermalChangedCallback(const Temperature &t); private: + class Looper { + public: + struct Event { + std::function<void()> handler; + }; + + Looper() { + thread_ = std::thread([&] { loop(); }); + } + void addEvent(const Event &e); + + private: + std::condition_variable cv_; + std::queue<Event> events_; + std::mutex mutex_; + std::thread thread_; + + void loop(); + }; + ThermalHelper thermal_helper_; std::mutex thermal_callback_mutex_; std::vector<CallbackSetting> callbacks_; + Looper looper_; ndk::ScopedAStatus getFilteredTemperatures(bool filterType, TemperatureType type, std::vector<Temperature> *_aidl_return); |