• 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

85.0
/libs/core/functional/src/basic_function.cpp
1
//  Copyright (c) 2011 Thomas Heller
2
//  Copyright (c) 2013-2022 Hartmut Kaiser
3
//  Copyright (c) 2014-2019 Agustin Berge
4
//  Copyright (c) 2017 Google
5
//
6
//  SPDX-License-Identifier: BSL-1.0
7
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
8
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9

10
#include <hpx/assert.hpp>
11
#include <hpx/functional/detail/basic_function.hpp>
12
#include <hpx/functional/detail/empty_function.hpp>
13
#include <hpx/functional/detail/vtable/function_vtable.hpp>
14
#include <hpx/functional/detail/vtable/vtable.hpp>
15
#include <hpx/functional/traits/get_function_address.hpp>
16
#include <hpx/functional/traits/get_function_annotation.hpp>
17
#include <hpx/modules/itt_notify.hpp>
18
#include <hpx/modules/tag_invoke.hpp>
19

20
#include <cstddef>
21
#include <cstring>
22
#include <new>
23
#include <string>
24
#include <type_traits>
25
#include <utility>
26

27
namespace hpx::util::detail {
28

29
    ///////////////////////////////////////////////////////////////////////////
30
    function_base::function_base(
255,650✔
31
        function_base const& other, vtable const* /* empty_vtable */)
255,650✔
32
      : vptr(other.vptr)
255,650✔
33
      , object(other.object)
255,650✔
34
      , storage_init()
255,650✔
35
    {
36
        if (other.object != nullptr)
255,650✔
37
        {
38
            object = vptr->copy(storage, detail::function_storage_size,
12,447✔
39
                other.object, /*destroy*/ false);
40
        }
41
    }
255,650✔
42

43
    function_base::function_base(
268,591✔
44
        function_base&& other, vtable const* empty_vptr) noexcept
268,591✔
45
      : vptr(other.vptr)
268,591✔
46
      , object(other.object)
268,591✔
47
      , storage_init()
268,591✔
48
    {
49
        if (object == &other.storage)
268,591✔
50
        {
51
            std::memcpy(storage, other.storage, function_storage_size);
116,513✔
52
            object = &storage;
116,513✔
53
        }
54

55
        other.vptr = empty_vptr;
268,591✔
56
        other.object = nullptr;
268,591✔
57
    }
268,591✔
58

59
    function_base::~function_base()
903,069✔
60
    {
61
        destroy();
903,069✔
62
    }
903,069✔
63

64
    void function_base::op_assign(
288✔
65
        function_base const& other, vtable const* /* empty_vtable */)
66
    {
67
        if (vptr == other.vptr)
288✔
68
        {
69
            if (this != &other && object)
32✔
70
            {
71
                HPX_ASSERT(other.object != nullptr);
72

73
                // reuse object storage
74
                object = vptr->copy(object, static_cast<std::size_t>(-1),
×
75
                    other.object, /*destroy*/ true);
×
76
            }
77
        }
78
        else
79
        {
80
            destroy();
256✔
81
            vptr = other.vptr;
256✔
82
            if (other.object != nullptr)
256✔
83
            {
84
                object = vptr->copy(storage, detail::function_storage_size,
256✔
85
                    other.object, /*destroy*/ false);
86
            }
87
            else
88
            {
89
                object = nullptr;
×
90
            }
91
        }
92
    }
288✔
93

94
    void function_base::op_assign(
103,758✔
95
        function_base&& other, vtable const* empty_vtable) noexcept
96
    {
97
        if (this != &other)
103,758✔
98
        {
99
            swap(other);
103,758✔
100
            other.reset(empty_vtable);
103,758✔
101
        }
102
    }
103,758✔
103

104
    void function_base::destroy() const noexcept
1,183,914✔
105
    {
106
        if (object != nullptr)
1,183,914✔
107
        {
108
            vptr->deallocate(object, function_storage_size, /*destroy*/ true);
144,001✔
109
        }
110
    }
1,183,914✔
111

112
    void function_base::reset(vtable const* empty_vptr) noexcept
149,291✔
113
    {
114
        destroy();
149,291✔
115
        vptr = empty_vptr;
149,291✔
116
        object = nullptr;
149,291✔
117
    }
149,291✔
118

119
    void function_base::swap(function_base& f) noexcept
103,758✔
120
    {
121
        std::swap(vptr, f.vptr);
122
        std::swap(object, f.object);
123
        std::swap(storage, f.storage);
103,758✔
124
        if (object == &f.storage)
103,758✔
125
            object = &storage;
8,558✔
126
        if (f.object == &storage)
103,758✔
127
            f.object = &f.storage;
6,000✔
128
    }
103,758✔
129

130
    std::size_t function_base::get_function_address() const
×
131
    {
132
#if defined(HPX_HAVE_THREAD_DESCRIPTION)
133
        return vptr->get_function_address(object);
134
#else
135
        return 0;
×
136
#endif
137
    }
138

139
    char const* function_base::get_function_annotation() const
×
140
    {
141
#if defined(HPX_HAVE_THREAD_DESCRIPTION)
142
        return vptr->get_function_annotation(object);
143
#else
144
        return nullptr;
×
145
#endif
146
    }
147

148
    util::itt::string_handle function_base::get_function_annotation_itt() const
×
149
    {
150
#if HPX_HAVE_ITTNOTIFY != 0 && !defined(HPX_HAVE_APEX)
151
        return vptr->get_function_annotation_itt(object);
152
#else
153
        return util::itt::string_handle{};
×
154
#endif
155
    }
156
}    // namespace hpx::util::detail
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