Skip to content

Commit

Permalink
Use thread_local instead of boost::thread_specific_ptr (#6991)
Browse files Browse the repository at this point in the history
  • Loading branch information
SiarheiFedartsou authored Jul 11, 2024
1 parent c2f877e commit d3638ac
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 38 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- NodeJS:
- CHANGED: Use node-api instead of NAN. [#6452](/~https://github.com/Project-OSRM/osrm-backend/pull/6452)
- Misc:
- CHANGED: Use thread_local instead of boost::thread_specific_ptr. [#6991](/~https://github.com/Project-OSRM/osrm-backend/pull/6991)
- CHANGED: Bump flatbuffers to v24.3.25 version. [#6988](/~https://github.com/Project-OSRM/osrm-backend/pull/6988)
- CHANGED: Add .reserve(...) to assembleGeometry function. [#6983](/~https://github.com/Project-OSRM/osrm-backend/pull/6983)
- CHANGED: Get rid of boost::optional leftovers. [#6977](/~https://github.com/Project-OSRM/osrm-backend/pull/6977)
Expand Down
42 changes: 20 additions & 22 deletions include/engine/search_engine_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include "util/query_heap.hpp"
#include "util/typedefs.hpp"

#include <boost/thread/tss.hpp>

namespace osrm::engine
{

Expand Down Expand Up @@ -45,19 +43,19 @@ template <> struct SearchEngineData<routing_algorithms::ch::Algorithm>
ManyToManyHeapData,
util::UnorderedMapStorage<NodeID, int>>;

using SearchEngineHeapPtr = boost::thread_specific_ptr<QueryHeap>;
using SearchEngineHeapPtr = std::unique_ptr<QueryHeap>;

using ManyToManyHeapPtr = boost::thread_specific_ptr<ManyToManyQueryHeap>;
using ManyToManyHeapPtr = std::unique_ptr<ManyToManyQueryHeap>;

static SearchEngineHeapPtr forward_heap_1;
static SearchEngineHeapPtr reverse_heap_1;
static SearchEngineHeapPtr forward_heap_2;
static SearchEngineHeapPtr reverse_heap_2;
static SearchEngineHeapPtr forward_heap_3;
static SearchEngineHeapPtr reverse_heap_3;
static ManyToManyHeapPtr many_to_many_heap;
static SearchEngineHeapPtr map_matching_forward_heap_1;
static SearchEngineHeapPtr map_matching_reverse_heap_1;
static thread_local SearchEngineHeapPtr forward_heap_1;
static thread_local SearchEngineHeapPtr reverse_heap_1;
static thread_local SearchEngineHeapPtr forward_heap_2;
static thread_local SearchEngineHeapPtr reverse_heap_2;
static thread_local SearchEngineHeapPtr forward_heap_3;
static thread_local SearchEngineHeapPtr reverse_heap_3;
static thread_local ManyToManyHeapPtr many_to_many_heap;
static thread_local SearchEngineHeapPtr map_matching_forward_heap_1;
static thread_local SearchEngineHeapPtr map_matching_reverse_heap_1;

void InitializeOrClearMapMatchingThreadLocalStorage(unsigned number_of_nodes);

Expand Down Expand Up @@ -127,16 +125,16 @@ template <> struct SearchEngineData<routing_algorithms::mld::Algorithm>
MapMatchingMultiLayerDijkstraHeapData,
util::TwoLevelStorage<NodeID, int>>;

using SearchEngineHeapPtr = boost::thread_specific_ptr<QueryHeap>;
using ManyToManyHeapPtr = boost::thread_specific_ptr<ManyToManyQueryHeap>;
using MapMatchingHeapPtr = boost::thread_specific_ptr<MapMatchingQueryHeap>;
using SearchEngineHeapPtr = std::unique_ptr<QueryHeap>;
using ManyToManyHeapPtr = std::unique_ptr<ManyToManyQueryHeap>;
using MapMatchingHeapPtr = std::unique_ptr<MapMatchingQueryHeap>;

static SearchEngineHeapPtr forward_heap_1;
static SearchEngineHeapPtr reverse_heap_1;
static MapMatchingHeapPtr map_matching_forward_heap_1;
static MapMatchingHeapPtr map_matching_reverse_heap_1;
static thread_local SearchEngineHeapPtr forward_heap_1;
static thread_local SearchEngineHeapPtr reverse_heap_1;
static thread_local MapMatchingHeapPtr map_matching_forward_heap_1;
static thread_local MapMatchingHeapPtr map_matching_reverse_heap_1;

static ManyToManyHeapPtr many_to_many_heap;
static thread_local ManyToManyHeapPtr many_to_many_heap;

void InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes,
unsigned number_of_boundary_nodes);
Expand All @@ -148,4 +146,4 @@ template <> struct SearchEngineData<routing_algorithms::mld::Algorithm>
};
} // namespace osrm::engine

#endif // SEARCH_ENGINE_DATA_HPP
#endif // SEARCH_ENGINE_DATA_HPP
36 changes: 20 additions & 16 deletions src/engine/search_engine_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ namespace osrm::engine

// CH heaps
using CH = routing_algorithms::ch::Algorithm;
SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::forward_heap_1;
SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::reverse_heap_1;
SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::forward_heap_2;
SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::reverse_heap_2;
SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::forward_heap_3;
SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::reverse_heap_3;
SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::map_matching_forward_heap_1;
SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::map_matching_reverse_heap_1;

SearchEngineData<CH>::ManyToManyHeapPtr SearchEngineData<CH>::many_to_many_heap;
thread_local SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::forward_heap_1;
thread_local SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::reverse_heap_1;
thread_local SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::forward_heap_2;
thread_local SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::reverse_heap_2;
thread_local SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::forward_heap_3;
thread_local SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::reverse_heap_3;
thread_local SearchEngineData<CH>::SearchEngineHeapPtr
SearchEngineData<CH>::map_matching_forward_heap_1;
thread_local SearchEngineData<CH>::SearchEngineHeapPtr
SearchEngineData<CH>::map_matching_reverse_heap_1;

thread_local SearchEngineData<CH>::ManyToManyHeapPtr SearchEngineData<CH>::many_to_many_heap;

void SearchEngineData<CH>::InitializeOrClearMapMatchingThreadLocalStorage(unsigned number_of_nodes)
{
Expand Down Expand Up @@ -114,11 +116,13 @@ void SearchEngineData<CH>::InitializeOrClearManyToManyThreadLocalStorage(unsigne

// MLD
using MLD = routing_algorithms::mld::Algorithm;
SearchEngineData<MLD>::SearchEngineHeapPtr SearchEngineData<MLD>::forward_heap_1;
SearchEngineData<MLD>::SearchEngineHeapPtr SearchEngineData<MLD>::reverse_heap_1;
SearchEngineData<MLD>::MapMatchingHeapPtr SearchEngineData<MLD>::map_matching_forward_heap_1;
SearchEngineData<MLD>::MapMatchingHeapPtr SearchEngineData<MLD>::map_matching_reverse_heap_1;
SearchEngineData<MLD>::ManyToManyHeapPtr SearchEngineData<MLD>::many_to_many_heap;
thread_local SearchEngineData<MLD>::SearchEngineHeapPtr SearchEngineData<MLD>::forward_heap_1;
thread_local SearchEngineData<MLD>::SearchEngineHeapPtr SearchEngineData<MLD>::reverse_heap_1;
thread_local SearchEngineData<MLD>::MapMatchingHeapPtr
SearchEngineData<MLD>::map_matching_forward_heap_1;
thread_local SearchEngineData<MLD>::MapMatchingHeapPtr
SearchEngineData<MLD>::map_matching_reverse_heap_1;
thread_local SearchEngineData<MLD>::ManyToManyHeapPtr SearchEngineData<MLD>::many_to_many_heap;

void SearchEngineData<MLD>::InitializeOrClearMapMatchingThreadLocalStorage(
unsigned number_of_nodes, unsigned number_of_boundary_nodes)
Expand Down Expand Up @@ -178,4 +182,4 @@ void SearchEngineData<MLD>::InitializeOrClearManyToManyThreadLocalStorage(
many_to_many_heap.reset(new ManyToManyQueryHeap(number_of_nodes, number_of_boundary_nodes));
}
}
} // namespace osrm::engine
} // namespace osrm::engine

0 comments on commit d3638ac

Please sign in to comment.