• 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

21.62
/libs/core/runtime_local/src/runtime_handlers.cpp
1
//  Copyright (c) 2007-2025 Hartmut Kaiser
2
//  Copyright (c)      2017 Shoshana Jakobovits
3
//  Copyright (c) 2010-2011 Phillip LeBlanc, Dylan Stark
4
//  Copyright (c)      2011 Bryce Lelbach
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/config.hpp>
11
#include <hpx/assert.hpp>
12
#include <hpx/modules/errors.hpp>
13
#include <hpx/modules/io_service.hpp>
14
#include <hpx/modules/logging.hpp>
15
#include <hpx/modules/threading_base.hpp>
16
#include <hpx/modules/threadmanager.hpp>
17
#include <hpx/runtime_local/custom_exception_info.hpp>
18
#include <hpx/runtime_local/debugging.hpp>
19
#include <hpx/runtime_local/runtime_handlers.hpp>
20
#include <hpx/runtime_local/runtime_local.hpp>
21
#if defined(HPX_HAVE_VERIFY_LOCKS)
22
#include <hpx/modules/debugging.hpp>
23
#include <hpx/runtime_local/config_entry.hpp>
24
#endif
25

26
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
27
#include <winsock2.h>
28
#endif
29
#include <asio/io_context.hpp>
30

31
#include <cstddef>
32
#include <iostream>
33
#include <sstream>
34
#include <string>
35

36
namespace hpx::detail {
×
37

38
    [[noreturn]] void assertion_handler(hpx::source_location const& loc,
39
        char const* expr, std::string const& msg)
40
    {
41
        thread_local bool handling_assertion = false;
×
42

43
        if (handling_assertion)
×
44
        {
45
            std::ostringstream strm;
46
            strm << "Trying to handle failed assertion while handling another "
47
                    "failed assertion!\n";
×
48
            strm << "Assertion '" << expr << "' failed";
×
49
            if (!msg.empty())
50
            {
×
51
                strm << " (" << msg << ")";
52
            }
53

54
            strm << "\n";
×
55
            strm << "{file}: " << loc.file_name() << "\n";
56
            strm << "{line}: " << loc.line() << "\n";
×
57
            strm << "{function}: " << loc.function_name() << "\n";
58

×
59
            std::cerr << strm.str() << std::flush;
60

×
61
            std::abort();
×
62
        }
63

×
64
        handling_assertion = true;
65

×
66
        hpx::util::may_attach_debugger("exception");
67

×
68
        std::ostringstream strm;
×
69
        strm << "Assertion '" << expr << "' failed";
×
70
        if (!msg.empty())
71
        {
×
72
            strm << " (" << msg << ")";
73
        }
74

×
75
        hpx::exception const e(hpx::error::assertion_failure, strm.str());
×
76
        std::cerr << hpx::diagnostic_information(hpx::detail::get_exception(
77
                         e, loc.function_name(), loc.file_name(), loc.line()))
78
                  << "\n"
×
79
                  << std::flush;
×
80
        std::abort();
81
    }
82

83
#if defined(HPX_HAVE_APEX)
84
    bool enable_parent_task_handler()
85
    {
86
        return !hpx::is_networking_enabled();
87
    }
88
#endif
×
89

90
    void test_failure_handler()
×
91
    {
×
92
        hpx::util::may_attach_debugger("test-failure");
93
    }
94

95
#if defined(HPX_HAVE_VERIFY_LOCKS)
96
    void registered_locks_error_handler()
97
    {
98
        std::string back_trace = hpx::util::trace(std::size_t(128));
99

100
        // throw or log, depending on config options
101
        if (get_config_entry("hpx.throw_on_held_lock", "1") == "0")
102
        {
103
            if (back_trace.empty())
104
            {
105
                LERR_(debug).format(
106
                    "suspending thread while at least one lock is being held "
107
                    "(stack backtrace was disabled at compile time)");
108
            }
109
            else
110
            {
111
                LERR_(debug).format("suspending thread while at least one lock "
112
                                    "is being held, stack backtrace: {}",
113
                    back_trace);
114
            }
115
        }
116
        else
117
        {
118
            if (back_trace.empty())
119
            {
120
                HPX_THROW_EXCEPTION(hpx::error::invalid_status,
121
                    "verify_no_locks",
122
                    "suspending thread while at least one lock is "
123
                    "being held (stack backtrace was disabled at "
124
                    "compile time)");
125
            }
126
            else
127
            {
128
                HPX_THROW_EXCEPTION(hpx::error::invalid_status,
129
                    "verify_no_locks",
130
                    "suspending thread while at least one lock is "
131
                    "being held, stack backtrace: {}",
132
                    back_trace);
133
            }
134
        }
135
    }
136

137
    bool register_locks_predicate()
138
    {
139
        return threads::get_self_ptr() != nullptr;
140
    }
141
#endif
308✔
142

143
    threads::thread_pool_base* get_default_pool()
308✔
144
    {
308✔
145
        hpx::runtime* rt = get_runtime_ptr();
146
        if (rt == nullptr)
×
147
        {
148
            HPX_THROW_EXCEPTION(hpx::error::invalid_status,
149
                "hpx::detail::get_default_pool",
150
                "The runtime system is not active");
151
        }
308✔
152
        return &rt->get_thread_manager().default_pool();
153
    }
154

141✔
155
    ::asio::io_context& get_default_timer_service()
156
    {
141✔
157
        hpx::runtime const* rt = get_runtime_ptr();
141✔
158
        if (rt == nullptr)
159
        {
×
160
            HPX_THROW_EXCEPTION(hpx::error::invalid_status,
161
                "hpx::detail::get_default_timer_service",
162
                "The runtime system is not active");
163
        }
164
        return get_thread_pool("timer-pool")->get_io_service();
141✔
165
    }
166

167
    threads::mask_type get_pu_mask(
×
168
        threads::topology& /* topo */, std::size_t thread_num)
169
    {
170
        auto const& rp = hpx::resource::get_partitioner();
×
171
        return rp.get_pu_mask(thread_num);
×
172
    }
173
}    // namespace hpx::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