Change to condvar signaling if data region swapped
This commit is contained in:
committed by
Patrick Niklaus
parent
774b8688ca
commit
fce8d72895
@@ -1,8 +1,8 @@
|
||||
#ifndef SHARED_BARRIERS_HPP
|
||||
#define SHARED_BARRIERS_HPP
|
||||
|
||||
#include <boost/interprocess/sync/named_sharable_mutex.hpp>
|
||||
#include <boost/interprocess/sync/named_upgradable_mutex.hpp>
|
||||
#include <boost/interprocess/sync/named_condition.hpp>
|
||||
#include <boost/interprocess/sync/named_mutex.hpp>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
@@ -13,22 +13,19 @@ struct SharedBarriers
|
||||
{
|
||||
|
||||
SharedBarriers()
|
||||
: current_region_mutex(boost::interprocess::open_or_create, "current_region"),
|
||||
region_1_mutex(boost::interprocess::open_or_create, "region_1"),
|
||||
region_2_mutex(boost::interprocess::open_or_create, "region_2")
|
||||
: region_mutex(boost::interprocess::open_or_create, "osrm-region")
|
||||
, region_condition(boost::interprocess::open_or_create, "osrm-region-cv")
|
||||
{
|
||||
}
|
||||
|
||||
static void resetCurrentRegion()
|
||||
static void remove()
|
||||
{
|
||||
boost::interprocess::named_sharable_mutex::remove("current_region");
|
||||
boost::interprocess::named_mutex::remove("osrm-region");
|
||||
boost::interprocess::named_condition::remove("osrm-region-cv");
|
||||
}
|
||||
static void resetRegion1() { boost::interprocess::named_sharable_mutex::remove("region_1"); }
|
||||
static void resetRegion2() { boost::interprocess::named_sharable_mutex::remove("region_2"); }
|
||||
|
||||
boost::interprocess::named_upgradable_mutex current_region_mutex;
|
||||
boost::interprocess::named_sharable_mutex region_1_mutex;
|
||||
boost::interprocess::named_sharable_mutex region_2_mutex;
|
||||
boost::interprocess::named_mutex region_mutex;
|
||||
boost::interprocess::named_condition region_condition;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include <sys/shm.h>
|
||||
#endif
|
||||
|
||||
// #include <cstring>
|
||||
#include <cstdint>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -150,25 +149,23 @@ class SharedMemory
|
||||
|
||||
SharedMemory(const boost::filesystem::path &lock_file,
|
||||
const int id,
|
||||
const uint64_t size = 0,
|
||||
bool read_write = false)
|
||||
const uint64_t size = 0)
|
||||
{
|
||||
sprintf(key, "%s.%d", "osrm.lock", id);
|
||||
auto access = read_write ? boost::interprocess::read_write : boost::interprocess::read_only;
|
||||
if (0 == size)
|
||||
{ // read_only
|
||||
shm = boost::interprocess::shared_memory_object(
|
||||
boost::interprocess::open_only,
|
||||
key,
|
||||
read_write ? boost::interprocess::read_write : boost::interprocess::read_only);
|
||||
region = boost::interprocess::mapped_region(shm, access);
|
||||
boost::interprocess::read_only);
|
||||
region = boost::interprocess::mapped_region(shm, boost::interprocess::read_only);
|
||||
}
|
||||
else
|
||||
{ // writeable pointer
|
||||
shm = boost::interprocess::shared_memory_object(
|
||||
boost::interprocess::open_or_create, key, boost::interprocess::read_write);
|
||||
shm.truncate(size);
|
||||
region = boost::interprocess::mapped_region(shm, access);
|
||||
region = boost::interprocess::mapped_region(shm, boost::interprocess::read_write);
|
||||
|
||||
util::Log(logDEBUG) << "writeable memory allocated " << size << " bytes";
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "storage/shared_datatype.hpp"
|
||||
#include "storage/storage_config.hpp"
|
||||
|
||||
#include <boost/interprocess/sync/named_mutex.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <string>
|
||||
@@ -44,20 +45,14 @@ class Storage
|
||||
public:
|
||||
Storage(StorageConfig config);
|
||||
|
||||
enum ReturnCode
|
||||
{
|
||||
Ok,
|
||||
Error,
|
||||
Retry
|
||||
};
|
||||
|
||||
ReturnCode Run(int max_wait);
|
||||
int Run();
|
||||
|
||||
void PopulateLayout(DataLayout &layout);
|
||||
void PopulateData(const DataLayout &layout, char *memory_ptr);
|
||||
|
||||
private:
|
||||
StorageConfig config;
|
||||
boost::interprocess::named_mutex datastore_mutex;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user