diff --git a/src/map/IMG/mapdata.cpp b/src/map/IMG/mapdata.cpp index 8f6e06b2..a72cb818 100644 --- a/src/map/IMG/mapdata.cpp +++ b/src/map/IMG/mapdata.cpp @@ -13,14 +13,14 @@ bool MapData::polyCb(VectorTile *tile, void *context) { PolyCTX *ctx = (PolyCTX*)context; tile->polys(ctx->rect, ctx->zoom, ctx->polygons, ctx->lines, - ctx->polyCache); + ctx->polyCache, ctx->lock); return true; } bool MapData::pointCb(VectorTile *tile, void *context) { PointCTX *ctx = (PointCTX*)context; - tile->points(ctx->rect, ctx->zoom, ctx->points, ctx->pointCache); + tile->points(ctx->rect, ctx->zoom, ctx->points, ctx->pointCache, ctx->lock); return true; } @@ -45,7 +45,7 @@ MapData::~MapData() void MapData::polys(const RectC &rect, int bits, QList *polygons, QList *lines) { - PolyCTX ctx(rect, zoom(bits), polygons, lines, &_polyCache); + PolyCTX ctx(rect, zoom(bits), polygons, lines, &_polyCache, &_lock); double min[2], max[2]; min[0] = rect.left(); @@ -53,14 +53,12 @@ void MapData::polys(const RectC &rect, int bits, QList *polygons, max[0] = rect.right(); max[1] = rect.top(); - _lock.lock(); _tileTree.Search(min, max, polyCb, &ctx); - _lock.unlock(); } void MapData::points(const RectC &rect, int bits, QList *points) { - PointCTX ctx(rect, zoom(bits), points, &_pointCache); + PointCTX ctx(rect, zoom(bits), points, &_pointCache, &_lock); double min[2], max[2]; min[0] = rect.left(); @@ -68,9 +66,7 @@ void MapData::points(const RectC &rect, int bits, QList *points) max[0] = rect.right(); max[1] = rect.top(); - _lock.lock(); _tileTree.Search(min, max, pointCb, &ctx); - _lock.unlock(); } void MapData::load() diff --git a/src/map/IMG/mapdata.h b/src/map/IMG/mapdata.h index e3c0fd02..7959cf2f 100644 --- a/src/map/IMG/mapdata.h +++ b/src/map/IMG/mapdata.h @@ -105,27 +105,30 @@ private: { PolyCTX(const RectC &rect, const Zoom &zoom, QList *polygons, QList *lines, - PolyCache *polyCache) + PolyCache *polyCache, QMutex *lock) : rect(rect), zoom(zoom), polygons(polygons), lines(lines), - polyCache(polyCache) {} + polyCache(polyCache), lock(lock) {} const RectC ▭ const Zoom &zoom; QList *polygons; QList *lines; PolyCache *polyCache; + QMutex *lock; }; struct PointCTX { PointCTX(const RectC &rect, const Zoom &zoom, - QList *points, PointCache *pointCache) - : rect(rect), zoom(zoom), points(points), pointCache(pointCache) {} + QList *points, PointCache *pointCache, QMutex *lock) + : rect(rect), zoom(zoom), points(points), pointCache(pointCache), + lock(lock) {} const RectC ▭ const Zoom &zoom; QList *points; PointCache *pointCache; + QMutex *lock; }; const Zoom &zoom(int bits) const; diff --git a/src/map/IMG/vectortile.cpp b/src/map/IMG/vectortile.cpp index 3435e65c..814b6a6a 100644 --- a/src/map/IMG/vectortile.cpp +++ b/src/map/IMG/vectortile.cpp @@ -102,15 +102,17 @@ void VectorTile::clear() void VectorTile::polys(const RectC &rect, const Zoom &zoom, QList *polygons, QList *lines, - MapData::PolyCache *polyCache) + MapData::PolyCache *polyCache, QMutex *lock) { SubFile::Handle *rgnHdl = 0, *lblHdl = 0, *netHdl = 0, *nodHdl = 0, *nodHdl2 = 0; - if (_loaded < 0) - return; + lock->lock(); - //polyCache->lock.lock(); + if (_loaded < 0) { + lock->unlock(); + return; + } if (!_loaded) { rgnHdl = new SubFile::Handle(_rgn); @@ -119,7 +121,7 @@ void VectorTile::polys(const RectC &rect, const Zoom &zoom, nodHdl = new SubFile::Handle(_nod); if (!load(*rgnHdl, *lblHdl, *netHdl, *nodHdl)) { - //polyCache->lock.unlock(); + lock->unlock(); delete rgnHdl; delete lblHdl; delete netHdl; delete nodHdl; return; } @@ -170,19 +172,24 @@ void VectorTile::polys(const RectC &rect, const Zoom &zoom, } } - //polyCache->lock.unlock(); + lock->unlock(); delete rgnHdl; delete lblHdl; delete netHdl; delete nodHdl; delete nodHdl2; } void VectorTile::points(const RectC &rect, const Zoom &zoom, QList *points, QCache > *pointCache) + QList > *pointCache, QMutex *lock) { SubFile::Handle *rgnHdl = 0, *lblHdl = 0; - if (_loaded < 0) + lock->lock(); + + if (_loaded < 0) { + lock->unlock(); return; + } + if (!_loaded) { rgnHdl = new SubFile::Handle(_rgn); lblHdl = new SubFile::Handle(_lbl); @@ -190,6 +197,7 @@ void VectorTile::points(const RectC &rect, const Zoom &zoom, SubFile::Handle netHdl(_net); if (!load(*rgnHdl, *lblHdl, netHdl, nodHdl)) { + lock->unlock(); delete rgnHdl; delete lblHdl; return; } @@ -223,6 +231,8 @@ void VectorTile::points(const RectC &rect, const Zoom &zoom, copyPoints(rect, pl, points); } + lock->unlock(); + delete rgnHdl; delete lblHdl; } diff --git a/src/map/IMG/vectortile.h b/src/map/IMG/vectortile.h index 9e617434..9f0a4214 100644 --- a/src/map/IMG/vectortile.h +++ b/src/map/IMG/vectortile.h @@ -29,10 +29,10 @@ public: void polys(const RectC &rect, const Zoom &zoom, QList *polygons, QList *lines, - MapData::PolyCache *polyCache); + MapData::PolyCache *polyCache, QMutex *lock); void points(const RectC &rect, const Zoom &zoom, QList *points, QCache > *pointCache); + QList > *pointCache, QMutex *lock); static bool isTileFile(SubFile::Type type) {