From 240ddaf39cce5c995743244d7e1238db6936cbc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Tue, 3 Dec 2024 20:20:40 +0100 Subject: [PATCH] Use the same locking algorithm like in IMG/Mapsforge maps --- src/map/ENC/atlasdata.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/map/ENC/atlasdata.cpp b/src/map/ENC/atlasdata.cpp index 7cb4f4a5..d960a0c4 100644 --- a/src/map/ENC/atlasdata.cpp +++ b/src/map/ENC/atlasdata.cpp @@ -39,34 +39,26 @@ bool AtlasData::polyCb(MapEntry *map, void *context) { PolyCTX *ctx = (PolyCTX*)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->polygons(ctx->rect, ctx->polygons); - data->lines(ctx->rect, ctx->lines); + MapData *data = new MapData(map->path); + data->polygons(ctx->rect, ctx->polygons); + data->lines(ctx->rect, ctx->lines); - 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->polygons(ctx->rect, ctx->polygons); cached->lines(ctx->rect, ctx->lines); } ctx->cacheLock.unlock(); + map->lock.unlock(); return true; }