22#define SHARED_DATA_TYPE_HPP
33
44#include " storage/block.hpp"
5- #include " storage/io_fwd.hpp"
65
76#include " util/exception.hpp"
8- #include " util/exception_utils.hpp"
97
108#include < array>
119#include < cstdint>
1210#include < map>
13- #include < numeric>
1411#include < unordered_set>
1512
1613namespace osrm ::storage
@@ -67,10 +64,7 @@ class BaseDataLayout
6764 return GetBlock (name).byte_size ;
6865 }
6966
70- inline bool HasBlock (const std::string &name) const
71- {
72- return blocks.find (name) != blocks.end ();
73- }
67+ inline bool HasBlock (const std::string &name) const { return blocks.contains (name); }
7468
7569 // Depending on the name prefix this function either lists all blocks with the same prefix
7670 // or all entries in the sub-directory.
@@ -192,13 +186,19 @@ class TarDataLayout final : public BaseDataLayout
192186 }
193187};
194188
189+ // The second parameter passed to ftok(). See: man 3 ftok
190+ // It should actually be an int, but for compatibility with earlier versions of OSRM it
191+ // is an uint16. It should't matter since, according to the man page, only the lowest 8
192+ // bits are used.
193+ using ProjID = uint16_t ;
194+
195195struct SharedRegion
196196{
197197 static constexpr const int MAX_NAME_LENGTH = 254 ;
198198
199199 SharedRegion () : name{0 }, timestamp{0 } {}
200- SharedRegion (const std::string &name_, std::uint64_t timestamp, std:: uint16_t shm_key )
201- : name{0 }, timestamp{timestamp}, shm_key{shm_key }
200+ SharedRegion (const std::string &name_, std::uint64_t timestamp, ProjID proj_id )
201+ : name{0 }, timestamp{timestamp}, proj_id{proj_id }
202202 {
203203 std::copy_n (name_.begin (), std::min<std::size_t >(MAX_NAME_LENGTH, name_.size ()), name);
204204 }
@@ -207,7 +207,7 @@ struct SharedRegion
207207
208208 char name[MAX_NAME_LENGTH + 1 ];
209209 std::uint64_t timestamp;
210- std:: uint16_t shm_key = 0 ;
210+ ProjID proj_id = 0 ;
211211};
212212
213213// Keeps a list of all shared regions in a fixed-sized struct
@@ -216,7 +216,6 @@ struct SharedRegionRegister
216216{
217217 using RegionID = std::uint16_t ;
218218 static constexpr const RegionID INVALID_REGION_ID = std::numeric_limits<RegionID>::max();
219- using ShmKey = decltype (SharedRegion::shm_key);
220219
221220 // Returns the key of the region with the given name
222221 RegionID Find (const std::string &name) const
@@ -238,7 +237,7 @@ struct SharedRegionRegister
238237 }
239238 }
240239
241- RegionID Register (const std::string &name, ShmKey key )
240+ RegionID Register (const std::string &name, ProjID proj_id )
242241 {
243242 auto iter = std::find_if (
244243 regions.begin (), regions.end (), [&](const auto ®ion) { return region.IsEmpty (); });
@@ -250,7 +249,7 @@ struct SharedRegionRegister
250249 else
251250 {
252251 constexpr std::uint32_t INITIAL_TIMESTAMP = 1 ;
253- *iter = SharedRegion{name, INITIAL_TIMESTAMP, key };
252+ *iter = SharedRegion{name, INITIAL_TIMESTAMP, proj_id };
254253 RegionID key = std::distance (regions.begin (), iter);
255254 return key;
256255 }
@@ -271,7 +270,7 @@ struct SharedRegionRegister
271270
272271 auto &GetRegion (const RegionID key) { return regions[key]; }
273272
274- ShmKey ReserveKey ()
273+ ProjID ReserveKey ()
275274 {
276275 auto free_key_iter = std::find (shm_key_in_use.begin (), shm_key_in_use.end (), false );
277276 if (free_key_iter == shm_key_in_use.end ())
@@ -283,7 +282,7 @@ struct SharedRegionRegister
283282 return std::distance (shm_key_in_use.begin (), free_key_iter);
284283 }
285284
286- void ReleaseKey (ShmKey key ) { shm_key_in_use[key ] = false ; }
285+ void ReleaseKey (ProjID proj_id ) { shm_key_in_use[proj_id ] = false ; }
287286
288287 static constexpr const std::size_t MAX_SHARED_REGIONS = 512 ;
289288 static_assert (MAX_SHARED_REGIONS < std::numeric_limits<RegionID>::max(),
0 commit comments