• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/core/threading_base/include/hpx/threading_base/annotated_function.hpp
1
//  Copyright (c) 2017-2023 Hartmut Kaiser
2
//
3
//  SPDX-License-Identifier: BSL-1.0
4
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
/// \page hpx::annotated_function
8
/// \headerfile hpx/functional.hpp
9

10
#pragma once
11

12
#include <hpx/config.hpp>
13

14
#if defined(HPX_HAVE_THREAD_DESCRIPTION)
15
#include <hpx/modules/functional.hpp>
16
#include <hpx/modules/tag_invoke.hpp>
17
#include <hpx/modules/type_support.hpp>
18
#include <hpx/threading_base/scoped_annotation.hpp>
19
#include <hpx/threading_base/thread_description.hpp>
20
#include <hpx/threading_base/thread_helpers.hpp>
21

22
#if HPX_HAVE_ITTNOTIFY != 0
23
#include <hpx/modules/itt_notify.hpp>
24
#elif defined(HPX_HAVE_APEX)
25
#include <hpx/threading_base/external_timer.hpp>
26
#endif
27
#endif
28

29
#include <cstddef>
30
#include <string>
31
#include <type_traits>
32
#include <utility>
33

34
namespace hpx {
35

36
#if defined(HPX_HAVE_THREAD_DESCRIPTION)
37
    ///////////////////////////////////////////////////////////////////////////
38
    namespace detail {
39

40
        template <typename F>
41
        struct annotated_function
42
        {
43
            using fun_type = util::decay_unwrap_t<F>;
44

45
            annotated_function() noexcept
46
              : name_(nullptr)
47
            {
48
            }
49

50
            annotated_function(F const& f, char const* name)
51
              : f_(f)
52
              , name_(name)
53
            {
54
            }
55

56
            annotated_function(F&& f, char const* name)
57
              : f_(HPX_MOVE(f))
58
              , name_(name)
59
            {
60
            }
61

62
            template <typename... Ts>
63
            hpx::util::invoke_result_t<fun_type, Ts...> operator()(Ts&&... ts)
64
            {
65
                scoped_annotation annotate(get_function_annotation());
66
                return HPX_INVOKE(f_, HPX_FORWARD(Ts, ts)...);
67
            }
68

69
            template <typename Archive>
70
            void serialize(Archive& ar, unsigned int const /*version*/)
71
            {
72
                // clang-format off
73
                ar & f_;
74
                // clang-format on
75
            }
76

77
            ///////////////////////////////////////////////////////////////////
78
            /// \brief Returns the function address
79
            ///
80
            /// This function returns the passed function address.
81
            constexpr std::size_t get_function_address() const noexcept
82
            {
83
                return traits::get_function_address<fun_type>::call(f_);
84
            }
85

86
            ///////////////////////////////////////////////////////////////////
87
            /// \brief Returns the function annotation
88
            ///
89
            /// This function returns the function annotation, if it has a name
90
            /// it is returned; if name is empty the typeid is returned
91
            constexpr char const* get_function_annotation() const noexcept
92
            {
93
                return name_ ? name_ : typeid(f_).name();
94
            }
95

96
            constexpr fun_type const& get_bound_function() const noexcept
97
            {
98
                return f_;
99
            }
100

101
        private:
102
            fun_type f_;
103
            char const* name_;
104
        };
105
    }    // namespace detail
106

107
    HPX_CXX_EXPORT template <typename F>
108
    detail::annotated_function<std::decay_t<F>> annotated_function(
109
        F&& f, char const* name = nullptr)
110
    {
111
        using result_type = detail::annotated_function<std::decay_t<F>>;
112

113
        return result_type(HPX_FORWARD(F, f), name);
114
    }
115

116
    HPX_CXX_EXPORT template <typename F>
117
    detail::annotated_function<std::decay_t<F>> annotated_function(
118
        F&& f, std::string name)
119
    {
120
        using result_type = detail::annotated_function<std::decay_t<F>>;
121

122
        // Store string in a set to ensure it lives for the entire duration of
123
        // the task.
124
        char const* name_c_str =
125
            hpx::detail::store_function_annotation(HPX_MOVE(name));
126
        return result_type(HPX_FORWARD(F, f), name_c_str);
127
    }
128

129
#else
130
    ///////////////////////////////////////////////////////////////////////////
131
    /// \brief Returns a function annotated with the given annotation.
132
    ///
133
    /// Annotating includes setting the thread description per thread id.
134
    ///
135
    /// \param f Function to annotate
136
    HPX_CXX_EXPORT template <typename F>
×
137
    constexpr F&& annotated_function(F&& f, char const* = nullptr) noexcept
138
    {
×
139
        return HPX_FORWARD(F, f);
140
    }
141

142
    HPX_CXX_EXPORT template <typename F>
143
    constexpr F&& annotated_function(F&& f, std::string const&) noexcept
144
    {
145
        return HPX_FORWARD(F, f);
146
    }
147
#endif
148
}    // namespace hpx
149

150
#if defined(HPX_HAVE_THREAD_DESCRIPTION)
151

152
///////////////////////////////////////////////////////////////////////////
153
HPX_CXX_EXPORT template <typename F>
154
struct hpx::traits::get_function_address<hpx::detail::annotated_function<F>>
155
{
156
    static constexpr std::size_t call(
157
        hpx::detail::annotated_function<F> const& f) noexcept
158
    {
159
        return f.get_function_address();
160
    }
161
};
162

163
HPX_CXX_EXPORT template <typename F>
164
struct hpx::traits::get_function_annotation<hpx::detail::annotated_function<F>>
165
{
166
    static constexpr char const* call(
167
        hpx::detail::annotated_function<F> const& f) noexcept
168
    {
169
        return f.get_function_annotation();
170
    }
171
};
172

173
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc