Skip to content

Commit

Permalink
[pal] Switch use of PAL's own mutex to QMutex
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 29, 2015
1 parent e804a87 commit e0b9f53
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 124 deletions.
18 changes: 7 additions & 11 deletions src/core/pal/layer.cpp
Expand Up @@ -49,8 +49,6 @@
#include "geomfunction.h"
#include "util.h"

#include "simplemutex.h"

namespace pal
{

Expand All @@ -74,8 +72,6 @@ namespace pal
this->name = new char[strlen( lyrName ) +1];
strcpy( this->name, lyrName );

modMutex = new SimpleMutex();

rtree = new RTree<FeaturePart*, double, 2, double>();
hashtable = new HashTable<Feature*> ( 5281 );

Expand All @@ -95,7 +91,7 @@ namespace pal

Layer::~Layer()
{
modMutex->lock();
mMutex.lock();

if ( featureParts )
{
Expand Down Expand Up @@ -126,7 +122,7 @@ namespace pal
delete rtree;

delete hashtable;
delete modMutex;
mMutex.unlock();
delete connectedTexts;
}

Expand Down Expand Up @@ -240,11 +236,11 @@ namespace pal
if ( !geom_id || label_x < 0 || label_y < 0 )
return false;

modMutex->lock();
mMutex.lock();

if ( hashtable->find( geom_id ) )
{
modMutex->unlock();
mMutex.unlock();
//A feature with this id already exists. Don't throw an exception as sometimes,
//the same feature is added twice (dateline split with otf-reprojection)
return false;
Expand Down Expand Up @@ -288,7 +284,7 @@ namespace pal
LinkedList <const GEOSGeometry*> *simpleGeometries = unmulti( the_geom );
if ( simpleGeometries == NULL ) // unmulti() failed?
{
modMutex->unlock();
mMutex.unlock();
throw InternalException::UnknownGeometry();
}

Expand All @@ -309,7 +305,7 @@ namespace pal

if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON )
{
modMutex->unlock();
mMutex.unlock();
throw InternalException::UnknownGeometry();
}

Expand Down Expand Up @@ -356,7 +352,7 @@ namespace pal

userGeom->releaseGeosGeometry( the_geom );

modMutex->unlock();
mMutex.unlock();

// if using only biggest parts...
if (( mode == LabelPerFeature || f->fixedPosition() ) && biggest_part != NULL )
Expand Down
4 changes: 2 additions & 2 deletions src/core/pal/layer.h
Expand Up @@ -34,6 +34,7 @@

#include <pal/pal.h>
#include <pal/palgeometry.h>
#include <QMutex>

namespace pal
{
Expand All @@ -47,7 +48,6 @@ namespace pal
class Feature;
class FeaturePart;
class Pal;
class SimpleMutex;
class LabelInfo;

/**
Expand Down Expand Up @@ -297,7 +297,7 @@ namespace pal
HashTable< LinkedList<FeaturePart*>* > * connectedHashtable;
LinkedList< char* >* connectedTexts;

SimpleMutex *modMutex;
QMutex mMutex;

/**
* \brief Create a new layer
Expand Down
39 changes: 18 additions & 21 deletions src/core/pal/pal.cpp
Expand Up @@ -56,7 +56,6 @@
#include "labelposition.h"
#include "problem.h"
#include "pointset.h"
#include "simplemutex.h"
#include "util.h"

#include <qgsgeometry.h> // for GEOS context
Expand Down Expand Up @@ -95,8 +94,6 @@ namespace pal

layers = new QList<Layer*>();

lyrsMutex = new SimpleMutex();

ejChainDeg = 50;
tenure = 10;
candListSize = 0.2;
Expand Down Expand Up @@ -132,43 +129,43 @@ namespace pal

Layer *Pal::getLayer( const char *lyrName )
{
lyrsMutex->lock();
mMutex.lock();
for ( QList<Layer*>::iterator it = layers->begin(); it != layers->end(); ++it )
if ( strcmp(( *it )->name, lyrName ) == 0 )
{
lyrsMutex->unlock();
mMutex.unlock();
return *it;
}

lyrsMutex->unlock();
mMutex.unlock();
throw new PalException::UnknownLayer();
}


void Pal::removeLayer( Layer *layer )
{
lyrsMutex->lock();
mMutex.lock();
if ( layer )
{
layers->removeOne( layer );
delete layer;
}
lyrsMutex->unlock();
mMutex.unlock();
}


Pal::~Pal()
{

lyrsMutex->lock();
mMutex.lock();
while ( layers->size() > 0 )
{
delete layers->front();
layers->pop_front();
}

delete layers;
delete lyrsMutex;
mMutex.unlock();

// do not init and exit GEOS - we do it inside QGIS
//finishGEOS();
Expand All @@ -178,7 +175,7 @@ namespace pal
Layer * Pal::addLayer( const char *lyrName, double min_scale, double max_scale, Arrangement arrangement, Units label_unit, double defaultPriority, bool obstacle, bool active, bool toLabel, bool displayAll )
{
Layer *lyr;
lyrsMutex->lock();
mMutex.lock();

#ifdef _DEBUG_
std::cout << "Pal::addLayer" << std::endl;
Expand All @@ -190,7 +187,7 @@ namespace pal
{
if ( strcmp(( *it )->name, lyrName ) == 0 ) // if layer already known
{
lyrsMutex->unlock();
mMutex.unlock();
//There is already a layer with this name, so we just return the existing one.
//Sometimes the same layer is added twice (e.g. datetime split with otf-reprojection)
return *it;
Expand All @@ -200,7 +197,7 @@ namespace pal
lyr = new Layer( lyrName, min_scale, max_scale, arrangement, label_unit, defaultPriority, obstacle, active, toLabel, this, displayAll );
layers->push_back( lyr );

lyrsMutex->unlock();
mMutex.unlock();

return lyr;
}
Expand Down Expand Up @@ -416,7 +413,7 @@ namespace pal

QList<char*> *labLayers = new QList<char*>();

lyrsMutex->lock();
mMutex.lock();
for ( i = 0; i < nbLayers; i++ )
{
for ( QList<Layer*>::iterator it = layers->begin(); it != layers->end(); ++it ) // iterate on pal->layers
Expand Down Expand Up @@ -447,9 +444,9 @@ namespace pal
<< " id=\"" << layer->name << "\">" << std::endl << std::endl;
#endif

context->layer->modMutex->lock();
context->layer->mMutex.lock();
context->layer->rtree->Search( amin, amax, extractFeatCallback, ( void* ) context );
context->layer->modMutex->unlock();
context->layer->mMutex.unlock();

#ifdef _EXPORT_MAP_
*svgmap << "</g>" << std::endl << std::endl;
Expand Down Expand Up @@ -479,7 +476,7 @@ namespace pal
}
}
delete context;
lyrsMutex->unlock();
mMutex.unlock();

prob->nbLabelledLayers = labLayers->size();
prob->labelledLayersName = new char*[prob->nbLabelledLayers];
Expand Down Expand Up @@ -665,7 +662,7 @@ namespace pal
#endif
int i;

lyrsMutex->lock();
mMutex.lock();
int nbLayers = layers->size();

char **layersName = new char*[nbLayers];
Expand All @@ -679,7 +676,7 @@ namespace pal
priorities[i] = layer->defaultPriority;
i++;
}
lyrsMutex->unlock();
mMutex.unlock();

std::list<LabelPosition*> * solution = labeller( nbLayers, layersName, priorities, scale, bbox, stats, displayAll );

Expand Down Expand Up @@ -836,7 +833,7 @@ namespace pal
Problem* Pal::extractProblem( double scale, double bbox[4] )
{
// find out: nbLayers, layersName, layersFactor
lyrsMutex->lock();
mMutex.lock();
int nbLayers = layers->size();

char **layersName = new char*[nbLayers];
Expand All @@ -850,7 +847,7 @@ namespace pal
priorities[i] = layer->defaultPriority;
i++;
}
lyrsMutex->unlock();
mMutex.unlock();

Problem* prob = extract( nbLayers, layersName, priorities, bbox[0], bbox[1], bbox[2], bbox[3], scale, NULL );

Expand Down
4 changes: 2 additions & 2 deletions src/core/pal/pal.h
Expand Up @@ -34,6 +34,7 @@
#include <iostream>
#include <ctime>
#include <geos_c.h>
#include <QMutex>

// TODO ${MAJOR} ${MINOR} etc instead of 0.2

Expand All @@ -57,7 +58,6 @@ namespace pal
class PalStat;
class Problem;
class PointSet;
class SimpleMutex;

/** Units for label sizes and distlabel */
enum _Units
Expand Down Expand Up @@ -327,7 +327,7 @@ namespace pal
private:
QList<Layer*> *layers;

SimpleMutex *lyrsMutex;
QMutex mMutex;

Units map_unit;

Expand Down
88 changes: 0 additions & 88 deletions src/core/pal/simplemutex.h

This file was deleted.

0 comments on commit e0b9f53

Please sign in to comment.