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

STEllAR-GROUP / hpx / #853

19 Dec 2022 01:01AM UTC coverage: 86.287% (+0.4%) from 85.912%
#853

push

StellarBot
Merge #6109

6109: Modernize serialization module r=hkaiser a=hkaiser

- flyby separate serialization of Boost types

working towards https://github.com/STEllAR-GROUP/hpx/issues/5497

Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

53 of 53 new or added lines in 6 files covered. (100.0%)

173939 of 201582 relevant lines covered (86.29%)

1931657.12 hits per line

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

73.0
/libs/full/components_base/src/server/one_size_heap_list.cpp
1
//  Copyright (c) 1998-2021 Hartmut Kaiser
2
//  Copyright (c)      2011 Bryce Lelbach
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#include <hpx/config.hpp>
9
#include <hpx/assert.hpp>
10
#include <hpx/components_base/server/one_size_heap_list.hpp>
11
#include <hpx/components_base/server/wrapper_heap_base.hpp>
12
#include <hpx/functional/bind_front.hpp>
13
#include <hpx/modules/errors.hpp>
14
#include <hpx/modules/format.hpp>
15
#include <hpx/runtime_local/state.hpp>
16
#include <hpx/thread_support/unlock_guard.hpp>
17
#include <hpx/threading_base/register_thread.hpp>
18
#include <hpx/threading_base/thread_data.hpp>
19
#if defined(HPX_DEBUG)
20
#include <hpx/modules/logging.hpp>
21
#endif
22

23
#include <cstddef>
24
#include <list>
25
#include <memory>
26
#include <mutex>
27
#include <string>
28

