From d3889b6dfeb6019ba4d257cc10132607ef603e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Tue, 3 Dec 2024 20:25:38 +0100 Subject: [PATCH] Use the same locking algorithm like in IMG/Mapsforge maps --- src/map/ENC/atlasdata.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/map/ENC/atlasdata.cpp b/src/map/ENC/atlasdata.cpp index d960a0c4..6e31ae66 100644 --- a/src/map/ENC/atlasdata.cpp +++ b/src/map/ENC/atlasdata.cpp @@ -6,31 +6,23 @@ bool AtlasData::pointCb(MapEntry *map, void *context) { PointCTX *ctx = (PointCTX*)context; -start: + map->lock.lock(); + ctx->cacheLock.lock(); - MapData *cached = ctx->cache.object(map->path); - if (!cached) { ctx->cacheLock.unlock(); - if (map->lock.tryLock()) { - MapData *data = new MapData(map->path); - data->points(ctx->rect, ctx->points); + MapData *data = new MapData(map->path); + data->points(ctx->rect, ctx->points); - ctx->cacheLock.lock(); - ctx->cache.insert(map->path, data); - - map->lock.unlock(); - } else { - map->lock.lock(); - map->lock.unlock(); - goto start; - } + ctx->cacheLock.lock(); + ctx->cache.insert(map->path, data); } else cached->points(ctx->rect, ctx->points); ctx->cacheLock.unlock(); + map->lock.unlock(); return true; }