mirror of
https://github.com/mapnik/mapnik.git
synced 2025-12-08 20:13:09 +00:00
use std::lock_guard instead of unique_lock (better fit for the job)
This commit is contained in:
parent
433741877d
commit
a8a90b7656
@ -25,7 +25,6 @@
|
||||
|
||||
// mapnik (should not depend on anything that need to use this)
|
||||
#include <mapnik/config.hpp>
|
||||
#include <mapnik/unique_lock.hpp>
|
||||
#include <mapnik/utils.hpp>
|
||||
#include <mapnik/util/noncopyable.hpp>
|
||||
|
||||
@ -70,7 +69,7 @@ namespace mapnik {
|
||||
static void set_severity(severity_type const& severity_level)
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(severity_mutex_);
|
||||
std::lock_guard<std::mutex> lock(severity_mutex_);
|
||||
#endif
|
||||
|
||||
severity_level_ = severity_level;
|
||||
@ -94,7 +93,7 @@ namespace mapnik {
|
||||
severity_type const& security_level)
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(severity_mutex_);
|
||||
std::lock_guard<std::mutex> lock(severity_mutex_);
|
||||
#endif
|
||||
if (! object_name.empty())
|
||||
{
|
||||
@ -105,7 +104,7 @@ namespace mapnik {
|
||||
static void clear_object_severity()
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(severity_mutex_);
|
||||
std::lock_guard<std::mutex> lock(severity_mutex_);
|
||||
#endif
|
||||
|
||||
object_severity_level_.clear();
|
||||
@ -120,7 +119,7 @@ namespace mapnik {
|
||||
static void set_format(std::string const& format)
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(format_mutex_);
|
||||
std::lock_guard<std::mutex> lock(format_mutex_);
|
||||
#endif
|
||||
format_ = format;
|
||||
}
|
||||
@ -166,7 +165,7 @@ namespace mapnik {
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
static std::mutex mutex;
|
||||
mapnik::scoped_lock lock(mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
#endif
|
||||
std::clog << logger::str() << " " << s.str() << std::endl;
|
||||
}
|
||||
|
||||
@ -24,7 +24,6 @@
|
||||
#define MAPNIK_POOL_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/unique_lock.hpp>
|
||||
#include <mapnik/utils.hpp>
|
||||
#include <mapnik/util/noncopyable.hpp>
|
||||
|
||||
@ -71,7 +70,7 @@ public:
|
||||
HolderType borrowObject()
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
|
||||
typename ContType::iterator itr=pool_.begin();
|
||||
@ -106,7 +105,7 @@ public:
|
||||
unsigned size() const
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
return pool_.size();
|
||||
}
|
||||
@ -114,7 +113,7 @@ public:
|
||||
unsigned max_size() const
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
return maxSize_;
|
||||
}
|
||||
@ -122,7 +121,7 @@ public:
|
||||
void set_max_size(unsigned size)
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
maxSize_ = std::max(maxSize_,size);
|
||||
}
|
||||
@ -130,7 +129,7 @@ public:
|
||||
unsigned initial_size() const
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
return initialSize_;
|
||||
}
|
||||
@ -138,7 +137,7 @@ public:
|
||||
void set_initial_size(unsigned size)
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
if (size > initialSize_)
|
||||
{
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2014 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef MAPNIK_UNIQUE_LOCK_HPP
|
||||
#define MAPNIK_UNIQUE_LOCK_HPP
|
||||
|
||||
#include <mutex>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
using scoped_lock = std::unique_lock<std::mutex>;
|
||||
}
|
||||
|
||||
#endif // MAPNIK_UNIQUE_LOCK_HPP
|
||||
@ -24,7 +24,6 @@
|
||||
#define MAPNIK_UTILS_HPP
|
||||
|
||||
#include <mapnik/config.hpp>
|
||||
#include <mapnik/unique_lock.hpp>
|
||||
|
||||
// stl
|
||||
#include <stdexcept> // std::runtime_error
|
||||
@ -123,7 +122,7 @@ protected:
|
||||
if (! pInstance_)
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
if (! pInstance_)
|
||||
{
|
||||
|
||||
@ -89,7 +89,7 @@ datasource_ptr datasource_cache::create(parameters const& params)
|
||||
// add scope to ensure lock is released asap
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
itr=plugins_.find(*type);
|
||||
if (itr == plugins_.end())
|
||||
@ -156,7 +156,7 @@ std::vector<std::string> datasource_cache::plugin_names()
|
||||
bool datasource_cache::register_datasources(std::string const& dir, bool recurse)
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
if (!mapnik::util::exists(dir))
|
||||
{
|
||||
|
||||
@ -84,7 +84,7 @@ unsigned long ft_read_cb(FT_Stream stream, unsigned long offset, unsigned char *
|
||||
bool freetype_engine::register_font(std::string const& file_name)
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
font_library library;
|
||||
return register_font_impl(file_name, library, global_font_file_mapping_);
|
||||
@ -166,7 +166,7 @@ bool freetype_engine::register_font_impl(std::string const& file_name,
|
||||
bool freetype_engine::register_fonts(std::string const& dir, bool recurse)
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
font_library library;
|
||||
return register_fonts_impl(dir, library, global_font_file_mapping_, recurse);
|
||||
@ -338,7 +338,7 @@ face_ptr freetype_engine::create_face(std::string const& family_name,
|
||||
if (file.open())
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
auto result = global_memory_fonts.emplace(itr->second.second, std::make_pair(std::move(file.data()),file.size()));
|
||||
FT_Face face;
|
||||
|
||||
@ -38,7 +38,7 @@ namespace mapnik
|
||||
void mapped_memory_cache::clear()
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
return cache_.clear();
|
||||
}
|
||||
@ -46,7 +46,7 @@ void mapped_memory_cache::clear()
|
||||
bool mapped_memory_cache::insert(std::string const& uri, mapped_region_ptr mem)
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
return cache_.emplace(uri,mem).second;
|
||||
}
|
||||
@ -54,7 +54,7 @@ bool mapped_memory_cache::insert(std::string const& uri, mapped_region_ptr mem)
|
||||
boost::optional<mapped_region_ptr> mapped_memory_cache::find(std::string const& uri, bool update_cache)
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
using iterator_type = std::unordered_map<std::string, mapped_region_ptr>::const_iterator;
|
||||
boost::optional<mapped_region_ptr> result;
|
||||
|
||||
@ -70,7 +70,7 @@ marker_cache::~marker_cache() {}
|
||||
void marker_cache::clear()
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
using iterator_type = boost::unordered_map<std::string, std::shared_ptr<mapnik::marker const> >::const_iterator;
|
||||
iterator_type itr = marker_cache_.begin();
|
||||
@ -112,7 +112,7 @@ bool marker_cache::insert_svg(std::string const& name, std::string const& svg_st
|
||||
bool marker_cache::insert_marker(std::string const& uri, mapnik::marker && path)
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
return marker_cache_.emplace(uri,std::make_shared<mapnik::marker const>(std::move(path))).second;
|
||||
}
|
||||
@ -137,7 +137,7 @@ struct visitor_create_marker
|
||||
marker operator() (T & data)
|
||||
{
|
||||
throw std::runtime_error("Can not make marker from this data type");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // end detail ns
|
||||
@ -151,7 +151,7 @@ std::shared_ptr<mapnik::marker const> marker_cache::find(std::string const& uri,
|
||||
}
|
||||
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
using iterator_type = boost::unordered_map<std::string, std::shared_ptr<mapnik::marker const> >::const_iterator;
|
||||
iterator_type itr = marker_cache_.find(uri);
|
||||
|
||||
@ -120,7 +120,7 @@ void projection::init_proj4() const
|
||||
}
|
||||
#else
|
||||
#if defined(MAPNIK_THREADSAFE)
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
proj_ = pj_init_plus(params_.c_str());
|
||||
if (!proj_) throw proj_init_error(params_);
|
||||
@ -158,7 +158,7 @@ void projection::forward(double & x, double &y ) const
|
||||
throw std::runtime_error("projection::forward not supported unless proj4 is initialized");
|
||||
}
|
||||
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
projUV p;
|
||||
p.u = x * DEG_TO_RAD;
|
||||
@ -185,7 +185,7 @@ void projection::inverse(double & x,double & y) const
|
||||
}
|
||||
|
||||
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
if (is_geographic_)
|
||||
{
|
||||
@ -207,7 +207,7 @@ projection::~projection()
|
||||
{
|
||||
#ifdef MAPNIK_USE_PROJ4
|
||||
#if defined(MAPNIK_THREADSAFE) && PJ_VERSION < 480
|
||||
mapnik::scoped_lock lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
#endif
|
||||
if (proj_)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user