Skip to content

Commit

Permalink
Use the same locking algorithm like in IMG/Mapsforge maps
Browse files Browse the repository at this point in the history
  • Loading branch information
tumic0 committed Dec 3, 2024
1 parent 5368525 commit 240ddaf
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/map/ENC/atlasdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,26 @@ bool AtlasData::polyCb(MapEntry *map, void *context)
{
PolyCTX *ctx = (PolyCTX*)context;

start:
ctx->cacheLock.lock();
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;
}
Expand Down

0 comments on commit 240ddaf

Please sign in to comment.