diff --git a/Library/OSRM_impl.cpp b/Library/OSRM_impl.cpp index bbc09c5f5..d1e843298 100644 --- a/Library/OSRM_impl.cpp +++ b/Library/OSRM_impl.cpp @@ -58,11 +58,11 @@ namespace boost { namespace interprocess { class named_mutex; } } #include #include -OSRM_impl::OSRM_impl(ServerPaths server_paths, const bool use_shared_memory) : use_shared_memory(use_shared_memory) +OSRM_impl::OSRM_impl(ServerPaths server_paths, const bool use_shared_memory) { if (use_shared_memory) { - barrier = new SharedBarriers(); + barrier = osrm::make_unique(); query_data_facade = new SharedDataFacade(); } else @@ -88,10 +88,6 @@ OSRM_impl::~OSRM_impl() { delete plugin_pointer.second; } - if (use_shared_memory) - { - delete barrier; - } } void OSRM_impl::RegisterPlugin(BasePlugin *plugin) @@ -111,7 +107,7 @@ void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply) if (plugin_map.end() != iter) { reply.status = http::Reply::ok; - if (use_shared_memory) + if (barrier) { // lock update pending boost::interprocess::scoped_lock pending_lock( @@ -132,7 +128,7 @@ void OSRM_impl::RunQuery(RouteParameters &route_parameters, http::Reply &reply) } iter->second->HandleRequest(route_parameters, reply); - if (use_shared_memory) + if (barrier) { // lock query boost::interprocess::scoped_lock query_lock( diff --git a/Library/OSRM_impl.h b/Library/OSRM_impl.h index 803a5b065..a4af62cb6 100644 --- a/Library/OSRM_impl.h +++ b/Library/OSRM_impl.h @@ -36,6 +36,7 @@ struct RouteParameters; #include "../DataStructures/QueryEdge.h" +#include #include #include @@ -56,8 +57,8 @@ class OSRM_impl private: void RegisterPlugin(BasePlugin *plugin); PluginMap plugin_map; - bool use_shared_memory; - SharedBarriers *barrier; + // will only be initialized if shared memory is used + std::unique_ptr barrier; // base class pointer to the objects BaseDataFacade *query_data_facade; };