Skip to content

Commit

Permalink
Fixing test failure
Browse files Browse the repository at this point in the history
- flyby: remove stubs from example
  • Loading branch information
hkaiser committed Aug 18, 2023
1 parent 4f676fe commit 268b225
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) 2007-2012 Hartmut Kaiser
// Copyright (c) 2007-2023 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(HPX_COMPUTE_DEVICE_CODE)
#include <hpx/hpx.hpp>
#include <hpx/include/components.hpp>
#include <hpx/serialization.hpp>
#include <hpx/include/serialization.hpp>

#include "server/cancelable_action.hpp"

Expand All @@ -17,8 +17,8 @@
HPX_REGISTER_COMPONENT_MODULE()

///////////////////////////////////////////////////////////////////////////////
typedef hpx::components::component<examples::server::cancelable_action>
cancelable_action_component_type;
using cancelable_action_component_type =
hpx::components::component<examples::server::cancelable_action>;

HPX_REGISTER_COMPONENT(cancelable_action_component_type, cancelable_action)

Expand Down
22 changes: 12 additions & 10 deletions examples/cancelable_action/cancelable_action/cancelable_action.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2011 Hartmut Kaiser
// Copyright (c) 2007-2023 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -11,21 +11,21 @@
#include <hpx/assert.hpp>
#include <hpx/include/components.hpp>

#include "stubs/cancelable_action.hpp"
#include "server/cancelable_action.hpp"

#include <utility>

namespace examples {

///////////////////////////////////////////////////////////////////////////
// Client side representation for for the \a server::cancelable_action
// component.
class cancelable_action
: public hpx::components::client_base<cancelable_action,
stubs::cancelable_action>
server::cancelable_action>
{
typedef hpx::components::client_base<cancelable_action,
stubs::cancelable_action>
base_type;
using base_type = hpx::components::client_base<cancelable_action,
server::cancelable_action>;

public:
// Default construct an empty client side representation (not
Expand All @@ -45,16 +45,18 @@ namespace examples {
}

///////////////////////////////////////////////////////////////////////
void do_it(hpx::error_code& ec = hpx::throws)
void do_it(hpx::error_code& ec = hpx::throws) const
{
using action_type = server::cancelable_action::do_it_action;
HPX_ASSERT(this->get_id());
this->base_type::do_it(this->get_id(), ec);
hpx::async<action_type>(this->get_id()).get(ec);
}

void cancel_it()
void cancel_it() const
{
using action_type = server::cancelable_action::cancel_it_action;
HPX_ASSERT(this->get_id());
this->base_type::cancel_it(this->get_id());
hpx::post<action_type>(this->get_id());
}
};
} // namespace examples
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2022 Hartmut Kaiser
// Copyright (c) 2007-2023 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -7,18 +7,22 @@
#pragma once

#include <hpx/config.hpp>

#if !defined(HPX_COMPUTE_DEVICE_CODE)
#include <hpx/hpx.hpp>
#include <hpx/assert.hpp>

#include <hpx/include/actions.hpp>
#include <hpx/include/components.hpp>
#include <hpx/include/lcos.hpp>
#include <hpx/include/threads.hpp>
#include <hpx/include/util.hpp>

#include <memory>
#include <mutex>

///////////////////////////////////////////////////////////////////////////////
namespace examples { namespace server {
namespace examples::server {

///////////////////////////////////////////////////////////////////////////
inline void delay(int c)
{
Expand Down Expand Up @@ -50,24 +54,29 @@ namespace examples { namespace server {
explicit reset_id(cancelable_action& this_)
: outer_(this_)
{
std::lock_guard<hpx::mutex> l(outer_.mtx_);
hpx::thread::id old_value = outer_.id_;
auto const mtx = outer_.mtx_;
std::lock_guard<hpx::mutex> l(*mtx);

[[maybe_unused]] hpx::thread::id const old_value = outer_.id_;
outer_.id_ = hpx::this_thread::get_id();
HPX_ASSERT(old_value == hpx::thread::id());
HPX_UNUSED(old_value);
}
~reset_id()
{
hpx::thread::id old_value = outer_.id_;
[[maybe_unused]] hpx::thread::id const old_value = outer_.id_;
outer_.id_ = hpx::thread::id();
HPX_ASSERT(old_value != hpx::thread::id());
HPX_UNUSED(old_value);
}

cancelable_action& outer_;
};

public:
cancelable_action()
: mtx_(std::make_shared<hpx::mutex>())
{
}

// Do some lengthy work
void do_it()
{
Expand All @@ -85,15 +94,17 @@ namespace examples { namespace server {
}

// Cancel the lengthy action above
void cancel_it()
void cancel_it() const
{
// Make sure id_ has been set
hpx::util::yield_while([this]() {
std::lock_guard<hpx::mutex> l(mtx_);
auto const mtx = mtx_;
std::lock_guard<hpx::mutex> l(*mtx);
return id_ == hpx::thread::id();
});

std::lock_guard<hpx::mutex> l(mtx_);
auto const mtx = mtx_;
std::lock_guard<hpx::mutex> l(*mtx);
HPX_ASSERT(id_ != hpx::thread::id());
hpx::thread::interrupt(id_);
}
Expand All @@ -103,10 +114,10 @@ namespace examples { namespace server {
cancelable_action, cancel_it, cancel_it_action)

private:
hpx::mutex mtx_;
std::shared_ptr<hpx::mutex> mtx_;
hpx::thread::id id_;
};
}} // namespace examples::server
} // namespace examples::server

///////////////////////////////////////////////////////////////////////////////
HPX_REGISTER_ACTION_DECLARATION(
Expand Down

This file was deleted.

5 changes: 3 additions & 2 deletions examples/cancelable_action/cancelable_action_client.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// Copyright (c) 2007-2012 Hartmut Kaiser
// Copyright (c) 2007-2023 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(HPX_COMPUTE_DEVICE_CODE)
#include <hpx/hpx.hpp>
#include <hpx/hpx_init.hpp>

#include "cancelable_action/cancelable_action.hpp"

///////////////////////////////////////////////////////////////////////////////
void interrupt_do_it(examples::cancelable_action ca)
void interrupt_do_it(examples::cancelable_action const& ca)
{
// wait for one second before interrupting the (possibly remote) operation
hpx::this_thread::sleep_for(std::chrono::seconds(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

#if defined(HPX_HAVE_NETWORKING)

namespace hpx::parcelset
{
namespace hpx::parcelset {

// force linking with this module
HPX_EXPORT void init_all_parcelports();
}
} // namespace hpx::parcelset

#endif

0 comments on commit 268b225

Please sign in to comment.