• 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/execution/src/polymorphic_executor.cpp
1
//  Copyright (c) 2020-2022 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
#include <hpx/config.hpp>
8
#include <hpx/assert.hpp>
9
#include <hpx/execution/executors/polymorphic_executor.hpp>
10
#include <hpx/modules/errors.hpp>
11

12
#include <cstddef>
13
#include <cstring>
14
#include <new>
15
#include <string>
16
#include <type_traits>
17
#include <utility>
18

19
namespace hpx::parallel::execution::detail {
20

21
    ///////////////////////////////////////////////////////////////////////////
22
    [[noreturn]] void throw_bad_polymorphic_executor()
×
23
    {
24
        hpx::throw_exception(hpx::error::bad_function_call,
×
25
            "empty polymorphic_executor object should not be used",
26
            "polymorphic_executor::operator()");
27
    }
28

29
    ///////////////////////////////////////////////////////////////////////////
30
    polymorphic_executor_base::polymorphic_executor_base(
×
31
        polymorphic_executor_base const& other,
32
        vtable const* /* empty_vtable */)
×
33
      : vptr(other.vptr)
×
34
      , object(other.object)
×
35
      , storage_init()
×
36
    {
37
        if (other.object != nullptr)
×
38
        {
39
            object = vptr->copy(storage, polymorphic_executor_storage_size,
×
40
                other.object, false);
41
        }
42
    }
×
43

44
    polymorphic_executor_base::polymorphic_executor_base(
×
45
        polymorphic_executor_base&& other, vtable const* empty_vptr) noexcept
×
46
      : vptr(other.vptr)
×
47
      , object(other.object)
×
48
      , storage_init()
×
49
    {
50
        if (object == &other.storage)
×
51
        {
52
            std::memcpy(
×
53
                storage, other.storage, polymorphic_executor_storage_size);
×
54
            object = &storage;
×
55
        }
56
        other.vptr = empty_vptr;
×
57
        other.object = nullptr;
×
58
    }
×
59

60
    polymorphic_executor_base::~polymorphic_executor_base()
×
61
    {
62
        destroy();
×
63
    }
×
64

65
    void polymorphic_executor_base::op_assign(
×
66
        polymorphic_executor_base const& other,
67
        vtable const* /* empty_vtable */)
68
    {
69
        if (vptr == other.vptr)
×
70
        {
71
            if (this != &other && object)
×
72
            {
73
                // reuse object storage
74
                HPX_ASSERT(other.object != nullptr);
75
                object =
×
76
                    vptr->copy(object, std::size_t(-1), other.object, true);
×
77
            }
78
        }
79
        else
80
        {
81
            destroy();
×
82
            vptr = other.vptr;
×
83
            if (other.object != nullptr)
×
84
            {
85
                object = vptr->copy(storage, polymorphic_executor_storage_size,
×
86
                    other.object, false);
87
            }
88
            else
89
            {
90
                object = nullptr;
×
91
            }
92
        }
93
    }
×
94

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

105
    void polymorphic_executor_base::destroy() noexcept
×
106
    {
107
        if (object != nullptr)
×
108
        {
109
            vptr->deallocate(object, polymorphic_executor_storage_size, true);
×
110
        }
111
    }
×
112

113
    void polymorphic_executor_base::reset(vtable const* empty_vptr) noexcept
×
114
    {
115
        destroy();
×
116
        vptr = empty_vptr;
×
117
        object = nullptr;
×
118
    }
×
119

120
    void polymorphic_executor_base::swap(polymorphic_executor_base& f) noexcept
×
121
    {
122
        std::swap(vptr, f.vptr);
123
        std::swap(object, f.object);
124
        std::swap(storage, f.storage);
×
125
        if (object == &f.storage)
×
126
            object = &storage;
×
127
        if (f.object == &storage)
×
128
            f.object = &f.storage;
×
129
    }
×
130
}    // namespace hpx::parallel::execution::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