Restore --max-wait and file_lock for osrm-datastore

This commit is contained in:
Patrick Niklaus
2017-01-05 22:38:48 +00:00
committed by Patrick Niklaus
parent a7bb26f2d6
commit 104e23abf3
12 changed files with 234 additions and 120 deletions
+25 -17
View File
@@ -26,10 +26,20 @@ namespace engine
class DataWatchdog
{
public:
DataWatchdog()
: active(true)
, timestamp(0)
DataWatchdog() : active(true), timestamp(0)
{
// create the initial facade before launching the watchdog thread
{
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> current_region_lock(
barrier.region_mutex);
auto shared_memory = makeSharedMemory(storage::CURRENT_REGION);
auto current = static_cast<storage::SharedDataTimestamp *>(shared_memory->Ptr());
facade = std::make_shared<datafacade::SharedMemoryDataFacade>(current->region);
timestamp = current->timestamp;
}
watcher = std::thread(&DataWatchdog::Run, this);
}
@@ -46,36 +56,34 @@ class DataWatchdog
return storage::SharedMemory::RegionExists(storage::CURRENT_REGION);
}
auto GetDataFacade() const
{
return facade;
}
auto GetDataFacade() const { return facade; }
private:
void Run()
{
boost::interprocess::scoped_lock<boost::interprocess::named_mutex>
current_region_lock(barrier.region_mutex);
auto shared_memory = makeSharedMemory(storage::CURRENT_REGION);
auto current = static_cast<storage::SharedDataTimestamp *>(shared_memory->Ptr());
while (active)
{
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> current_region_lock(
barrier.region_mutex);
while (active && timestamp == current->timestamp)
{
barrier.region_condition.wait(current_region_lock);
}
if (timestamp != current->timestamp)
{
facade = std::make_shared<datafacade::SharedMemoryDataFacade>(current->region);
timestamp = current->timestamp;
util::Log() << "updated facade to region " << storage::regionToString(current->region)
<< " with timestamp " << current->timestamp;
util::Log() << "updated facade to region "
<< storage::regionToString(current->region) << " with timestamp "
<< current->timestamp;
}
barrier.region_condition.wait(current_region_lock);
}
facade.reset();
util::Log() << "DataWatchdog thread stopped";
}
@@ -30,9 +30,7 @@ class SharedMemoryDataFacade : public ContiguousInternalMemoryDataFacadeBase
SharedMemoryDataFacade() {}
public:
SharedMemoryDataFacade(storage::SharedDataType data_region)
: data_region(data_region)
SharedMemoryDataFacade(storage::SharedDataType data_region) : data_region(data_region)
{
util::Log(logDEBUG) << "Loading new data for region " << regionToString(data_region);