29
namespace hpx { namespace util {
30

31
    one_size_heap_list::~one_size_heap_list() noexcept
2,702✔
32
    {
33
#if defined(HPX_DEBUG)
34
        LOSH_(info).format(
2,702✔
35
            "{1}::~{1}: size({2}), max_count({3}), alloc_count({4}), "
2,655✔
36
            "free_count({5})",
37
            name(), heap_count_, max_alloc_count_, alloc_count_, free_count_);
2,655✔
38

39
        if (alloc_count_ > free_count_)
2,702✔
40
        {
41
            LOSH_(warning).format(
590✔
42
                "{1}::~{1}: releasing with {2} allocated objects", name(),
576✔
43
                alloc_count_ - free_count_);
576✔
44
        }
590✔
45
#endif
46
    }
2,702✔
47

48
    void* one_size_heap_list::alloc(std::size_t count)
809,116✔
49
    {
50
        std::unique_lock guard(mtx_);
809,121✔
51

52
        if (HPX_UNLIKELY(0 == count))
809,121✔
53
        {
54
            guard.unlock();
×
55
            HPX_THROW_EXCEPTION(hpx::error::bad_parameter, name() + "::alloc",
×
56
                "cannot allocate 0 objects");
57
        }
58

59
        void* p = nullptr;
809,121✔
60
        {
61
            if (!heap_list_.empty())
809,121✔
62
            {
63
                for (auto& heap : heap_list_)
820,091✔
64
                {
65
                    bool allocated = false;
819,916✔
66

67
                    {
68
                        hpx::unlock_guard ul(guard);
819,916✔
69
                        allocated = heap->alloc(&p, count);
819,919✔
70
                    }
819,916✔
71

72
                    if (allocated)
819,919✔
73
                    {
74
#if defined(HPX_DEBUG)
75
                        // Allocation succeeded, update statistics.
76
                        alloc_count_ += count;
806,246✔
77
                        if (alloc_count_ - free_count_ > max_alloc_count_)
806,246✔
78
                            max_alloc_count_ = alloc_count_ - free_count_;
18,533✔
79
#endif
80
                        return p;
806,246✔
81
                    }
82

83
#if defined(HPX_DEBUG)
84
                    LOSH_(info).format(
27,346✔
85
                        "{1}::alloc: failed to allocate from heap[{2}] "
13,673✔
86
                        "(heap[{2}] has allocated {3} objects and has "
87
                        "space for {4} more objects)",
88
                        name(), heap->heap_count(), heap->size(),
13,673✔
89
                        heap->free_size());
13,673✔
90
#endif
91
                }
92
            }
172✔
93
        }
94

95
        // Create new heap.
96
        bool did_create = false;
2,875✔
97
        {
98
#if defined(HPX_DEBUG)
99
            heap_list_.push_front(create_heap_(
5,750✔
100
                class_name_.c_str(), heap_count_ + 1, parameters_));
2,875✔
101
#else
102
            heap_list_.push_front(
103
                create_heap_(class_name_.c_str(), 0, parameters_));
104
#endif
105

106
            iterator itnew = heap_list_.begin();
2,875✔
107
            typename list_type::value_type heap = *itnew;
2,875✔
108
            bool result = false;
2,875✔
109

110
            {
111
                hpx::unlock_guard ul(guard);
2,875✔
112
                result = heap->alloc((void**) &p, count);
2,875✔
113
            }
2,875✔
114

115
            if (HPX_UNLIKELY(!result || nullptr == p))
2,875✔
116
            {
117
                // out of memory
118
                guard.unlock();
×
119
                HPX_THROW_EXCEPTION(hpx::error::out_of_memory,
×
120
                    name() + "::alloc",
121
                    "new heap failed to allocate {1} objects", count);
122
            }
123

124
#if defined(HPX_DEBUG)
125
            alloc_count_ += count;
2,875✔
126
            ++heap_count_;
2,875✔
127

128
            LOSH_(info).format(
2,875✔
129
                "{1}::alloc: creating new heap[{2}], size is now {3}", name(),
2,828✔
130
                heap_count_, heap_list_.size());
2,828✔
131
#endif
132
            did_create = true;
2,875✔
133
        }
2,875✔
134

135
        if (did_create)
2,875✔
136
        {
137
            return p;
2,875✔
138
        }
139

140
        guard.unlock();
×
141

142
        // Try again, we just got a new heap, so we should be good.
143
        return alloc(count);
×
144
    }
809,121✔
145

146
    bool one_size_heap_list::reschedule(void* p, std::size_t count)
800,000✔
147
    {
148
        if (nullptr == threads::get_self_ptr())
800,001✔
149
        {
150
            hpx::threads::thread_init_data data(
×
151
                hpx::threads::make_thread_function_nullary(
×
152
                    hpx::bind_front(&one_size_heap_list::free, this, p, count)),
×
153
                "one_size_heap_list::free");
×
154
            hpx::threads::register_work(data);
×
155
            return true;
×
156
        }
×
157
        return false;
800,001✔
158
    }
800,001✔
159

160
    void one_size_heap_list::free(void* p, std::size_t count)
800,005✔
161
    {
162
        if (nullptr == p || !threads::threadmanager_is(hpx::state::running))
800,005✔
163
        {
164
            return;
×
165
        }
166

167
        // if this is called from outside a HPX thread we need to
168
        // re-schedule the request
169
        if (reschedule(p, count))
800,001✔
170
            return;
×
171

172
        std::unique_lock ul(mtx_);
800,008✔
173

174
        // Find the heap which allocated this pointer.
175
        for (auto& heap : heap_list_)
840,605✔
176
        {
177
            bool did_allocate = false;
840,611✔
178

179
            {
180
                hpx::unlock_guard ull(ul);
840,611✔
181
                did_allocate = heap->did_alloc(p);
840,612✔
182
                if (did_allocate)
840,611✔
183
                {
184
                    heap->free(p, count);
800,008✔
185
                }
800,008✔
186
            }
840,612✔
187

188
            if (did_allocate)
840,611✔
189
            {
190
#if defined(HPX_DEBUG)
191
                free_count_ += count;
800,006✔
192
#endif
193
                return;
194
            }
195
        }
196

197
        ul.unlock();
×
198

199
        HPX_THROW_EXCEPTION(hpx::error::bad_parameter, name() + "::free",
×
200
            "pointer {1} was not allocated by this {2}", p, name());
201
    }
800,007✔
202

203
    bool one_size_heap_list::did_alloc(void* p) const
×
204
    {
205
        std::unique_lock ul(mtx_);
×
206
        for (typename list_type::value_type const& heap : heap_list_)
×
207
        {
208
            hpx::unlock_guard ull(ul);
×
209
            if (heap->did_alloc(p))
×
210
            {
211
                return true;
×
212
            }
213
        }
×
214
        return false;
×
215
    }
×
216

217
    std::string one_size_heap_list::name() const
19,732✔
218
    {
219
        if (class_name_.empty())
19,732✔
220
        {
221
            return std::string("one_size_heap_list(unknown)");
×
222
        }
223
        return std::string("one_size_heap_list(") + class_name_ + ")";
19,732✔
224
    }
19,732✔
225
}}    // namespace hpx::util
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

© 2026 Coveralls, Inc