Optimize battery life across DTB pinctrl, schedutil, SDHCI, and background daemons
This commit is contained in:
1 parent
9c28fa1e4c
commit
0a24bf8aff
20 files changed
+59
-29
No files matched your search
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <cmath>
|
||||
#include <condition_variable>
|
||||
#include <fstream>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
@@ -249,7 +250,7 @@ std::string getWaypointsPath() {
|
||||
}
|
||||
|
||||
std::string getOsmTileCacheDir() {
|
||||
if (::access("/media/sdcard", W_OK) == 0) {
|
||||
if (!isDuressMode() && ::access("/media/sdcard", W_OK) == 0) {
|
||||
std::string sdDir = "/media/sdcard/osm_tiles";
|
||||
::mkdir(sdDir.c_str(), 0755);
|
||||
return sdDir;
|
||||
@@ -442,6 +443,7 @@ class OsmTileCache {
|
||||
|
||||
~OsmTileCache() {
|
||||
stopWorker_.store(true);
|
||||
cv_.notify_all();
|
||||
if (worker_.joinable()) worker_.join();
|
||||
}
|
||||
|
||||
@@ -485,6 +487,7 @@ class OsmTileCache {
|
||||
cache_[key] = std::move(pending);
|
||||
if (queue_.size() < 16) {
|
||||
queue_.push_back({z, x, y, key, diskPath});
|
||||
cv_.notify_one();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -505,18 +508,12 @@ class OsmTileCache {
|
||||
void workerLoop() {
|
||||
while (!stopWorker_.load()) {
|
||||
TileReq req;
|
||||
bool hasReq = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(mtx_);
|
||||
if (!queue_.empty()) {
|
||||
req = queue_.back();
|
||||
queue_.pop_back();
|
||||
hasReq = true;
|
||||
}
|
||||
}
|
||||
if (!hasReq) {
|
||||
::usleep(120000);
|
||||
continue;
|
||||
std::unique_lock<std::mutex> lk(mtx_);
|
||||
cv_.wait(lk, [this]() { return stopWorker_.load() || !queue_.empty(); });
|
||||
if (stopWorker_.load()) break;
|
||||
req = queue_.back();
|
||||
queue_.pop_back();
|
||||
}
|
||||
|
||||
std::string url = "https://tile.openstreetmap.org/" + std::to_string(req.z) +
|
||||
@@ -544,6 +541,7 @@ class OsmTileCache {
|
||||
}
|
||||
|
||||
std::mutex mtx_;
|
||||
std::condition_variable cv_;
|
||||
std::unordered_map<std::string, TilePixels> cache_;
|
||||
std::vector<TileReq> queue_;
|
||||
std::atomic<bool> stopWorker_{false};
|
||||
|
||||
Reference in new issue
Block a user