mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-19 04:02:09 +01:00
Tile search can be done lock-free
This commit is contained in:
parent
a92d6efec6
commit
822a0c2866
@ -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<Poly> *polygons,
|
||||
QList<Poly> *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<Poly> *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<Point> *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<Point> *points)
|
||||
max[0] = rect.right();
|
||||
max[1] = rect.top();
|
||||
|
||||
_lock.lock();
|
||||
_tileTree.Search(min, max, pointCb, &ctx);
|
||||
_lock.unlock();
|
||||
}
|
||||
|
||||
void MapData::load()
|
||||
|
@ -105,27 +105,30 @@ private:
|
||||
{
|
||||
PolyCTX(const RectC &rect, const Zoom &zoom,
|
||||
QList<MapData::Poly> *polygons, QList<MapData::Poly> *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<MapData::Poly> *polygons;
|
||||
QList<MapData::Poly> *lines;
|
||||
PolyCache *polyCache;
|
||||
QMutex *lock;
|
||||
};
|
||||
|
||||
struct PointCTX
|
||||
{
|
||||
PointCTX(const RectC &rect, const Zoom &zoom,
|
||||
QList<MapData::Point> *points, PointCache *pointCache)
|
||||
: rect(rect), zoom(zoom), points(points), pointCache(pointCache) {}
|
||||
QList<MapData::Point> *points, PointCache *pointCache, QMutex *lock)
|
||||
: rect(rect), zoom(zoom), points(points), pointCache(pointCache),
|
||||
lock(lock) {}
|
||||
|
||||
const RectC ▭
|
||||
const Zoom &zoom;
|
||||
QList<MapData::Point> *points;
|
||||
PointCache *pointCache;
|
||||
QMutex *lock;
|
||||
};
|
||||
|
||||
const Zoom &zoom(int bits) const;
|
||||
|
@ -102,15 +102,17 @@ void VectorTile::clear()
|
||||
|
||||
void VectorTile::polys(const RectC &rect, const Zoom &zoom,
|
||||
QList<MapData::Poly> *polygons, QList<MapData::Poly> *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<MapData::Point> *points, QCache<const SubDiv *,
|
||||
QList<MapData::Point> > *pointCache)
|
||||
QList<MapData::Point> > *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;
|
||||
}
|
||||
|
||||
|
@ -29,10 +29,10 @@ public:
|
||||
|
||||
void polys(const RectC &rect, const Zoom &zoom,
|
||||
QList<MapData::Poly> *polygons, QList<MapData::Poly> *lines,
|
||||
MapData::PolyCache *polyCache);
|
||||
MapData::PolyCache *polyCache, QMutex *lock);
|
||||
void points(const RectC &rect, const Zoom &zoom,
|
||||
QList<MapData::Point> *points, QCache<const SubDiv*,
|
||||
QList<MapData::Point> > *pointCache);
|
||||
QList<MapData::Point> > *pointCache, QMutex *lock);
|
||||
|
||||
static bool isTileFile(SubFile::Type type)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user