implement update barrier
This commit is contained in:
parent
53a0bc963a
commit
19a457ab7d
@ -26,21 +26,36 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "OSRM.h"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
OSRM::OSRM( const ServerPaths & server_paths, const bool use_shared_memory ) {
|
||||
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 ) {
|
||||
SimpleLogger().Write() << "loading data into internal memory";
|
||||
query_data_facade = new InternalDataFacade<QueryEdge::EdgeData>(
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//The following plugins handle all requests.
|
||||
RegisterPlugin(
|
||||
new HelloWorldPlugin()
|
||||
@ -88,6 +103,13 @@ void OSRM::RunQuery(RouteParameters & route_parameters, http::Reply & reply) {
|
||||
|
||||
if(plugin_map.end() != iter) {
|
||||
reply.status = http::Reply::ok;
|
||||
if( use_shared_memory && barrier->update_ongoing ) {
|
||||
//wait until we get the mutex and free it immediately
|
||||
//TODO: increment semaphore of querying processes
|
||||
boost::interprocess::scoped_lock<
|
||||
boost::interprocess::interprocess_mutex
|
||||
> lock(barrier->update_mutex);
|
||||
}
|
||||
iter->second->HandleRequest(route_parameters, reply );
|
||||
} else {
|
||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||
|
@ -45,9 +45,14 @@ 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>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/interprocess/shared_memory_object.hpp>
|
||||
#include <boost/interprocess/mapped_region.hpp>
|
||||
#include <boost/interprocess/sync/scoped_lock.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
@ -57,7 +62,11 @@ 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,
|
||||
|
18
Server/DataStructures/SharedBarriers.h
Normal file
18
Server/DataStructures/SharedBarriers.h
Normal file
@ -0,0 +1,18 @@
|
||||
#include <boost/interprocess/sync/interprocess_mutex.hpp>
|
||||
#include <boost/interprocess/sync/interprocess_condition.hpp>
|
||||
|
||||
struct SharedBarriers {
|
||||
|
||||
SharedBarriers () : update_ongoing(false), number_of_queries(0) { }
|
||||
|
||||
// Mutex to protect access to the boolean variable
|
||||
boost::interprocess::interprocess_mutex update_mutex;
|
||||
boost::interprocess::interprocess_mutex query_mutex;
|
||||
|
||||
// Condition that no update is running
|
||||
boost::interprocess::interprocess_condition update_finished_condition;
|
||||
|
||||
// Is there any message?
|
||||
bool update_ongoing;
|
||||
int number_of_queries;
|
||||
};
|
@ -33,6 +33,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
|
||||
#include <boost/integer.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/interprocess/sync/interprocess_semaphore.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
Loading…
Reference in New Issue
Block a user