Skip to content

Commit

Permalink
Merge #6077
Browse files Browse the repository at this point in the history
6077: Making default constructor of hpx::mutex constexpr r=hkaiser a=hkaiser

Fixes #6008

This also helps with #3440


Co-authored-by: Hartmut Kaiser <[email protected]>
  • Loading branch information
StellarBot and hkaiser committed Nov 21, 2022
2 parents ab86a31 + bef013f commit ed88594
Show file tree
Hide file tree
Showing 14 changed files with 750 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void test_for_each_seq(IteratorTag)
template <typename ExPolicy, typename IteratorTag>
void test_for_each(ExPolicy&& policy, IteratorTag)
{
BOOST_STATIC_ASSERT(hpx::is_execution_policy<ExPolicy>::value);
static_assert(hpx::is_execution_policy<ExPolicy>::value);

typedef std::vector<std::size_t>::iterator base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;
Expand Down Expand Up @@ -155,7 +155,7 @@ void test_for_each_exception_seq(IteratorTag)
template <typename ExPolicy, typename IteratorTag>
void test_for_each_exception(ExPolicy&& policy, IteratorTag)
{
BOOST_STATIC_ASSERT(hpx::is_execution_policy<ExPolicy>::value);
static_assert(hpx::is_execution_policy<ExPolicy>::value);

typedef std::vector<std::size_t>::iterator base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;
Expand Down Expand Up @@ -268,7 +268,7 @@ void test_for_each_bad_alloc_seq(IteratorTag)
template <typename ExPolicy, typename IteratorTag>
void test_for_each_bad_alloc(ExPolicy&& policy, IteratorTag)
{
BOOST_STATIC_ASSERT(hpx::is_execution_policy<ExPolicy>::value);
static_assert(hpx::is_execution_policy<ExPolicy>::value);

typedef std::vector<std::size_t>::iterator base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void test_for_each_seq(IteratorTag, Proj&& proj)
template <typename ExPolicy, typename IteratorTag, typename Proj>
void test_for_each(ExPolicy&& policy, IteratorTag, Proj&& proj)
{
BOOST_STATIC_ASSERT(hpx::is_execution_policy<ExPolicy>::value);
static_assert(hpx::is_execution_policy<ExPolicy>::value);

typedef std::vector<std::size_t>::iterator base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;
Expand Down Expand Up @@ -151,7 +151,7 @@ void test_for_each_exception_seq(IteratorTag, Proj&& proj)
template <typename ExPolicy, typename IteratorTag, typename Proj>
void test_for_each_exception(ExPolicy policy, IteratorTag, Proj&& proj)
{
BOOST_STATIC_ASSERT(hpx::is_execution_policy<ExPolicy>::value);
static_assert(hpx::is_execution_policy<ExPolicy>::value);

typedef std::vector<std::size_t>::iterator base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;
Expand Down Expand Up @@ -266,7 +266,7 @@ void test_for_each_bad_alloc_seq(IteratorTag, Proj&& proj)
template <typename ExPolicy, typename IteratorTag, typename Proj>
void test_for_each_bad_alloc(ExPolicy policy, IteratorTag, Proj&& proj)
{
BOOST_STATIC_ASSERT(hpx::is_execution_policy<ExPolicy>::value);
static_assert(hpx::is_execution_policy<ExPolicy>::value);

typedef std::vector<std::size_t>::iterator base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ namespace hpx {
typename NeedsPadding = typename detail::needs_padding<Data>::type>
struct cache_aligned_data
{
// We have an explicit (non-default) constructor here to avoid for
// the entire cache-line to be initialized by the compiler.
cache_aligned_data()
// We have an explicit (default) constructor here to avoid for the
// entire cache-line to be initialized by the compiler.
constexpr cache_aligned_data() noexcept(
std::is_nothrow_default_constructible_v<Data>)
: data_()
{
}
Expand Down Expand Up @@ -122,9 +123,10 @@ namespace hpx {
typename NeedsPadding = typename detail::needs_padding<Data>::type>
struct cache_aligned_data_derived : Data
{
// We have an explicit (non-default) constructor here to avoid for
// the entire cache-line to be initialized by the compiler.
cache_aligned_data_derived()
// We have an explicit (default) constructor here to avoid for the
// entire cache-line to be initialized by the compiler.
constexpr cache_aligned_data_derived() noexcept(
std::is_nothrow_default_constructible_v<Data>)
: Data()
{
}
Expand Down
10 changes: 9 additions & 1 deletion libs/core/config/include/hpx/config/constexpr.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2013 Hartmut Kaiser
// Copyright (c) 2013-2022 Hartmut Kaiser
// Copyright (c) 2015 Thomas Heller
//
// SPDX-License-Identifier: BSL-1.0
Expand All @@ -19,3 +19,11 @@
#else
#define HPX_HOST_DEVICE_INLINE_CONSTEXPR_VARIABLE inline constexpr
#endif

/// This macro evaluates to ``constexpr`` for host code and expands nothing for
/// NVCC
#if defined(__NVCC__)
#define HPX_HOST_DEVICE_CONSTEXPR
#else
#define HPX_HOST_DEVICE_CONSTEXPR constexpr
#endif
1 change: 1 addition & 0 deletions libs/core/datastructures/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ endif()
set(datastructures_headers
hpx/datastructures/any.hpp
hpx/datastructures/detail/dynamic_bitset.hpp
hpx/datastructures/detail/intrusive_list.hpp
hpx/datastructures/detail/small_vector.hpp
hpx/datastructures/detail/optional.hpp
hpx/datastructures/detail/variant.hpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// Copyright (c) 2022 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.

#pragma once

#include <hpx/config.hpp>
#include <hpx/assert.hpp>

#include <cstddef>
#include <utility>

namespace hpx::detail {

template <typename Entry>
class intrusive_list
{
public:
constexpr intrusive_list() noexcept = default;

intrusive_list(intrusive_list const&) = delete;
intrusive_list& operator=(intrusive_list const&) = delete;

intrusive_list(intrusive_list&&) = default;
intrusive_list& operator=(intrusive_list&&) = default;

void push_back(Entry& e) noexcept
{
if (last_entry == nullptr)
{
HPX_ASSERT(num_entries == 0);
HPX_ASSERT(root == nullptr);

e.prev = nullptr;
e.next = nullptr;

root = &e;
last_entry = &e;
}
else
{
HPX_ASSERT(num_entries != 0);
HPX_ASSERT(root != nullptr);

e.prev = last_entry;
e.next = nullptr;

last_entry->next = &e;
last_entry = &e;
}
++num_entries;
}

void pop_front() noexcept
{
HPX_ASSERT(num_entries != 0);

--num_entries;
if (root->next != nullptr)
{
root->next->prev = nullptr;
}
else
{
last_entry = nullptr;
}
root = root->next;
}

void splice(intrusive_list& queue) noexcept
{
Entry* start = queue.front();
Entry* end = queue.back();

if (start != nullptr)
{
start->prev = last_entry;
}

if (last_entry != nullptr)
{
last_entry->next = start;
if (end != nullptr)
{
last_entry = end;
}
}
else
{
root = start;
last_entry = end;
}

num_entries += queue.size();

queue.reset();
}

void erase(Entry const* e) noexcept
{
HPX_ASSERT(num_entries != 0);
HPX_ASSERT(e != nullptr);

--num_entries;
if (e->next != nullptr)
{
e->next->prev = e->prev;
}
else
{
last_entry = e->prev;
}

if (e->prev != nullptr)
{
e->prev->next = e->next;
}
else
{
root = e->next;
}
}

void reset() noexcept
{
num_entries = 0;
root = nullptr;
last_entry = nullptr;
}

Entry* front() noexcept
{
return root;
}
constexpr Entry const* front() const noexcept
{
return root;
}

Entry* back() noexcept
{
return last_entry;
}
constexpr Entry const* back() const noexcept
{
return last_entry;
}

constexpr std::size_t size() const noexcept
{
return num_entries;
}

constexpr bool empty() const noexcept
{
return num_entries == 0;
}

void swap(intrusive_list& rhs) noexcept
{
std::swap(num_entries, rhs.num_entries);
std::swap(root, rhs.root);
std::swap(last_entry, rhs.last_entry);
}

private:
std::size_t num_entries = 0;
Entry* root = nullptr;
Entry* last_entry = nullptr;
};
} // namespace hpx::detail
1 change: 1 addition & 0 deletions libs/core/datastructures/tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(tests
dynamic_bitset3
dynamic_bitset4
dynamic_bitset5
intrusive_list
is_tuple_like
serializable_any
serializable_boost_any
Expand Down
Loading

0 comments on commit ed88594

Please sign in to comment.