Skip to content

Commit

Permalink
Merge pull request #2856 from STEllAR-GROUP/fix_ubsan
Browse files Browse the repository at this point in the history
Fixing component handling for lcos
  • Loading branch information
hkaiser committed Aug 27, 2017
2 parents cf6ccf5 + 9fb4e43 commit c71da44
Show file tree
Hide file tree
Showing 11 changed files with 379 additions and 392 deletions.
30 changes: 4 additions & 26 deletions hpx/lcos/base_lco_with_value.hpp
Expand Up @@ -12,7 +12,7 @@
#include <hpx/runtime/actions/basic_action.hpp>
#include <hpx/runtime/actions/component_action.hpp>
#include <hpx/runtime/components/component_type.hpp>
#include <hpx/runtime/components/server/simple_component_base.hpp>
#include <hpx/runtime/components/server/component.hpp>
#include <hpx/runtime/components/server/managed_component_base.hpp>
#include <hpx/runtime/components_fwd.hpp>
#include <hpx/runtime/naming/id_type.hpp>
Expand Down Expand Up @@ -42,13 +42,7 @@ namespace hpx { namespace lcos
template <typename BaseLco>
struct base_lco_wrapping_type<traits::detail::component_tag, BaseLco>
{
typedef components::simple_component<BaseLco> type;
};

template <typename BaseLco>
struct base_lco_wrapping_type<traits::detail::simple_component_tag, BaseLco>
{
typedef components::simple_component<BaseLco> type;
typedef components::component<BaseLco> type;
};

template <typename BaseLco>
Expand Down Expand Up @@ -174,7 +168,8 @@ namespace hpx { namespace lcos
// components must contain a typedef for wrapping_type defining the
// managed_component type used to encapsulate instances of this
// component
typedef components::managed_component<base_lco_with_value> wrapping_type;
typedef typename detail::base_lco_wrapping_type<ComponentTag,
base_lco_with_value>::type wrapping_type;
typedef base_lco_with_value base_type_holder;

// refer to base type for the corresponding implementation
Expand Down Expand Up @@ -208,23 +203,6 @@ namespace hpx { namespace traits
}
};

template <typename Result, typename RemoteResult, typename Enable>
struct component_type_database<
hpx::lcos::base_lco_with_value<
Result, RemoteResult, traits::detail::simple_component_tag
>, Enable>
{
static components::component_type get()
{
return components::component_base_lco_with_value_unmanaged;
}

static void set(components::component_type)
{
HPX_ASSERT(false);
}
};

template <typename Result, typename RemoteResult, typename Enable>
struct component_type_database<
hpx::lcos::base_lco_with_value<
Expand Down
36 changes: 23 additions & 13 deletions hpx/performance_counters/server/base_performance_counter.hpp
Expand Up @@ -20,8 +20,8 @@
namespace hpx { namespace performance_counters { namespace server
{
class base_performance_counter
: public hpx::performance_counters::performance_counter_base
, public hpx::traits::detail::simple_component_tag
: public hpx::performance_counters::performance_counter_base,
public hpx::traits::detail::component_tag
{
protected:
/// the following functions are not implemented by default, they will
Expand All @@ -48,7 +48,8 @@ namespace hpx { namespace performance_counters { namespace server
virtual counter_values_array get_counter_values_array(bool reset)
{
HPX_THROW_EXCEPTION(invalid_status, "get_counter_values_array",
"get_counter_values_array is not implemented for this counter");
"get_counter_values_array is not implemented for this "
"counter");
return counter_values_array();
}

Expand All @@ -68,20 +69,28 @@ namespace hpx { namespace performance_counters { namespace server
}

public:
base_performance_counter() : invocation_count_(0) {}
base_performance_counter()
: invocation_count_(0)
{
}
base_performance_counter(counter_info const& info)
: info_(info), invocation_count_(0)
{}
: info_(info)
, invocation_count_(0)
{
}

// components must contain a typedef for wrapping_type defining the
// component type used to encapsulate instances of this
// component
typedef components::component<base_performance_counter> wrapping_type;
typedef components::component<base_performance_counter>
wrapping_type;
typedef base_performance_counter base_type_holder;

/// \brief finalize() will be called just before the instance gets
/// destructed
void finalize() {}
void finalize()
{
}

static components::component_type get_component_type()
{
Expand Down Expand Up @@ -145,7 +154,8 @@ namespace hpx { namespace performance_counters { namespace server
/// The \a get_counter_value_action queries the value of a performance
/// counter.
HPX_DEFINE_COMPONENT_ACTION(base_performance_counter,
get_counter_values_array_nonvirt, get_counter_values_array_action);
get_counter_values_array_nonvirt,
get_counter_values_array_action);

/// The \a set_counter_value_action
HPX_DEFINE_COMPONENT_ACTION(base_performance_counter,
Expand All @@ -156,12 +166,12 @@ namespace hpx { namespace performance_counters { namespace server
reset_counter_value_nonvirt, reset_counter_value_action);

/// The \a start_action
HPX_DEFINE_COMPONENT_ACTION(base_performance_counter,
start_nonvirt, start_action);
HPX_DEFINE_COMPONENT_ACTION(
base_performance_counter, start_nonvirt, start_action);

/// The \a stop_action
HPX_DEFINE_COMPONENT_ACTION(base_performance_counter,
stop_nonvirt, stop_action);
HPX_DEFINE_COMPONENT_ACTION(
base_performance_counter, stop_nonvirt, stop_action);

protected:
hpx::performance_counters::counter_info info_;
Expand Down
2 changes: 1 addition & 1 deletion hpx/runtime/components/component_type.hpp
Expand Up @@ -70,7 +70,7 @@ namespace hpx { namespace components
component_first_dynamic = component_last,

// Force this enum type to be at least 32 bits.
component_upper_bound = 0x7fffffffL //-V112
component_upper_bound = 0x7fffffffL //-V112
};

enum factory_state_enum
Expand Down
4 changes: 2 additions & 2 deletions hpx/runtime/components/server/abstract_component_base.hpp
Expand Up @@ -22,14 +22,14 @@ namespace hpx { namespace components
{
///////////////////////////////////////////////////////////////////////////
template <typename Component>
class simple_component;
class component;

template <typename Component>
class abstract_simple_component_base
: private traits::detail::component_tag
{
private:
typedef simple_component<Component> outer_wrapping_type;
typedef component<Component> outer_wrapping_type;

public:
virtual ~abstract_simple_component_base() {}
Expand Down
60 changes: 53 additions & 7 deletions hpx/runtime/components/server/component.hpp
@@ -1,4 +1,6 @@
// Copyright (c) 2015 Thomas Heller
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2015-2017 Thomas Heller
// Copyright (c) 2011 Bryce Lelbach
//
// 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)
Expand All @@ -7,23 +9,67 @@
#define HPX_RUNTIME_COMPONENTS_SERVER_COMPONENT_HPP

#include <hpx/config.hpp>
#include <hpx/util/assert.hpp>

#include <hpx/runtime/components/server/simple_component_base.hpp>

#include <cstddef>
#include <new>
#include <utility>

namespace hpx { namespace components {

namespace detail {
///////////////////////////////////////////////////////////////////////
template <typename Component>
struct simple_heap_factory
{
static void* alloc(std::size_t count)
{
HPX_ASSERT(1 == count);
return ::operator new(sizeof(Component));
}
static void free(void* p, std::size_t count)
{
HPX_ASSERT(1 == count);
::operator delete(p);
}
};
}

///////////////////////////////////////////////////////////////////////////
template <typename Component>
class component
: public simple_component<Component>
class component : public Component
{
public:
typedef Component type_holder;
typedef component<Component> component_type;
typedef component_type derived_type;
typedef detail::simple_heap_factory<component_type> heap_type;

/// \brief Construct a simple_component instance holding a new wrapped
/// instance
template <typename ...Ts>
template <typename... Ts>
component(Ts&&... vs)
: simple_component<Component>(std::forward<Ts>(vs)...)
: Component(std::forward<Ts>(vs)...)
{}

/// \brief The function \a create is used for allocation and
/// initialization of instances of the derived components.
static component_type* create(std::size_t count)
{
// simple components can be created individually only
HPX_ASSERT(1 == count);
return new component_type(); //-V572
}

/// \brief The function \a destroy is used for destruction and
/// de-allocation of instances of the derived components.
static void destroy(Component* p, std::size_t count = 1)
{
// simple components can be deleted individually only
HPX_ASSERT(1 == count);
p->finalize();
delete p;
}
};
}}

Expand Down

0 comments on commit c71da44

Please sign in to comment.