Make swap noexcept (as it has to be!) and fix swap misuses
This commit is contained in:
parent
7b37c847bd
commit
fa8529949b
@ -134,7 +134,6 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
|
|||||||
|
|
||||||
void LoadNodeAndEdgeInformation()
|
void LoadNodeAndEdgeInformation()
|
||||||
{
|
{
|
||||||
|
|
||||||
auto coordinate_list_ptr = data_layout->GetBlockPtr<util::FixedPointCoordinate>(
|
auto coordinate_list_ptr = data_layout->GetBlockPtr<util::FixedPointCoordinate>(
|
||||||
shared_memory, storage::SharedDataLayout::COORDINATE_LIST);
|
shared_memory, storage::SharedDataLayout::COORDINATE_LIST);
|
||||||
m_coordinate_list = util::make_unique<util::ShM<util::FixedPointCoordinate, true>::vector>(
|
m_coordinate_list = util::make_unique<util::ShM<util::FixedPointCoordinate, true>::vector>(
|
||||||
@ -145,20 +144,20 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
|
|||||||
shared_memory, storage::SharedDataLayout::TRAVEL_MODE);
|
shared_memory, storage::SharedDataLayout::TRAVEL_MODE);
|
||||||
typename util::ShM<extractor::TravelMode, true>::vector travel_mode_list(
|
typename util::ShM<extractor::TravelMode, true>::vector travel_mode_list(
|
||||||
travel_mode_list_ptr, data_layout->num_entries[storage::SharedDataLayout::TRAVEL_MODE]);
|
travel_mode_list_ptr, data_layout->num_entries[storage::SharedDataLayout::TRAVEL_MODE]);
|
||||||
m_travel_mode_list.swap(travel_mode_list);
|
m_travel_mode_list = std::move(travel_mode_list);
|
||||||
|
|
||||||
auto turn_instruction_list_ptr = data_layout->GetBlockPtr<extractor::TurnInstruction>(
|
auto turn_instruction_list_ptr = data_layout->GetBlockPtr<extractor::TurnInstruction>(
|
||||||
shared_memory, storage::SharedDataLayout::TURN_INSTRUCTION);
|
shared_memory, storage::SharedDataLayout::TURN_INSTRUCTION);
|
||||||
typename util::ShM<extractor::TurnInstruction, true>::vector turn_instruction_list(
|
typename util::ShM<extractor::TurnInstruction, true>::vector turn_instruction_list(
|
||||||
turn_instruction_list_ptr,
|
turn_instruction_list_ptr,
|
||||||
data_layout->num_entries[storage::SharedDataLayout::TURN_INSTRUCTION]);
|
data_layout->num_entries[storage::SharedDataLayout::TURN_INSTRUCTION]);
|
||||||
m_turn_instruction_list.swap(turn_instruction_list);
|
m_turn_instruction_list = std::move(turn_instruction_list);
|
||||||
|
|
||||||
auto name_id_list_ptr = data_layout->GetBlockPtr<unsigned>(
|
auto name_id_list_ptr = data_layout->GetBlockPtr<unsigned>(
|
||||||
shared_memory, storage::SharedDataLayout::NAME_ID_LIST);
|
shared_memory, storage::SharedDataLayout::NAME_ID_LIST);
|
||||||
typename util::ShM<unsigned, true>::vector name_id_list(
|
typename util::ShM<unsigned, true>::vector name_id_list(
|
||||||
name_id_list_ptr, data_layout->num_entries[storage::SharedDataLayout::NAME_ID_LIST]);
|
name_id_list_ptr, data_layout->num_entries[storage::SharedDataLayout::NAME_ID_LIST]);
|
||||||
m_name_ID_list.swap(name_id_list);
|
m_name_ID_list = std::move(name_id_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadViaNodeList()
|
void LoadViaNodeList()
|
||||||
@ -167,7 +166,7 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
|
|||||||
shared_memory, storage::SharedDataLayout::VIA_NODE_LIST);
|
shared_memory, storage::SharedDataLayout::VIA_NODE_LIST);
|
||||||
typename util::ShM<NodeID, true>::vector via_node_list(
|
typename util::ShM<NodeID, true>::vector via_node_list(
|
||||||
via_node_list_ptr, data_layout->num_entries[storage::SharedDataLayout::VIA_NODE_LIST]);
|
via_node_list_ptr, data_layout->num_entries[storage::SharedDataLayout::VIA_NODE_LIST]);
|
||||||
m_via_node_list.swap(via_node_list);
|
m_via_node_list = std::move(via_node_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadNames()
|
void LoadNames()
|
||||||
@ -188,7 +187,7 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
|
|||||||
m_name_table = util::make_unique<util::RangeTable<16, true>>(
|
m_name_table = util::make_unique<util::RangeTable<16, true>>(
|
||||||
name_offsets, name_blocks, static_cast<unsigned>(names_char_list.size()));
|
name_offsets, name_blocks, static_cast<unsigned>(names_char_list.size()));
|
||||||
|
|
||||||
m_names_char_list.swap(names_char_list);
|
m_names_char_list = std::move(names_char_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadCoreInformation()
|
void LoadCoreInformation()
|
||||||
@ -202,7 +201,7 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
|
|||||||
shared_memory, storage::SharedDataLayout::CORE_MARKER);
|
shared_memory, storage::SharedDataLayout::CORE_MARKER);
|
||||||
typename util::ShM<bool, true>::vector is_core_node(
|
typename util::ShM<bool, true>::vector is_core_node(
|
||||||
core_marker_ptr, data_layout->num_entries[storage::SharedDataLayout::CORE_MARKER]);
|
core_marker_ptr, data_layout->num_entries[storage::SharedDataLayout::CORE_MARKER]);
|
||||||
m_is_core_node.swap(is_core_node);
|
m_is_core_node = std::move(is_core_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadGeometries()
|
void LoadGeometries()
|
||||||
@ -212,21 +211,21 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
|
|||||||
typename util::ShM<bool, true>::vector edge_is_compressed(
|
typename util::ShM<bool, true>::vector edge_is_compressed(
|
||||||
geometries_compressed_ptr,
|
geometries_compressed_ptr,
|
||||||
data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_INDICATORS]);
|
data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_INDICATORS]);
|
||||||
m_edge_is_compressed.swap(edge_is_compressed);
|
m_edge_is_compressed = std::move(edge_is_compressed);
|
||||||
|
|
||||||
auto geometries_index_ptr = data_layout->GetBlockPtr<unsigned>(
|
auto geometries_index_ptr = data_layout->GetBlockPtr<unsigned>(
|
||||||
shared_memory, storage::SharedDataLayout::GEOMETRIES_INDEX);
|
shared_memory, storage::SharedDataLayout::GEOMETRIES_INDEX);
|
||||||
typename util::ShM<unsigned, true>::vector geometry_begin_indices(
|
typename util::ShM<unsigned, true>::vector geometry_begin_indices(
|
||||||
geometries_index_ptr,
|
geometries_index_ptr,
|
||||||
data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_INDEX]);
|
data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_INDEX]);
|
||||||
m_geometry_indices.swap(geometry_begin_indices);
|
m_geometry_indices = std::move(geometry_begin_indices);
|
||||||
|
|
||||||
auto geometries_list_ptr = data_layout->GetBlockPtr<unsigned>(
|
auto geometries_list_ptr = data_layout->GetBlockPtr<unsigned>(
|
||||||
shared_memory, storage::SharedDataLayout::GEOMETRIES_LIST);
|
shared_memory, storage::SharedDataLayout::GEOMETRIES_LIST);
|
||||||
typename util::ShM<unsigned, true>::vector geometry_list(
|
typename util::ShM<unsigned, true>::vector geometry_list(
|
||||||
geometries_list_ptr,
|
geometries_list_ptr,
|
||||||
data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_LIST]);
|
data_layout->num_entries[storage::SharedDataLayout::GEOMETRIES_LIST]);
|
||||||
m_geometry_list.swap(geometry_list);
|
m_geometry_list = std::move(geometry_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
{
|
{
|
||||||
@ -52,8 +53,9 @@ template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY> class RangeTable
|
|||||||
const unsigned sum_lengths)
|
const unsigned sum_lengths)
|
||||||
: sum_lengths(sum_lengths)
|
: sum_lengths(sum_lengths)
|
||||||
{
|
{
|
||||||
block_offsets.swap(external_offsets);
|
using std::swap;
|
||||||
diff_blocks.swap(external_blocks);
|
swap(block_offsets, external_offsets);
|
||||||
|
swap(diff_blocks, external_blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
// construct table from length vector
|
// construct table from length vector
|
||||||
|
@ -55,13 +55,6 @@ template <typename DataT> class SharedMemoryWrapper
|
|||||||
|
|
||||||
SharedMemoryWrapper(DataT *ptr, std::size_t size) : m_ptr(ptr), m_size(size) {}
|
SharedMemoryWrapper(DataT *ptr, std::size_t size) : m_ptr(ptr), m_size(size) {}
|
||||||
|
|
||||||
void swap(SharedMemoryWrapper<DataT> &other)
|
|
||||||
{
|
|
||||||
// BOOST_ASSERT_MSG(m_size != 0 || other.size() != 0, "size invalid");
|
|
||||||
std::swap(m_size, other.m_size);
|
|
||||||
std::swap(m_ptr, other.m_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
DataT &at(const std::size_t index) { return m_ptr[index]; }
|
DataT &at(const std::size_t index) { return m_ptr[index]; }
|
||||||
|
|
||||||
const DataT &at(const std::size_t index) const { return m_ptr[index]; }
|
const DataT &at(const std::size_t index) const { return m_ptr[index]; }
|
||||||
@ -85,6 +78,9 @@ template <typename DataT> class SharedMemoryWrapper
|
|||||||
BOOST_ASSERT_MSG(index < m_size, "invalid size");
|
BOOST_ASSERT_MSG(index < m_size, "invalid size");
|
||||||
return m_ptr[index];
|
return m_ptr[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
friend void swap(SharedMemoryWrapper<T> &, SharedMemoryWrapper<T> &) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> class SharedMemoryWrapper<bool>
|
template <> class SharedMemoryWrapper<bool>
|
||||||
@ -98,13 +94,6 @@ template <> class SharedMemoryWrapper<bool>
|
|||||||
|
|
||||||
SharedMemoryWrapper(unsigned *ptr, std::size_t size) : m_ptr(ptr), m_size(size) {}
|
SharedMemoryWrapper(unsigned *ptr, std::size_t size) : m_ptr(ptr), m_size(size) {}
|
||||||
|
|
||||||
void swap(SharedMemoryWrapper<bool> &other)
|
|
||||||
{
|
|
||||||
// BOOST_ASSERT_MSG(m_size != 0 || other.size() != 0, "size invalid");
|
|
||||||
std::swap(m_size, other.m_size);
|
|
||||||
std::swap(m_ptr, other.m_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool at(const std::size_t index) const
|
bool at(const std::size_t index) const
|
||||||
{
|
{
|
||||||
const std::size_t bucket = index / 32;
|
const std::size_t bucket = index / 32;
|
||||||
@ -123,8 +112,19 @@ template <> class SharedMemoryWrapper<bool>
|
|||||||
const unsigned offset = index % 32;
|
const unsigned offset = index % 32;
|
||||||
return m_ptr[bucket] & (1 << offset);
|
return m_ptr[bucket] & (1 << offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
friend void swap(SharedMemoryWrapper<T> &, SharedMemoryWrapper<T> &) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Both SharedMemoryWrapper<T> and the SharedMemoryWrapper<bool> specializations share this impl.
|
||||||
|
template <typename DataT>
|
||||||
|
void swap(SharedMemoryWrapper<DataT> &lhs, SharedMemoryWrapper<DataT> &rhs) noexcept
|
||||||
|
{
|
||||||
|
std::swap(lhs.m_ptr, rhs.m_ptr);
|
||||||
|
std::swap(lhs.m_size, rhs.m_size);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename DataT, bool UseSharedMemory> struct ShM
|
template <typename DataT, bool UseSharedMemory> struct ShM
|
||||||
{
|
{
|
||||||
using vector = typename std::conditional<UseSharedMemory,
|
using vector = typename std::conditional<UseSharedMemory,
|
||||||
|
@ -105,8 +105,9 @@ template <typename EdgeDataT, bool UseSharedMemory = false> class StaticGraph
|
|||||||
number_of_nodes = static_cast<decltype(number_of_nodes)>(nodes.size() - 1);
|
number_of_nodes = static_cast<decltype(number_of_nodes)>(nodes.size() - 1);
|
||||||
number_of_edges = static_cast<decltype(number_of_edges)>(edges.size());
|
number_of_edges = static_cast<decltype(number_of_edges)>(edges.size());
|
||||||
|
|
||||||
node_array.swap(nodes);
|
using std::swap;
|
||||||
edge_array.swap(edges);
|
swap(node_array, nodes);
|
||||||
|
swap(edge_array, edges);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned GetNumberOfNodes() const { return number_of_nodes; }
|
unsigned GetNumberOfNodes() const { return number_of_nodes; }
|
||||||
|
Loading…
Reference in New Issue
Block a user