From 7794cd62743d3626babf3ac3c8cb69398751a04b Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 11 Feb 2014 11:35:29 +0100 Subject: [PATCH] do not instantiate shared memory facility in routed, fixes #905 and #910 --- Library/OSRM_impl.cpp | 23 ++++++++++-------- Library/OSRM_impl.h | 8 ++++--- Plugins/NearestPlugin.h | 20 ++++++++++------ Server/DataStructures/SharedBarriers.h | 32 ++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 19 deletions(-) diff --git a/Library/OSRM_impl.cpp b/Library/OSRM_impl.cpp index 448823d94..cee96f742 100644 --- a/Library/OSRM_impl.cpp +++ b/Library/OSRM_impl.cpp @@ -34,8 +34,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../Plugins/TimestampPlugin.h" #include "../Plugins/ViaRoutePlugin.h" - +#include "../Server/DataStructures/BaseDataFacade.h" #include "../Server/DataStructures/InternalDataFacade.h" +#include "../Server/DataStructures/SharedBarriers.h" #include "../Server/DataStructures/SharedDataFacade.h" #include @@ -49,6 +50,7 @@ OSRM_impl::OSRM_impl( const ServerPaths & server_paths, const bool use_shared_me server_paths ); } else { + barrier = new SharedBarriers(); query_data_facade = new SharedDataFacade( ); } @@ -82,6 +84,9 @@ OSRM_impl::~OSRM_impl() { BOOST_FOREACH(PluginMap::value_type & plugin_pointer, plugin_map) { delete plugin_pointer.second; } + if( use_shared_memory ) { + delete barrier; + } } void OSRM_impl::RegisterPlugin(BasePlugin * plugin) { @@ -103,18 +108,18 @@ void OSRM_impl::RunQuery(RouteParameters & route_parameters, http::Reply & reply // lock update pending boost::interprocess::scoped_lock< boost::interprocess::named_mutex - > pending_lock(barrier.pending_update_mutex); + > pending_lock(barrier->pending_update_mutex); // lock query boost::interprocess::scoped_lock< boost::interprocess::named_mutex - > query_lock(barrier.query_mutex); + > query_lock(barrier->query_mutex); // unlock update pending pending_lock.unlock(); // increment query count - ++(barrier.number_of_queries); + ++(barrier->number_of_queries); (static_cast* >(query_data_facade))->CheckAndReloadFacade(); } @@ -124,18 +129,18 @@ void OSRM_impl::RunQuery(RouteParameters & route_parameters, http::Reply & reply // lock query boost::interprocess::scoped_lock< boost::interprocess::named_mutex - > query_lock(barrier.query_mutex); + > query_lock(barrier->query_mutex); // decrement query count - --(barrier.number_of_queries); + --(barrier->number_of_queries); BOOST_ASSERT_MSG( - 0 <= barrier.number_of_queries, + 0 <= barrier->number_of_queries, "invalid number of queries" ); // notify all processes that were waiting for this condition - if (0 == barrier.number_of_queries) { - barrier.no_running_queries_condition.notify_all(); + if (0 == barrier->number_of_queries) { + barrier->no_running_queries_condition.notify_all(); } } } else { diff --git a/Library/OSRM_impl.h b/Library/OSRM_impl.h index df09ad38f..a96071b54 100644 --- a/Library/OSRM_impl.h +++ b/Library/OSRM_impl.h @@ -34,12 +34,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../DataStructures/QueryEdge.h" #include "../Plugins/BasePlugin.h" -#include "../Server/DataStructures/SharedBarriers.h" -#include "../Server/DataStructures/BaseDataFacade.h" #include "../Util/ProgramOptions.h" #include +struct SharedBarriers; +template +class BaseDataFacade; + class OSRM_impl : boost::noncopyable { private: typedef boost::unordered_map PluginMap; @@ -55,7 +57,7 @@ private: void RegisterPlugin(BasePlugin * plugin); PluginMap plugin_map; bool use_shared_memory; - SharedBarriers barrier; + SharedBarriers * barrier; //base class pointer to the objects BaseDataFacade * query_data_facade; }; diff --git a/Plugins/NearestPlugin.h b/Plugins/NearestPlugin.h index 4c765cf96..5a4bcbab7 100644 --- a/Plugins/NearestPlugin.h +++ b/Plugins/NearestPlugin.h @@ -25,13 +25,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef NearestPlugin_H_ -#define NearestPlugin_H_ +#ifndef NEAREST_PLUGIN_H +#define NEAREST_PLUGIN_H #include "BasePlugin.h" #include "../DataStructures/PhantomNodes.h" #include "../Util/StringUtil.h" +#include + /* * This Plugin locates the nearest point on a street in the road network for a given coordinate. */ @@ -44,11 +46,15 @@ public: facade(facade), descriptor_string("nearest") { - descriptorTable.insert(std::make_pair("" , 0)); //default descriptor - descriptorTable.insert(std::make_pair("json", 1)); + descriptorTable.emplace("", 0); //default descriptor + descriptorTable.emplace("json", 1); } const std::string & GetDescriptor() const { return descriptor_string; } - void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { + + void HandleRequest( + const RouteParameters & routeParameters, + http::Reply& reply + ) { //check number of parameters if(!routeParameters.coordinates.size()) { reply = http::Reply::StockReply(http::Reply::badRequest); @@ -119,8 +125,8 @@ public: private: DataFacadeT * facade; - HashTable descriptorTable; + boost::unordered_map descriptorTable; std::string descriptor_string; }; -#endif /* NearestPlugin_H_ */ +#endif /* NEAREST_PLUGIN_H */ diff --git a/Server/DataStructures/SharedBarriers.h b/Server/DataStructures/SharedBarriers.h index c11f121f3..9e38f51b5 100644 --- a/Server/DataStructures/SharedBarriers.h +++ b/Server/DataStructures/SharedBarriers.h @@ -1,3 +1,33 @@ +/* + +Copyright (c) 2013, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef SHARED_BARRIER_H +#define SHARED_BARRIER_H + #include #include @@ -38,3 +68,5 @@ struct SharedBarriers { // Is there any query? int number_of_queries; }; + +#endif //SHARED_BARRIER_H