1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-18 11:52:08 +01:00

Use the same locking algorithm like in IMG/Mapsforge maps

This commit is contained in:
Martin Tůma 2024-12-03 20:25:38 +01:00
parent 240ddaf39c
commit d3889b6dfe

View File

@ -6,31 +6,23 @@ bool AtlasData::pointCb(MapEntry *map, void *context)
{ {
PointCTX *ctx = (PointCTX*)context; PointCTX *ctx = (PointCTX*)context;
start: map->lock.lock();
ctx->cacheLock.lock(); ctx->cacheLock.lock();
MapData *cached = ctx->cache.object(map->path); MapData *cached = ctx->cache.object(map->path);
if (!cached) { if (!cached) {
ctx->cacheLock.unlock(); ctx->cacheLock.unlock();
if (map->lock.tryLock()) { MapData *data = new MapData(map->path);
MapData *data = new MapData(map->path); data->points(ctx->rect, ctx->points);
data->points(ctx->rect, ctx->points);
ctx->cacheLock.lock(); ctx->cacheLock.lock();
ctx->cache.insert(map->path, data); ctx->cache.insert(map->path, data);
map->lock.unlock();
} else {
map->lock.lock();
map->lock.unlock();
goto start;
}
} else } else
cached->points(ctx->rect, ctx->points); cached->points(ctx->rect, ctx->points);
ctx->cacheLock.unlock(); ctx->cacheLock.unlock();
map->lock.unlock();
return true; return true;
} }