Skip to content

Commit

Permalink
Enable lcos::channel<T>::register_as
Browse files Browse the repository at this point in the history
- add test
  • Loading branch information
hkaiser committed Jun 28, 2017
1 parent 00a9882 commit 40a0f95
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
1 change: 1 addition & 0 deletions hpx/include/traits.hpp
Expand Up @@ -20,6 +20,7 @@
#include <hpx/traits/action_stacksize.hpp>
#include <hpx/traits/action_was_object_migrated.hpp>
#include <hpx/traits/component_config_data.hpp>
#include <hpx/traits/component_get_id.hpp>
#include <hpx/traits/component_supports_migration.hpp>
#include <hpx/traits/component_type_database.hpp>
#include <hpx/traits/component_type_is_compatible.hpp>
Expand Down
18 changes: 17 additions & 1 deletion hpx/runtime/components/client_base.hpp
Expand Up @@ -17,6 +17,7 @@
#include <hpx/throw_exception.hpp>
#include <hpx/traits/acquire_future.hpp>
#include <hpx/traits/action_remote_result.hpp>
#include <hpx/traits/component_get_id.hpp>
#include <hpx/traits/future_access.hpp>
#include <hpx/traits/future_traits.hpp>
#include <hpx/traits/is_client.hpp>
Expand Down Expand Up @@ -141,6 +142,19 @@ namespace hpx { namespace traits
typedef id_type type;
};
}

///////////////////////////////////////////////////////////////////////////
template <typename Client>
struct component_get_id<Client,
typename std::enable_if<is_client<Client>::value>::type>
{
template <typename Derived, typename Stub>
static hpx::id_type call(
components::client_base<Derived, Stub> const& client)
{
return client.get();
}
};
}}

namespace hpx { namespace lcos { namespace detail
Expand Down Expand Up @@ -529,7 +543,9 @@ namespace hpx { namespace components
static void register_as_helper(Derived && f,
std::string const& symbolic_name)
{
hpx::agas::register_name(launch::sync, symbolic_name, f.get());
hpx::agas::register_name(launch::sync, symbolic_name,
hpx::traits::component_get_id<Derived>::call(
std::forward<Derived>(f)));
}

public:
Expand Down
17 changes: 17 additions & 0 deletions hpx/traits/component_get_id.hpp
@@ -0,0 +1,17 @@
// Copyright (c) 2007-2017 Hartmut Kaiser
//
// 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)

#if !defined(HPX_TRAITS_COMPONENT_GET_ID_JUN_28_2017_0428PM)
#define HPX_TRAITS_COMPONENT_GET_ID_JUN_28_2017_0428PM

#include <hpx/config.hpp>

namespace hpx { namespace traits
{
template <typename Component, typename Enable = void>
struct component_get_id;
}}

#endif
1 change: 1 addition & 0 deletions tests/regressions/lcos/CMakeLists.txt
Expand Up @@ -12,6 +12,7 @@ set(tests
async_unwrap_1037
barrier_hang
call_promise_get_gid_more_than_once
channel_register_as_2722
dataflow_791
dataflow_action_2008
dataflow_const_functor_773
Expand Down
47 changes: 47 additions & 0 deletions tests/regressions/lcos/channel_register_as_2722.cpp
@@ -0,0 +1,47 @@
// Copyright (c) 2017 Zach Byerly
//
// 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/hpx.hpp>
#include <hpx/hpx_init.hpp>
#include <hpx/util/lightweight_test.hpp>

HPX_REGISTER_CHANNEL(int); // add to one source file

void send_values(hpx::lcos::channel<int> buffer)
{
buffer.set(hpx::launch::sync, 42);
buffer.set(hpx::launch::sync, 42);
}

void receive_values()
{
hpx::lcos::channel<int> buffer;
buffer.connect_to("my_channel");

HPX_TEST_EQ(42, buffer.get(hpx::launch::sync));
HPX_TEST_EQ(42, buffer.get(hpx::launch::sync));
}

int hpx_main(int argc, char **argv)
{
{
hpx::lcos::channel<int> buffer(hpx::find_here());
buffer.register_as("my_channel");

hpx::future<void> f1 = hpx::async(&send_values, buffer);
hpx::future<void> f2 = hpx::async(&receive_values);

hpx::wait_all(f1, f2);

} // unregisters 'buffer'

return hpx::finalize();
}

int main(int argc, char **argv)
{
HPX_TEST_EQ(0, hpx::init(argc, argv));
return hpx::util::report_errors();
}

0 comments on commit 40a0f95

Please sign in to comment.