• 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

82.14
/libs/core/threading_base/src/execution_agent.cpp
1
//  Copyright (c) 2019 Thomas Heller
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/coroutines/thread_enums.hpp>
10
#include <hpx/errors/throw_exception.hpp>
11
#include <hpx/lock_registration/detail/register_locks.hpp>
12
#include <hpx/modules/format.hpp>
13
#include <hpx/modules/logging.hpp>
14
#include <hpx/threading_base/thread_data.hpp>
15
#include <hpx/threading_base/thread_num_tss.hpp>
16

17
#include <hpx/threading_base/detail/reset_lco_description.hpp>
18
#include <hpx/threading_base/execution_agent.hpp>
19
#include <hpx/threading_base/scheduler_base.hpp>
20
#include <hpx/threading_base/set_thread_state.hpp>
21
#include <hpx/threading_base/thread_description.hpp>
22

23
#ifdef HPX_HAVE_THREAD_BACKTRACE_ON_SUSPENSION
24
#include <hpx/debugging/backtrace.hpp>
25
#include <hpx/threading_base/detail/reset_backtrace.hpp>
26
#endif
27

28
#include <cstddef>
29
#include <cstdint>
30
#include <memory>
31
#include <string>
32
#include <utility>
33

34
namespace hpx { namespace threads {
35

36
    execution_agent::execution_agent(
341,156✔
37
        coroutines::detail::coroutine_impl* coroutine) noexcept
38
      : self_(coroutine)
341,237✔
39
    {
682,312✔
40
    }
341,237✔
41

42
    std::string execution_agent::description() const
×
43
    {
44
        thread_id_type id = self_.get_thread_id();
×
45
        if (HPX_UNLIKELY(!id))
×
46
        {
47
            HPX_THROW_EXCEPTION(hpx::error::null_thread_id,
×
48
                "execution_agent::description",
49
                "null thread id encountered (is this executed on a "
50
                "HPX-thread?)");
51
        }
52

53
        return hpx::util::format(
×
54
            "{}: {}", id, get_thread_id_data(id)->get_description());
×
55
    }
×
56

57
    void execution_agent::yield(const char* desc)
78,112,118✔
58
    {
59
        do_yield(desc, hpx::threads::thread_schedule_state::pending);
78,117,834✔
60
    }
78,117,834✔
61

62
    void execution_agent::yield_k(std::size_t k, const char* desc)
4,933,291✔
63
    {
64
        if (k < 4)    //-V112
4,940,296✔
65
        {
66
        }
3,375,111✔
67
        else if (k < 16)
1,565,444✔
68
        {
69
            HPX_SMT_PAUSE;
1,208,626✔
70
        }
1,208,626✔
71
        else if (k < 32 || k & 1)    //-V112
356,851✔
72
        {
73
            do_yield(desc, hpx::threads::thread_schedule_state::pending_boost);
291,008✔
74
        }
291,008✔
75
        else
76
        {
77
            do_yield(desc, hpx::threads::thread_schedule_state::pending);
65,906✔
78
        }
79
    }
4,933,385✔
80

81
    void execution_agent::resume(const char* desc)
1,105,727✔
82
    {
83
        do_resume(desc, threads::thread_restart_state::signaled);
1,105,728✔
84
    }
1,105,728✔
85

86
    void execution_agent::abort(const char* desc)
×
87
    {
88
        do_resume(desc, threads::thread_restart_state::abort);
×
89
    }
×
90

91
    void execution_agent::suspend(const char* desc)
1,105,713✔
92
    {
93
        do_yield(desc, threads::thread_schedule_state::suspended);
1,105,714✔
94
    }
1,105,714✔
95

96
    void execution_agent::sleep_for(
×
97
        hpx::chrono::steady_duration const& sleep_duration, const char* desc)
98
    {
99
        sleep_until(sleep_duration.from_now(), desc);
×
100
    }
×
101

102
    void execution_agent::sleep_until(
62✔
103
        hpx::chrono::steady_time_point const& sleep_time, const char* desc)
104
    {
105
        // Just yield until time has passed by...
106
        auto now = std::chrono::steady_clock::now();
62✔
107

108
        // Note: we yield at least once to allow for other threads to
109
        // make progress in any case. We also use yield instead of yield_k
110
        // for the same reason.
111
        std::size_t k = 0;
62✔
112
        do
62✔
113
        {
114
            if (k < 32 || k & 1)
425,092✔
115
            {
116
                do_yield(
213,466✔
117
                    desc, hpx::threads::thread_schedule_state::pending_boost);
213,466✔
118
            }
213,466✔
119
            else
120
            {
121
                do_yield(desc, hpx::threads::thread_schedule_state::pending);
211,626✔
122
            }
123
            ++k;
425,092✔
124
            now = std::chrono::steady_clock::now();
425,092✔
125
        } while (now < sleep_time.value());
425,092✔
126
    }
62✔
127

128
#if defined(HPX_HAVE_VERIFY_LOCKS)
129
    struct on_exit_reset_held_lock_data
130
    {
131
        on_exit_reset_held_lock_data()
79,928,249✔
132
          : data_(hpx::util::get_held_locks_data())
79,932,122✔
133
        {
134
        }
79,932,122✔
135

136
        ~on_exit_reset_held_lock_data()
78,614,724✔
137
        {
138
            hpx::util::set_held_locks_data(HPX_MOVE(data_));
79,306,787✔
139
        }
79,306,787✔
140

141
        std::unique_ptr<hpx::util::held_locks_data> data_;
142
    };
143
#else
144
    struct on_exit_reset_held_lock_data
145
    {
146
    };
147
#endif
148

149
    hpx::threads::thread_restart_state execution_agent::do_yield(
80,003,390✔
150
        const char* desc, threads::thread_schedule_state state)
151
    {
152
        thread_id_ref_type id = self_.get_thread_id();    // keep alive
80,579,403✔
153
        if (HPX_UNLIKELY(!id))
80,579,403✔
154
        {
155
            HPX_THROW_EXCEPTION(hpx::error::null_thread_id,
×
156
                "execution_agent::do_yield",
157
                "null thread id encountered (is this executed on a "
158
                "HPX-thread?)");
159
        }
160

161
        // handle interruption, if needed
162
        thread_data* thrd_data = get_thread_id_data(id);
80,579,403✔
163
        HPX_ASSERT(thrd_data);
80,164,846✔
164
        thrd_data->interruption_point();
80,052,316✔
165

166
        thrd_data->set_last_worker_thread_num(
80,052,316✔
167
            hpx::get_local_worker_thread_num());
79,943,179✔
168

169
        threads::thread_restart_state statex =
79,951,200✔
170
            threads::thread_restart_state::unknown;
171

172
        {
173
#ifdef HPX_HAVE_THREAD_DESCRIPTION
174
            threads::detail::reset_lco_description desc(
175
                id.noref(), util::thread_description(desc));
176
#endif
177
#ifdef HPX_HAVE_THREAD_BACKTRACE_ON_SUSPENSION
178
            threads::detail::reset_backtrace bt(id);
179
#endif
180
            on_exit_reset_held_lock_data held_locks;
79,951,200✔
181
            HPX_UNUSED(held_locks);
79,825,567✔
182

183
            HPX_ASSERT(thrd_data->get_state().state() ==
79,951,200✔
184
                thread_schedule_state::active);
185
            HPX_ASSERT(state != thread_schedule_state::active);
79,807,416✔
186
            statex = self_.yield(
79,793,894✔
187
                threads::thread_result_type(state, threads::invalid_thread_id));
79,687,760✔
188
            HPX_ASSERT(get_thread_id_data(id)->get_state().state() ==
78,611,481✔
189
                thread_schedule_state::active);
190
        }
78,658,340✔
191

192
        // handle interruption, if needed
193
        thrd_data->interruption_point();
79,373,800✔
194

195
        // handle interrupt and abort
196
        if (statex == threads::thread_restart_state::abort)
79,377,921✔
197
        {
198
            HPX_THROW_EXCEPTION(hpx::error::yield_aborted, desc,
×
199
                "thread({}) aborted (yield returned wait_abort)",
200
                description());
201
        }
202

203
        return statex;
79,311,250✔
204
    }
79,377,921✔
205

206
    void execution_agent::do_resume(
1,105,730✔
207
        const char* /* desc */, hpx::threads::thread_restart_state statex)
208
    {
209
        threads::detail::set_thread_state(self_.get_thread_id(),
2,211,460✔
210
            thread_schedule_state::pending, statex, thread_priority::normal,
1,105,730✔
211
            thread_schedule_hint{}, false);
1,105,730✔
212
    }
1,105,730✔
213
}}    // namespace hpx::threads
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