finished locking implementation in queries. YAY\!
This commit is contained in:
parent
0d1149310c
commit
6ae880f61e
@ -29,11 +29,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
OSRM::OSRM( const ServerPaths & server_paths, const bool use_shared_memory )
|
||||
:
|
||||
shm(
|
||||
boost::interprocess::open_or_create,
|
||||
"SharedBarriers",
|
||||
boost::interprocess::read_write
|
||||
),
|
||||
use_shared_memory(use_shared_memory)
|
||||
{
|
||||
if( !use_shared_memory ) {
|
||||
@ -42,13 +37,6 @@ OSRM::OSRM( const ServerPaths & server_paths, const bool use_shared_memory )
|
||||
server_paths
|
||||
);
|
||||
} else {
|
||||
region = boost::interprocess::mapped_region(
|
||||
shm, //What to map
|
||||
boost::interprocess::read_write //Map it as read-write
|
||||
);
|
||||
shm.truncate( sizeof(SharedBarriers) );
|
||||
barrier = static_cast<SharedBarriers *>( region.get_address() );
|
||||
|
||||
SimpleLogger().Write() << "loading data from shared memory";
|
||||
query_data_facade = new SharedDataFacade<QueryEdge::EdgeData>(
|
||||
server_paths
|
||||
@ -97,6 +85,7 @@ void OSRM::RegisterPlugin(BasePlugin * plugin) {
|
||||
}
|
||||
|
||||
void OSRM::RunQuery(RouteParameters & route_parameters, http::Reply & reply) {
|
||||
SimpleLogger().Write() << "running query";
|
||||
const PluginMap::const_iterator & iter = plugin_map.find(
|
||||
route_parameters.service
|
||||
);
|
||||
@ -104,39 +93,50 @@ void OSRM::RunQuery(RouteParameters & route_parameters, http::Reply & reply) {
|
||||
if(plugin_map.end() != iter) {
|
||||
reply.status = http::Reply::ok;
|
||||
if( use_shared_memory ) {
|
||||
SimpleLogger().Write() << "shared memory handling";
|
||||
// lock update pending
|
||||
boost::interprocess::scoped_lock<
|
||||
boost::interprocess::named_mutex
|
||||
> pending_lock(barrier->pending_update_mutex);
|
||||
> pending_lock(barrier.pending_update_mutex);
|
||||
|
||||
SimpleLogger().Write() << "got pending lock";
|
||||
|
||||
// lock query
|
||||
boost::interprocess::scoped_lock<
|
||||
boost::interprocess::named_mutex
|
||||
> query_lock(barrier->query_mutex);
|
||||
> query_lock(barrier.query_mutex);
|
||||
|
||||
SimpleLogger().Write() << "got query lock";
|
||||
|
||||
// unlock update pending
|
||||
pending_lock.unlock();
|
||||
SimpleLogger().Write() << "released pending lock";
|
||||
|
||||
// increment query count
|
||||
++(barrier->number_of_queries);
|
||||
++(barrier.number_of_queries);
|
||||
}
|
||||
|
||||
iter->second->HandleRequest(route_parameters, reply );
|
||||
SimpleLogger().Write() << "finished request";
|
||||
if( use_shared_memory ) {
|
||||
// lock query
|
||||
boost::interprocess::scoped_lock<
|
||||
boost::interprocess::named_mutex
|
||||
> query_lock(barrier->query_mutex);
|
||||
> query_lock(barrier.query_mutex);
|
||||
|
||||
SimpleLogger().Write() << "got query lock";
|
||||
|
||||
// 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"
|
||||
);
|
||||
|
||||
if (0 == barrier->number_of_queries) {
|
||||
if (0 == barrier.number_of_queries) {
|
||||
// notify all processes that were waiting for this condition
|
||||
barrier->no_running_queries_condition.notify_all();
|
||||
barrier.no_running_queries_condition.notify_all();
|
||||
SimpleLogger().Write() << "sent notification";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#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 "../Server/DataStructures/RouteParameters.h"
|
||||
#include "../Util/InputFileUtil.h"
|
||||
@ -45,7 +46,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "../Util/ProgramOptions.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../Server/BasicDatastructures.h"
|
||||
#include "../Server/DataStructures/SharedBarriers.h"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
@ -62,11 +62,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
class OSRM : boost::noncopyable {
|
||||
private:
|
||||
typedef boost::unordered_map<std::string, BasePlugin *> PluginMap;
|
||||
boost::interprocess::shared_memory_object shm;
|
||||
boost::interprocess::mapped_region region;
|
||||
SharedBarriers * barrier;
|
||||
|
||||
bool use_shared_memory;
|
||||
public:
|
||||
OSRM(
|
||||
const ServerPaths & paths,
|
||||
@ -77,10 +72,11 @@ public:
|
||||
|
||||
private:
|
||||
void RegisterPlugin(BasePlugin * plugin);
|
||||
PluginMap plugin_map;
|
||||
bool use_shared_memory;
|
||||
SharedBarriers barrier;
|
||||
//base class pointer to the objects
|
||||
BaseDataFacade<QueryEdge::EdgeData> * query_data_facade;
|
||||
|
||||
PluginMap plugin_map;
|
||||
};
|
||||
|
||||
#endif //OSRM_H
|
||||
|
@ -189,6 +189,8 @@ public:
|
||||
throw OSRMException("no leaf index file given in ini file");
|
||||
}
|
||||
|
||||
SimpleLogger().Write() << "1";
|
||||
|
||||
//generate paths of data files
|
||||
ServerPaths::const_iterator paths_iterator = server_paths.find("fileindex");
|
||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||
|
Loading…
Reference in New Issue
Block a user