1 //  Copyright (c) 2011-2017 Thomas Heller
2 //
3 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #ifndef HPX_COMPONENTS_COMPONENT_HEAP_HPP
7 #define HPX_COMPONENTS_COMPONENT_HEAP_HPP
8 
9 #include <hpx/config.hpp>
10 #include <hpx/util/reinitializable_static.hpp>
11 
12 namespace hpx { namespace components {
13     // This is a utility to ensure that there exists exactly one heap
14     // per component.
15     // This is the customization point and will be defined by the registration
16     // macros
17     namespace detail {
18         template <typename Component>
19         struct component_heap_impl;
20 
21         template <typename Component>
22         typename Component::heap_type&
component_heap_helper(typename detail::component_heap_impl<Component>::valid *)23         component_heap_helper(typename detail::component_heap_impl<Component>::valid*)
24         {
25             return detail::component_heap_impl<Component>::call();
26         }
27 
28         template <typename Component> HPX_ALWAYS_EXPORT
29         typename Component::heap_type& component_heap_helper(...);
30     }
31 
32     template <typename Component>
component_heap()33     typename Component::heap_type& component_heap()
34     {
35         return detail::component_heap_helper<Component>(nullptr);
36     }
37 }}
38 
39 #define HPX_REGISTER_COMPONENT_HEAP(Component)                                \
40 namespace hpx { namespace components { namespace detail {                     \
41     template <> HPX_ALWAYS_EXPORT                                             \
42     Component::heap_type& component_heap_helper< Component>(...)              \
43     {                                                                         \
44         util::reinitializable_static<Component::heap_type> heap;              \
45         return heap.get();                                                    \
46     }                                                                         \
47 }}}                                                                           \
48 /**/
49 
50 
51 #endif
52