MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / swapData

Function swapData

src/storage/storage.cpp:82–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82bool swapData(Monitor &monitor,
83 SharedRegionRegister &shared_register,
84 const std::map<std::string, RegionHandle> &handles,
85 int max_wait)
86{
87 std::vector<RegionHandle> old_handles;
88
89 { // Lock for write access shared region mutex
90 boost::interprocess::scoped_lock<Monitor::mutex_type> lock(monitor.get_mutex(),
91 boost::interprocess::defer_lock);
92
93 if (max_wait >= 0)
94 {
95 auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(max_wait);
96 while (!lock.try_lock())
97 {
98 if (std::chrono::steady_clock::now() >= deadline)
99 {
100 util::Log(logERROR) << "Could not acquire current region lock after "
101 << max_wait << " seconds. Data update failed.";
102
103 for (auto &pair : handles)
104 {
105 Remove(pair.second.proj_id);
106 }
107 return false;
108 }
109 std::this_thread::sleep_for(std::chrono::milliseconds(10));
110 }
111 }
112 else
113 {
114 lock.lock();
115 }
116
117 for (auto &pair : handles)
118 {
119 auto region_id = shared_register.Find(pair.first);
120 if (region_id == SharedRegionRegister::INVALID_REGION_ID)
121 {
122 region_id = shared_register.Register(pair.first, pair.second.proj_id);
123 }
124 else
125 {
126 auto &shared_region = shared_register.GetRegion(region_id);
127
128 old_handles.push_back(RegionHandle{
129 makeSharedMemory(shared_region.proj_id), nullptr, shared_region.proj_id});
130
131 shared_region.proj_id = pair.second.proj_id;
132 shared_region.timestamp++;
133 }
134 }
135 }
136
137 util::Log() << "All data loaded. Notify all clients about new data in:";
138 for (const auto &pair : handles)
139 {

Callers 1

RunMethod · 0.85

Calls 10

LogClass · 0.85
RemoveFunction · 0.85
makeSharedMemoryFunction · 0.85
UnbufferedLogClass · 0.85
WaitForDetachFunction · 0.85
FindMethod · 0.80
RegisterMethod · 0.80
notify_allMethod · 0.80
ReleaseKeyMethod · 0.80
push_backMethod · 0.45

Tested by

no test coverage detected