diff --git a/src/CachedTile.hpp b/src/CachedTile.hpp index ab0ec9f..75b1fa9 100644 --- a/src/CachedTile.hpp +++ b/src/CachedTile.hpp @@ -34,7 +34,6 @@ struct CachedTile uint8_t z; bool valid; bool busy; - SemaphoreHandle_t mutex; uint16_t *buffer; CachedTile() @@ -43,18 +42,12 @@ struct CachedTile z(0), valid(false), busy(false), - mutex(xSemaphoreCreateMutex()), buffer(nullptr) { } ~CachedTile() { - if (mutex) - { - vSemaphoreDelete(mutex); - mutex = nullptr; - } free(); } diff --git a/src/OpenStreetMap-esp32.cpp b/src/OpenStreetMap-esp32.cpp index cfaa757..85325a0 100644 --- a/src/OpenStreetMap-esp32.cpp +++ b/src/OpenStreetMap-esp32.cpp @@ -47,12 +47,6 @@ OpenStreetMap::~OpenStreetMap() freeTilesCache(); - if (cacheMutex) - { - vSemaphoreDelete(cacheMutex); - cacheMutex = nullptr; - } - if (pngCore0) { pngCore0->~PNG(); @@ -148,7 +142,6 @@ CachedTile *OpenStreetMap::findUnusedTile(const tileList &requiredTiles, uint8_t { for (auto &tile : tilesCache) { - ScopedMutex lock(tile.mutex); if (tile.busy) continue; @@ -253,10 +246,8 @@ void OpenStreetMap::updateCache(const tileList &requiredTiles, uint8_t zoom) delay(1); for (const TileJob &job : jobs) - { - ScopedMutex _(job.tile->mutex); job.tile->busy = false; - } + log_i("Cache updated in %lu ms", millis() - startMS); } } @@ -317,17 +308,6 @@ bool OpenStreetMap::composeMap(LGFX_Sprite &mapSprite, const tileList &requiredT bool OpenStreetMap::fetchMap(LGFX_Sprite &mapSprite, double longitude, double latitude, uint8_t zoom) { - if (!cacheMutex) - { - cacheMutex = xSemaphoreCreateBinary(); - if (!cacheMutex) - { - log_e("could not init cache mutex"); - return false; - } - xSemaphoreGive(cacheMutex); - } - if (!tasksStarted && !startTileWorkerTasks()) { log_e("Failed to start tile worker(s)"); @@ -533,36 +513,14 @@ void OpenStreetMap::tileFetcherTask(void *param) while (true) { TileJob job; - unsigned long startMS; - { - ScopedMutex lock(osm->cacheMutex); - BaseType_t received = xQueueReceive(osm->jobQueue, &job, portMAX_DELAY); - startMS = millis(); - - if (received != pdTRUE) - continue; - - if (job.z == 255) - break; + xQueueReceive(osm->jobQueue, &job, portMAX_DELAY); + const unsigned long startMS = millis(); - if (!job.tile) - continue; + if (job.z == 255) + break; - { - ScopedMutex lock(job.tile->mutex); - if (job.tile->valid && - job.tile->x == job.x && - job.tile->y == job.y && - job.tile->z == job.z) - { - continue; - } - - job.tile->x = job.x; - job.tile->y = job.y; - job.tile->z = job.z; - } - } + if (!job.tile) + continue; String result; if (!osm->fetchTile(*job.tile, job.x, job.y, job.z, result)) diff --git a/src/OpenStreetMap-esp32.hpp b/src/OpenStreetMap-esp32.hpp index 8c14235..7a4a9b5 100644 --- a/src/OpenStreetMap-esp32.hpp +++ b/src/OpenStreetMap-esp32.hpp @@ -34,7 +34,6 @@ #include #include "CachedTile.hpp" -#include "ScopedMutex.hpp" #include "TileJob.hpp" #include "MemoryBuffer.hpp" #include "HTTPClientRAII.hpp" @@ -85,7 +84,6 @@ class OpenStreetMap bool fetchMap(LGFX_Sprite &sprite, double longitude, double latitude, uint8_t zoom); private: - SemaphoreHandle_t cacheMutex = nullptr; std::vector tilesCache; static inline thread_local OpenStreetMap *currentInstance = nullptr; static inline thread_local uint16_t *currentTileBuffer = nullptr; diff --git a/src/ScopedMutex.hpp b/src/ScopedMutex.hpp deleted file mode 100644 index 08ffa41..0000000 --- a/src/ScopedMutex.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - MIT License - Copyright (c) 2025 Cellie https://github.com/CelliesProjects/OpenStreetMap-esp32 - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - SPDX-License-Identifier: MIT -*/ -#ifndef SCOPEDMUTEX_HPP_ -#define SCOPEDMUTEX_HPP_ - -#include -#include - -class ScopedMutex -{ -private: - SemaphoreHandle_t &mutex; - bool locked; - -public: - explicit ScopedMutex(SemaphoreHandle_t &m, TickType_t timeout = portMAX_DELAY) - : mutex(m), locked(xSemaphoreTake(mutex, timeout)) {} - - ScopedMutex(const ScopedMutex &) = delete; - ScopedMutex &operator=(const ScopedMutex &) = delete; - - ~ScopedMutex() - { - if (locked) - xSemaphoreGive(mutex); - } - - bool acquired() const { return locked; } -}; - -#endif // SCOPEDMUTEX_H