libs/core/coroutines/CMakeLists.txt | 1 +
.../hpx/coroutines/detail/context_posix.hpp | 17 ++++++++---------
libs/core/coroutines/src/detail/context_posix.cpp | 22 ++++++++++++++++++++++
3 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/libs/core/coroutines/CMakeLists.txt b/libs/core/coroutines/CMakeLists.txt
index 06c6dde6b53..210821b9581 100644
--- a/libs/core/coroutines/CMakeLists.txt
+++ b/libs/core/coroutines/CMakeLists.txt
@@ -52,6 +52,7 @@ set(coroutines_compat_headers
set(coroutines_sources
detail/context_base.cpp
+ detail/context_posix.cpp
detail/coroutine_impl.cpp
detail/coroutine_self.cpp
detail/posix_utility.cpp
diff --git a/libs/core/coroutines/include/hpx/coroutines/detail/context_posix.hpp b/libs/core/coroutines/include/hpx/coroutines/detail/context_posix.hpp
index 405722e2dba..5c27bfc67f5 100644
--- a/libs/core/coroutines/include/hpx/coroutines/detail/context_posix.hpp
+++ b/libs/core/coroutines/include/hpx/coroutines/detail/context_posix.hpp
@@ -65,6 +65,7 @@
#include <cstdint>
#include <exception>
#include <limits>
+
#include "pth/pth.h"
namespace hpx { namespace threads { namespace coroutines { namespace detail {
@@ -96,7 +97,7 @@ namespace hpx { namespace threads { namespace coroutines { namespace detail {
hpx::threads::coroutines::detail::posix::pth::check_( \
pth_uctx_destroy(ctx))
-#else // generic Posix platform (e.g. OS X >= 10.5)
+#else // generic Posix platform (e.g. OS X >= 10.5)
/*
* makecontext based context implementation. Should be available on all
@@ -184,6 +185,10 @@ namespace hpx { namespace threads { namespace coroutines {
class ucontext_context_impl_base : detail::context_impl_base
{
public:
+ // on some platforms SIGSTKSZ resolves to a syscall, we can't make
+ // this constexpr
+ HPX_CORE_EXPORT static std::ptrdiff_t default_stack_size;
+
ucontext_context_impl_base()
{
HPX_COROUTINE_CREATE_CONTEXT(m_ctx);
@@ -219,19 +224,13 @@ namespace hpx { namespace threads { namespace coroutines {
public:
typedef ucontext_context_impl_base context_impl_base;
- enum
- {
- default_stack_size = SIGSTKSZ
- };
-
/**
* Create a context that on restore invokes Functor on
* a new stack. The stack size can be optionally specified.
*/
explicit ucontext_context_impl(std::ptrdiff_t stack_size = -1)
- : m_stack_size(stack_size == -1 ?
- static_cast<std::ptrdiff_t>(default_stack_size) :
- stack_size)
+ : m_stack_size(
+ stack_size == -1 ? this->default_stack_size : stack_size)
, m_stack(nullptr)
, funp_(&trampoline<CoroutineImpl>)
{
diff --git a/libs/core/coroutines/src/detail/context_posix.cpp b/libs/core/coroutines/src/detail/context_posix.cpp
new file mode 100644
index 00000000000..c0c3ce65091
--- /dev/null
+++ b/libs/core/coroutines/src/detail/context_posix.cpp
@@ -0,0 +1,22 @@
+// Copyright (c) 2021 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)
+
+#include <hpx/config.hpp>
+
+#if defined(_POSIX_VERSION) || defined(__bgq__) || defined(__powerpc__) || \
+ defined(__s390x__)
+#include <hpx/coroutines/detail/context_posix.hpp>
+
+#include <cstddef>
+
+namespace hpx { namespace threads { namespace coroutines { namespace detail {
+ namespace posix {
+
+ std::ptrdiff_t ucontext_context_impl_base::default_stack_size =
+ SIGSTKSZ;
+}}}}} // namespace hpx::threads::coroutines::detail::posix
+
+#endif