Use a shared (!) reader writer lock to protect CURRENT_REGIONS

This fixes issue #3016.
This commit is contained in:
Patrick Niklaus
2016-10-07 16:08:08 +02:00
committed by Patrick Niklaus
parent 036475afd0
commit 9eb7fc03ce
5 changed files with 30 additions and 94 deletions
+6 -5
View File
@@ -1,7 +1,6 @@
#ifndef ENGINE_HPP
#define ENGINE_HPP
#include "storage/shared_barriers.hpp"
#include "engine/status.hpp"
#include "util/json_container.hpp"
@@ -20,6 +19,11 @@ struct Object;
}
}
namespace storage
{
struct SharedBarriers;
}
// Fwd decls
namespace engine
{
@@ -52,9 +56,6 @@ class BaseDataFacade;
class Engine final
{
public:
// Needs to be public
struct EngineLock;
explicit Engine(const EngineConfig &config);
Engine(Engine &&) noexcept;
@@ -71,7 +72,7 @@ class Engine final
Status Tile(const api::TileParameters &parameters, std::string &result) const;
private:
std::unique_ptr<EngineLock> lock;
std::unique_ptr<storage::SharedBarriers> lock;
std::unique_ptr<plugins::ViaRoutePlugin> route_plugin;
std::unique_ptr<plugins::TablePlugin> table_plugin;
+3 -14
View File
@@ -3,6 +3,7 @@
#include <boost/interprocess/sync/named_condition.hpp>
#include <boost/interprocess/sync/named_mutex.hpp>
#include <boost/interprocess/sync/named_sharable_mutex.hpp>
namespace osrm
{
@@ -13,25 +14,13 @@ struct SharedBarriers
SharedBarriers()
: pending_update_mutex(boost::interprocess::open_or_create, "pending_update"),
update_mutex(boost::interprocess::open_or_create, "update"),
query_mutex(boost::interprocess::open_or_create, "query"),
no_running_queries_condition(boost::interprocess::open_or_create, "no_running_queries"),
update_ongoing(false), number_of_queries(0)
query_mutex(boost::interprocess::open_or_create, "query")
{
}
// Mutex to protect access to the boolean variable
boost::interprocess::named_mutex pending_update_mutex;
boost::interprocess::named_mutex update_mutex;
boost::interprocess::named_mutex query_mutex;
// Condition that no update is running
boost::interprocess::named_condition no_running_queries_condition;
// Is there an ongoing update?
bool update_ongoing;
// Is there any query?
int number_of_queries;
boost::interprocess::named_sharable_mutex query_mutex;
};
}
}