Skip to content
Permalink
Browse files

[pal] Switch use of PAL's own mutex to QMutex

  • Loading branch information
nyalldawson committed Jun 27, 2015
1 parent e804a87 commit e0b9f538fa49be0e19679bd8b9e75ca53a29d106
Showing with 29 additions and 124 deletions.
  1. +7 −11 src/core/pal/layer.cpp
  2. +2 −2 src/core/pal/layer.h
  3. +18 −21 src/core/pal/pal.cpp
  4. +2 −2 src/core/pal/pal.h
  5. +0 −88 src/core/pal/simplemutex.h
@@ -49,8 +49,6 @@
#include "geomfunction.h"
#include "util.h"

#include "simplemutex.h"

namespace pal
{

@@ -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 );

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

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

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

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

@@ -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;
@@ -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();
}

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

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

@@ -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 )
@@ -34,6 +34,7 @@

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

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

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

SimpleMutex *modMutex;
QMutex mMutex;

/**
* \brief Create a new layer
@@ -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
@@ -95,8 +94,6 @@ namespace pal

layers = new QList<Layer*>();

lyrsMutex = new SimpleMutex();

ejChainDeg = 50;
tenure = 10;
candListSize = 0.2;
@@ -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();
@@ -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;
@@ -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;
@@ -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;
}
@@ -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
@@ -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;
@@ -479,7 +476,7 @@ namespace pal
}
}
delete context;
lyrsMutex->unlock();
mMutex.unlock();

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

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

char **layersName = new char*[nbLayers];
@@ -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 );

@@ -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];
@@ -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 );

@@ -34,6 +34,7 @@
#include <iostream>
#include <ctime>
#include <geos_c.h>
#include <QMutex>

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

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

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

SimpleMutex *lyrsMutex;
QMutex mMutex;

Units map_unit;

This file was deleted.

0 comments on commit e0b9f53

Please sign in to comment.
You can’t perform that action at this time.