mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-27 21:24:47 +01:00
Use parallel ENC maps data loading in ENC atlases
This commit is contained in:
parent
8b51f3ff04
commit
1186cb104b
@ -2,45 +2,71 @@
|
||||
|
||||
using namespace ENC;
|
||||
|
||||
bool AtlasData::pointCb(const QString *map, void *context)
|
||||
bool AtlasData::pointCb(MapEntry *map, void *context)
|
||||
{
|
||||
PointCTX *ctx = (PointCTX*)context;
|
||||
|
||||
ctx->lock.lock();
|
||||
start:
|
||||
ctx->cacheLock.lock();
|
||||
|
||||
MapData *cached = ctx->cache.object(map);
|
||||
MapData *cached = ctx->cache.object(map->path);
|
||||
|
||||
if (!cached) {
|
||||
MapData *data = new MapData(*map);
|
||||
ctx->cacheLock.unlock();
|
||||
|
||||
if (map->lock.tryLock()) {
|
||||
MapData *data = new MapData(map->path);
|
||||
data->points(ctx->rect, ctx->points);
|
||||
ctx->cache.insert(map, data);
|
||||
|
||||
ctx->cacheLock.lock();
|
||||
ctx->cache.insert(map->path, data);
|
||||
|
||||
map->lock.unlock();
|
||||
} else {
|
||||
map->lock.lock();
|
||||
map->lock.unlock();
|
||||
goto start;
|
||||
}
|
||||
} else
|
||||
cached->points(ctx->rect, ctx->points);
|
||||
|
||||
ctx->lock.unlock();
|
||||
ctx->cacheLock.unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AtlasData::polyCb(const QString *map, void *context)
|
||||
bool AtlasData::polyCb(MapEntry *map, void *context)
|
||||
{
|
||||
PolyCTX *ctx = (PolyCTX*)context;
|
||||
|
||||
ctx->lock.lock();
|
||||
start:
|
||||
ctx->cacheLock.lock();
|
||||
|
||||
MapData *cached = ctx->cache.object(map);
|
||||
MapData *cached = ctx->cache.object(map->path);
|
||||
|
||||
if (!cached) {
|
||||
MapData *data = new MapData(*map);
|
||||
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);
|
||||
ctx->cache.insert(map, data);
|
||||
|
||||
ctx->cacheLock.lock();
|
||||
ctx->cache.insert(map->path, data);
|
||||
|
||||
map->lock.unlock();
|
||||
} else {
|
||||
map->lock.lock();
|
||||
map->lock.unlock();
|
||||
goto start;
|
||||
}
|
||||
} else {
|
||||
cached->polygons(ctx->rect, ctx->polygons);
|
||||
cached->lines(ctx->rect, ctx->lines);
|
||||
}
|
||||
|
||||
ctx->lock.unlock();
|
||||
ctx->cacheLock.unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -61,14 +87,14 @@ void AtlasData::addMap(const RectC &bounds, const QString &path)
|
||||
max[0] = bounds.right();
|
||||
max[1] = bounds.top();
|
||||
|
||||
_tree.Insert(min, max, new QString(path));
|
||||
_tree.Insert(min, max, new MapEntry(path));
|
||||
}
|
||||
|
||||
void AtlasData::polys(const RectC &rect, QList<MapData::Poly> *polygons,
|
||||
QList<MapData::Line> *lines)
|
||||
{
|
||||
double min[2], max[2];
|
||||
PolyCTX polyCtx(rect, polygons, lines, _cache, _lock);
|
||||
PolyCTX polyCtx(rect, polygons, lines, _cache, _cacheLock);
|
||||
|
||||
min[0] = rect.left();
|
||||
min[1] = rect.bottom();
|
||||
@ -81,7 +107,7 @@ void AtlasData::polys(const RectC &rect, QList<MapData::Poly> *polygons,
|
||||
void AtlasData::points(const RectC &rect, QList<MapData::Point> *points)
|
||||
{
|
||||
double min[2], max[2];
|
||||
PointCTX pointCtx(rect, points, _cache, _lock);
|
||||
PointCTX pointCtx(rect, points, _cache, _cacheLock);
|
||||
|
||||
min[0] = rect.left();
|
||||
min[1] = rect.bottom();
|
||||
|
@ -8,13 +8,13 @@
|
||||
|
||||
namespace ENC {
|
||||
|
||||
typedef QCache<const QString*, MapData> MapCache;
|
||||
typedef QCache<QString, MapData> MapCache;
|
||||
|
||||
class AtlasData
|
||||
{
|
||||
public:
|
||||
AtlasData(MapCache &cache, QMutex &lock)
|
||||
: _cache(cache), _lock(lock) {}
|
||||
AtlasData(MapCache &cache, QMutex &cacheLock)
|
||||
: _cache(cache), _cacheLock(cacheLock) {}
|
||||
~AtlasData();
|
||||
|
||||
void addMap(const RectC &bounds, const QString &path);
|
||||
@ -24,40 +24,47 @@ public:
|
||||
void points(const RectC &rect, QList<MapData::Point> *points);
|
||||
|
||||
private:
|
||||
typedef RTree<const QString*, double, 2> MapTree;
|
||||
struct MapEntry {
|
||||
MapEntry(const QString &path) : path(path) {}
|
||||
|
||||
QString path;
|
||||
QMutex lock;
|
||||
};
|
||||
|
||||
typedef RTree<MapEntry*, double, 2> MapTree;
|
||||
|
||||
struct PolyCTX
|
||||
{
|
||||
PolyCTX(const RectC &rect, QList<MapData::Poly> *polygons,
|
||||
QList<MapData::Line> *lines, MapCache &cache, QMutex &lock)
|
||||
QList<MapData::Line> *lines, MapCache &cache, QMutex &cacheLock)
|
||||
: rect(rect), polygons(polygons), lines(lines), cache(cache),
|
||||
lock(lock) {}
|
||||
cacheLock(cacheLock) {}
|
||||
|
||||
const RectC ▭
|
||||
QList<MapData::Poly> *polygons;
|
||||
QList<MapData::Line> *lines;
|
||||
MapCache &cache;
|
||||
QMutex &lock;
|
||||
QMutex &cacheLock;
|
||||
};
|
||||
|
||||
struct PointCTX
|
||||
{
|
||||
PointCTX(const RectC &rect, QList<MapData::Point> *points,
|
||||
MapCache &cache, QMutex &lock) : rect(rect), points(points),
|
||||
cache(cache), lock(lock) {}
|
||||
MapCache &cache, QMutex &cacheLock)
|
||||
: rect(rect), points(points), cache(cache), cacheLock(cacheLock) {}
|
||||
|
||||
const RectC ▭
|
||||
QList<MapData::Point> *points;
|
||||
MapCache &cache;
|
||||
QMutex &lock;
|
||||
QMutex &cacheLock;
|
||||
};
|
||||
|
||||
static bool polyCb(const QString *map, void *context);
|
||||
static bool pointCb(const QString *map, void *context);
|
||||
static bool polyCb(MapEntry *map, void *context);
|
||||
static bool pointCb(MapEntry *map, void *context);
|
||||
|
||||
MapTree _tree;
|
||||
MapCache &_cache;
|
||||
QMutex &_lock;
|
||||
QMutex &_cacheLock;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ void ENCAtlas::addMap(const QDir &dir, const QByteArray &file,
|
||||
IntendedUsage iu = usage(path);
|
||||
auto it = _data.find(iu);
|
||||
if (it == _data.end())
|
||||
it = _data.insert(iu, new AtlasData(_cache, _lock));
|
||||
it = _data.insert(iu, new AtlasData(_cache, _cacheLock));
|
||||
|
||||
it.value()->addMap(bounds, path);
|
||||
|
||||
|
@ -89,7 +89,7 @@ private:
|
||||
QMap<IntendedUsage, ENC::AtlasData*> _data;
|
||||
ENC::Style *_style;
|
||||
ENC::MapCache _cache;
|
||||
QMutex _lock;
|
||||
QMutex _cacheLock;
|
||||
IntendedUsage _usage;
|
||||
int _zoom;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user