Skip to content

Commit

Permalink
do not instantiate shared memory facility in routed, fixes #905 and #910
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisOSRM committed Feb 11, 2014
1 parent 45a4fe4 commit 7794cd6
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 19 deletions.
23 changes: 14 additions & 9 deletions Library/OSRM_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/assert.hpp>
Expand All @@ -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<QueryEdge::EdgeData>( );
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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<SharedDataFacade<QueryEdge::EdgeData>* >(query_data_facade))->CheckAndReloadFacade();
}
Expand All @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions Library/OSRM_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/noncopyable.hpp>

struct SharedBarriers;
template<class EdgeDataT>
class BaseDataFacade;

class OSRM_impl : boost::noncopyable {
private:
typedef boost::unordered_map<std::string, BasePlugin *> PluginMap;
Expand All @@ -55,7 +57,7 @@ class OSRM_impl : boost::noncopyable {
void RegisterPlugin(BasePlugin * plugin);
PluginMap plugin_map;
bool use_shared_memory;
SharedBarriers barrier;
SharedBarriers * barrier;
//base class pointer to the objects
BaseDataFacade<QueryEdge::EdgeData> * query_data_facade;
};
Expand Down
20 changes: 13 additions & 7 deletions Plugins/NearestPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/unordered_map.hpp>

/*
* This Plugin locates the nearest point on a street in the road network for a given coordinate.
*/
Expand All @@ -44,11 +46,15 @@ class NearestPlugin : public BasePlugin {
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);
Expand Down Expand Up @@ -119,8 +125,8 @@ class NearestPlugin : public BasePlugin {

private:
DataFacadeT * facade;
HashTable<std::string, unsigned> descriptorTable;
boost::unordered_map<std::string, unsigned> descriptorTable;
std::string descriptor_string;
};

#endif /* NearestPlugin_H_ */
#endif /* NEAREST_PLUGIN_H */
32 changes: 32 additions & 0 deletions Server/DataStructures/SharedBarriers.h
Original file line number Diff line number Diff line change
@@ -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 <boost/interprocess/sync/named_mutex.hpp>
#include <boost/interprocess/sync/named_condition.hpp>

Expand Down Expand Up @@ -38,3 +68,5 @@ struct SharedBarriers {
// Is there any query?
int number_of_queries;
};

#endif //SHARED_BARRIER_H

0 comments on commit 7794cd6

Please sign in to comment.