Skip to content

Commit

Permalink
Attempting to avoid segfault in OctoTiger during initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Jan 13, 2024
1 parent 7b35448 commit 9f23e8a
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 39 deletions.
14 changes: 7 additions & 7 deletions libs/core/futures/include/hpx/futures/future_or_value.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Hartmut Kaiser
// Copyright (c) 2022-2024 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -30,11 +30,11 @@ namespace hpx {
{
}

constexpr bool has_value() const noexcept
[[nodiscard]] constexpr bool has_value() const noexcept
{
return hpx::holds_alternative<T>(data);
}
constexpr bool has_future() const noexcept
[[nodiscard]] constexpr bool has_future() const noexcept
{
return hpx::holds_alternative<hpx::future<T>>(data);
}
Expand All @@ -43,11 +43,11 @@ namespace hpx {
{
return hpx::get<T>(data);
}
constexpr T const& get_value() const&
[[nodiscard]] constexpr T const& get_value() const&
{
return hpx::get<T>(data);
}
constexpr T&& get_value() &&
constexpr T get_value() &&
{
return hpx::get<T>(HPX_MOVE(data));
}
Expand All @@ -56,11 +56,11 @@ namespace hpx {
{
return hpx::get<hpx::future<T>>(data);
}
constexpr hpx::future<T> const& get_future() const&
[[nodiscard]] constexpr hpx::future<T> const& get_future() const&
{
return hpx::get<hpx::future<T>>(data);
}
constexpr hpx::future<T>&& get_future() &&
constexpr hpx::future<T> get_future() &&
{
return hpx::get<hpx::future<T>>(HPX_MOVE(data));
}
Expand Down
30 changes: 15 additions & 15 deletions libs/core/type_support/include/hpx/type_support/extra_data.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
// Copyright (c) 2019 Thomas Heller
// Copyright (c) 2019-2023 Hartmut Kaiser
// Copyright (c) 2019-2024 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)

#pragma once

#include <hpx/assert.hpp>

#include <memory>
#include <type_traits>
#include <utility>

namespace hpx::util {

using extra_data_id_type = void*;
using extra_data_id_type = void const*;

template <typename T>
struct extra_data_helper
Expand Down Expand Up @@ -61,7 +59,12 @@ namespace hpx::util {
~extra_data_node() = default;

template <typename T>
[[nodiscard]] T* get() const noexcept;
[[nodiscard]] constexpr T* get() const noexcept;

[[nodiscard]] explicit constexpr operator bool() const noexcept
{
return id_ != nullptr && ptr_;
}

std::unique_ptr<extra_data_member_base> ptr_;
extra_data_id_type id_ = nullptr;
Expand Down Expand Up @@ -89,7 +92,7 @@ namespace hpx::util {
};

template <typename T>
struct extra_data_member : extra_data_member_base
struct extra_data_member final : extra_data_member_base
{
explicit constexpr extra_data_member(extra_data_node&& next) noexcept
: extra_data_member_base(HPX_MOVE(next))
Expand Down Expand Up @@ -124,17 +127,14 @@ namespace hpx::util {
}

template <typename T>
T* extra_data_node::get() const noexcept
constexpr T* extra_data_node::get() const noexcept
{
auto id = extra_data_id<T>();
if (id_ == nullptr)
if (!*this)
{
HPX_ASSERT(!ptr_);
return nullptr;
}

HPX_ASSERT(ptr_);
if (id_ == id)
if (id_ == extra_data_id<T>())
{
return static_cast<extra_data_member<T>*>(ptr_.get())->value();
}
Expand All @@ -144,7 +144,7 @@ namespace hpx::util {

struct extra_data
{
extra_data() noexcept = default;
constexpr extra_data() noexcept = default;

template <typename T>
T& get()
Expand All @@ -159,9 +159,9 @@ namespace hpx::util {
}

template <typename T>
[[nodiscard]] T* try_get() const noexcept
[[nodiscard]] constexpr T* try_get() const noexcept
{
return head_.get<T>();
return head_ ? head_.get<T>() : nullptr;
}

// reset all extra archive data
Expand Down
2 changes: 1 addition & 1 deletion libs/full/agas/src/detail/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ namespace hpx::agas::detail::impl {
return naming::invalid_gid;
}

// during bootstrap we use the id pool
// during bootstrap, we use the id pool
if (rt->get_state() == state::invalid)
{
return hpx::detail::get_next_id(count);
Expand Down
6 changes: 4 additions & 2 deletions libs/full/async_colocated/src/get_colocation_id.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2020 Hartmut Kaiser
// Copyright (c) 2007-2024 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
//
// SPDX-License-Identifier: BSL-1.0
Expand Down Expand Up @@ -28,6 +28,8 @@ namespace hpx {
{
return hpx::make_ready_future(HPX_MOVE(result).get_value());
}
return HPX_MOVE(result).get_future();

auto f = HPX_MOVE(result).get_future();
return f;
}
} // namespace hpx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ namespace hpx::parcelset {
{
HPX_ASSERT(result.has_future());

auto&& split_gid = HPX_MOVE(result).get_future();
auto split_gid = HPX_MOVE(result).get_future();
if (split_gid.is_ready())
{
pp(detail::create_parcel::call_with_action(
Expand Down
5 changes: 3 additions & 2 deletions libs/full/components/include/hpx/components/client_base.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2007-2024 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -183,7 +183,8 @@ template <>
struct hpx::util::extra_data_helper<hpx::lcos::detail::registered_name_tracker>
{
HPX_EXPORT static extra_data_id_type id() noexcept;
HPX_EXPORT static void reset(lcos::detail::registered_name_tracker*);
HPX_EXPORT static void reset(
lcos::detail::registered_name_tracker*) noexcept;
}; // namespace hpx::util

// Specialization for shared state of id_type, additionally (optionally) holds a
Expand Down
4 changes: 3 additions & 1 deletion libs/full/components/include/hpx/components/get_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ namespace hpx {
{
return hpx::make_ready_future(HPX_MOVE(result).get_value());
}
return HPX_MOVE(result).get_future();

auto f = HPX_MOVE(result).get_future();
return f;
}

/// \brief Returns a future referring to the pointer to the
Expand Down
14 changes: 5 additions & 9 deletions libs/full/components/src/client_base.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2007-2024 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -28,9 +28,9 @@ namespace hpx::util {
}

void extra_data_helper<lcos::detail::registered_name_tracker>::reset(
lcos::detail::registered_name_tracker* registered_name)
lcos::detail::registered_name_tracker* registered_name) noexcept
{
if (!registered_name->empty())
if (registered_name != nullptr && !registered_name->empty())
{
std::string name;
std::swap(name, *registered_name);
Expand All @@ -45,12 +45,8 @@ namespace hpx::lcos::detail {

void future_data<hpx::id_type>::tidy() const noexcept
{
auto* registered_name = try_get_extra_data<registered_name_tracker>();
if (registered_name != nullptr && !registered_name->empty())
{
error_code ec(throwmode::lightweight);
agas::unregister_name(launch::sync, HPX_MOVE(*registered_name), ec);
}
hpx::util::extra_data_helper<registered_name_tracker>::reset(
try_get_extra_data<registered_name_tracker>());
}

std::string const& future_data<hpx::id_type>::get_registered_name()
Expand Down
4 changes: 3 additions & 1 deletion libs/full/components_base/src/agas_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ namespace hpx::agas {
{
return hpx::make_ready_future(HPX_MOVE(result).get_value());
}
return HPX_MOVE(result).get_future();

auto f = HPX_MOVE(result).get_future();
return f;
}

naming::address resolve(
Expand Down

0 comments on commit 9f23e8a

Please sign in to comment.