Skip to content

Commit a4b8925

Browse files
Cleanup (#59)
1 parent 2b5aa4f commit a4b8925

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

src/OpenStreetMap-esp32.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ OpenStreetMap::~OpenStreetMap()
4545

4646
freeTilesCache();
4747

48-
if (cacheSemaphore)
49-
vSemaphoreDelete(cacheSemaphore);
48+
if (cacheMutex)
49+
vSemaphoreDelete(cacheMutex);
5050

5151
if (pngCore0)
5252
{
@@ -312,15 +312,15 @@ bool OpenStreetMap::composeMap(LGFX_Sprite &mapSprite, const tileList &requiredT
312312

313313
bool OpenStreetMap::fetchMap(LGFX_Sprite &mapSprite, double longitude, double latitude, uint8_t zoom)
314314
{
315-
if (!cacheSemaphore)
315+
if (!cacheMutex)
316316
{
317-
cacheSemaphore = xSemaphoreCreateBinary();
318-
if (!cacheSemaphore)
317+
cacheMutex = xSemaphoreCreateBinary();
318+
if (!cacheMutex)
319319
{
320320
log_e("could not init cache mutex");
321321
return false;
322322
}
323-
xSemaphoreGive(cacheSemaphore);
323+
xSemaphoreGive(cacheMutex);
324324
}
325325

326326
if (!tasksStarted && !startTileWorkerTasks())
@@ -525,13 +525,6 @@ bool OpenStreetMap::fetchTile(CachedTile &tile, uint32_t x, uint32_t y, uint8_t
525525
return true;
526526
}
527527

528-
void OpenStreetMap::decrementActiveJobs()
529-
{
530-
log_d("pending jobs: %d", pendingJobs.load());
531-
if (--pendingJobs == 0)
532-
log_v("jobs done");
533-
}
534-
535528
void OpenStreetMap::tileFetcherTask(void *param)
536529
{
537530
OpenStreetMap *osm = static_cast<OpenStreetMap *>(param);
@@ -540,27 +533,27 @@ void OpenStreetMap::tileFetcherTask(void *param)
540533
TileJob job;
541534
unsigned long startMS;
542535
{
543-
ScopedMutex lock(osm->cacheSemaphore);
536+
ScopedMutex lock(osm->cacheMutex);
544537
BaseType_t received = xQueueReceive(osm->jobQueue, &job, portMAX_DELAY);
545538
startMS = millis();
546539

547540
if (received != pdTRUE)
548541
continue;
549542

550-
if (job.z == 255) // poison pill: absolved by dtor
543+
if (job.z == 255)
551544
break;
552545

553546
if (!job.tile)
554547
continue;
555548

556549
{
557-
ScopedMutex lock(job.tile->mutex); // protect tile fields
550+
ScopedMutex lock(job.tile->mutex);
558551
if (job.tile->valid &&
559552
job.tile->x == job.x &&
560553
job.tile->y == job.y &&
561554
job.tile->z == job.z)
562555
{
563-
continue; // Already fetched
556+
continue;
564557
}
565558

566559
job.tile->x = job.x;

src/OpenStreetMap-esp32.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class OpenStreetMap
8888
bool fetchMap(LGFX_Sprite &sprite, double longitude, double latitude, uint8_t zoom);
8989

9090
private:
91-
SemaphoreHandle_t cacheSemaphore = nullptr;
91+
SemaphoreHandle_t cacheMutex = nullptr;
9292
std::vector<CachedTile> tilesCache;
9393
thread_local static uint16_t *currentTileBuffer;
9494
thread_local static OpenStreetMap *currentInstance;
@@ -105,7 +105,7 @@ class OpenStreetMap
105105
bool composeMap(LGFX_Sprite &mapSprite, const tileList &requiredTiles, uint8_t zoom);
106106
static void tileFetcherTask(void *param);
107107
TaskHandle_t ownerTask = nullptr;
108-
void decrementActiveJobs();
108+
inline void decrementActiveJobs() { --pendingJobs; }
109109
bool startTileWorkerTasks();
110110

111111
QueueHandle_t jobQueue = nullptr;

0 commit comments

Comments
 (0)