Skip to content

Commit

Permalink
Moving hpx::threads::run_as_xxx to namespace hpx
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Sep 14, 2023
1 parent c8ea2c7 commit 496f4ba
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion components/process/src/server/child_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace hpx { namespace components { namespace process { namespace server
{
int (*f)(process::util::child const&) =
&process::util::wait_for_exit<process::util::child>;
return hpx::threads::run_as_os_thread(f, std::ref(child_)).get();
return hpx::run_as_os_thread(f, std::ref(child_)).get();
}
}}}}

6 changes: 3 additions & 3 deletions examples/quickstart/init_globally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ void thread_func()

// Create an HPX thread (returning an int) and wait for it to run to
// completion.
int result = hpx::threads::run_as_hpx_thread(&hpx_thread_func2, 42);
int result = hpx::run_as_hpx_thread(&hpx_thread_func2, 42);

// Create an HPX thread (returning void) and wait for it to run to
// completion.
if (result == 42)
hpx::threads::run_as_hpx_thread(&hpx_thread_func1);
hpx::run_as_hpx_thread(&hpx_thread_func1);
}

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -286,7 +286,7 @@ int main()

// The main thread was automatically registered with the HPX runtime,
// no explicit registration for this thread is necessary.
hpx::threads::run_as_hpx_thread(&hpx_thread_func1);
hpx::run_as_hpx_thread(&hpx_thread_func1);

// wait for the (kernel) thread to run to completion
t.join();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#include <type_traits>
#include <utility>

namespace hpx { namespace threads {
namespace hpx {

///////////////////////////////////////////////////////////////////////////
namespace detail {
// This is the overload for running functions which return a value.
Expand Down Expand Up @@ -148,4 +149,17 @@ namespace hpx { namespace threads {
return detail::run_as_hpx_thread(
result_is_void(), f, HPX_FORWARD(Ts, vs)...);
}
}} // namespace hpx::threads
} // namespace hpx

namespace hpx::threads {

template <typename F, typename... Ts>
HPX_DEPRECATED_V(1, 10,
"hpx::threads::run_as_hpx_thread is deprecated, use "
"hpx::run_as_hpx_thread instead")
decltype(auto) run_as_hpx_thread(F const& f, Ts&&... ts)
{
return hpx::run_as_hpx_thread(
HPX_FORWARD(F, f), HPX_FORWARD(Ts, ts)...);
}
} // namespace hpx::threads
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,30 @@
#include <type_traits>
#include <utility>

namespace hpx { namespace threads {
namespace hpx {

///////////////////////////////////////////////////////////////////////////
template <typename F, typename... Ts>
hpx::future<typename util::invoke_result<F, Ts...>::type> run_as_os_thread(
hpx::future<util::invoke_result_t<F, Ts...>> run_as_os_thread(
F&& f, Ts&&... vs)
{
HPX_ASSERT(get_self_ptr() != nullptr);
HPX_ASSERT(threads::get_self_ptr() != nullptr);

parallel::execution::io_pool_executor executor;
auto result = parallel::execution::async_execute(
executor, HPX_FORWARD(F, f), HPX_FORWARD(Ts, vs)...);
return result;
}
}} // namespace hpx::threads
} // namespace hpx

namespace hpx::threads {

template <typename F, typename... Ts>
HPX_DEPRECATED_V(1, 10,
"hpx::threads::run_as_os_thread is deprecated, use "
"hpx::run_as_os_thread instead")
decltype(auto) run_as_os_thread(F const& f, Ts&&... ts)
{
return hpx::run_as_os_thread(HPX_FORWARD(F, f), HPX_FORWARD(Ts, ts)...);
}
} // namespace hpx::threads
2 changes: 1 addition & 1 deletion libs/full/collectives/src/barrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ namespace hpx { namespace distributed {
// make sure this runs as an HPX thread
if (hpx::threads::get_self_ptr() == nullptr)
{
hpx::threads::run_as_hpx_thread(&barrier::release, this);
hpx::run_as_hpx_thread(&barrier::release, this);
}

hpx::future<void> f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int main(int argc, char** argv)
bool exception_caught = false;
try
{
hpx::threads::run_as_hpx_thread(&hpx_thread_func);
hpx::run_as_hpx_thread(&hpx_thread_func);
HPX_TEST(false); // this should not be executed
}
catch (...)
Expand Down
2 changes: 1 addition & 1 deletion tests/regressions/threads/run_as_os_thread_lockup_2991.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int hpx_main()

std::cout << std::this_thread::get_id()
<< ": about to run on io thread\n";
hpx::threads::run_as_os_thread(locker);
hpx::run_as_os_thread(locker);
//sleep(2);
}
std::cout << std::this_thread::get_id() << ": exiting\n";
Expand Down

0 comments on commit 496f4ba

Please sign in to comment.