• 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

80.95
/libs/core/threading_base/src/create_work.cpp
1
//  Copyright (c) 2007-2025 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/modules/coroutines.hpp>
10
#include <hpx/modules/errors.hpp>
11
#include <hpx/modules/logging.hpp>
12
#include <hpx/threading_base/create_work.hpp>
13
#include <hpx/threading_base/scheduler_base.hpp>
14
#include <hpx/threading_base/thread_data.hpp>
15
#include <hpx/threading_base/thread_init_data.hpp>
16

17
#include <cstddef>
18

19
namespace hpx::threads::detail {
42,999✔
20

21
    thread_id_ref_type create_work(policies::scheduler_base* scheduler,
22
        threads::thread_init_data& data, error_code& ec)
23
    {
42,999✔
24
        // verify parameters
25
        switch (data.initial_state)
26
        {
27
        // NOLINTNEXTLINE(bugprone-branch-clone)
28
        case thread_schedule_state::pending:
29
            [[fallthrough]];
30
        case thread_schedule_state::pending_do_not_schedule:
31
            [[fallthrough]];
32
        case thread_schedule_state::pending_boost:
33
            [[fallthrough]];
34
        case thread_schedule_state::suspended:
35
            break;
36

37
        default:
×
38
        {
39
            HPX_THROWS_IF(ec, hpx::error::bad_parameter,
40
                "thread::detail::create_work", "invalid initial state: {}",
41
                data.initial_state);
42
            return invalid_thread_id;
43
        }
44
        }
45

46
#ifdef HPX_HAVE_THREAD_DESCRIPTION
47
        if (!data.description)
48
        {
49
            HPX_THROWS_IF(ec, hpx::error::bad_parameter,
50
                "thread::detail::create_work", "description is nullptr");
51
            return invalid_thread_id;
52
        }
53
#endif
42,999✔
54

×
55
        LTM_(info)
56
            .format("create_work: pool({}), scheduler({}), initial_state({}), "
57
                    "thread_priority({})",
×
58
                *scheduler->get_parent_pool(), *scheduler,
×
59
                get_thread_state_name(data.initial_state),
60
                get_thread_priority_name(data.priority))
61
#ifdef HPX_HAVE_THREAD_DESCRIPTION
62
            .format(", description({})", data.description)
63
#endif
64
            ;
42,999✔
65

66
        thread_self const* self = get_self_ptr();
67

68
#ifdef HPX_HAVE_THREAD_PARENT_REFERENCE
69
        if (nullptr == data.parent_id)
70
        {
71
            if (self)
72
            {
73
                data.parent_id = get_thread_id_data(self->get_thread_id());
74
                data.parent_phase = self->get_thread_phase();
75
            }
76
        }
77
        if (0 == data.parent_locality_id)
78
            data.parent_locality_id = detail::get_locality_id(hpx::throws);
79
#endif
42,999✔
80

42,999✔
81
        if (nullptr == data.scheduler_base)
82
            data.scheduler_base = scheduler;
83

42,999✔
84
        // Pass critical priority from parent to child.
85
        if (self)
85,714✔
86
        {
87
            if (data.priority == thread_priority::default_ &&
85,580✔
88
                thread_priority::high_recursive ==
89
                    get_thread_id_data(self->get_thread_id())->get_priority())
134✔
90
            {
91
                data.priority = thread_priority::high_recursive;
92
            }
93
        }
94

42,999✔
95
        // create the new thread
96
        if (data.priority == thread_priority::default_)
42,856✔
97
        {
98
            data.priority = thread_priority::normal;
99
        }
100

42,999✔
101
        HPX_ASSERT(!data.run_now);
42,863✔
102
        data.run_now = (thread_priority::high == data.priority ||
85,858✔
103
            thread_priority::high_recursive == data.priority ||
104
            thread_priority::bound == data.priority ||
105
            thread_priority::boost == data.priority);
106

85,858✔
107
        thread_id_ref_type id = invalid_thread_id;
108
        scheduler->create_thread(data, data.run_now ? &id : nullptr, ec);
109

110
        scheduler->do_some_work(data.schedulehint.mode ==
42,999✔
111
                    hpx::threads::thread_schedule_hint_mode::numa ?
112
                static_cast<std::size_t>(-1) :
113
                data.schedulehint.hint);
114

115
        return id;
116
    }
117
}    // namespace hpx::threads::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