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

llnl / dftracer-utils / 28693295402

04 Jul 2026 03:17AM UTC coverage: 52.408% (+0.1%) from 52.278%
28693295402

push

github

hariharan-devarajan
feat: silence noisy warnings on aarch64

37318 of 92666 branches covered (40.27%)

Branch coverage included in aggregate %.

33462 of 42389 relevant lines covered (78.94%)

20557.64 hits per line

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

49.74
/src/dftracer/utils/core/tasks/task_result.cpp
1
#include <dftracer/utils/core/common/error.h>
2
#include <dftracer/utils/core/tasks/task_result.h>
3

4
#include <cassert>
5

6
namespace dftracer::utils {
7

8
void TaskResult::set_value(std::any value) {
1,533✔
9
    value_ = std::move(value);
1,533✔
10
    publish(State::value);
1,540✔
11
}
1,526✔
12

13
void TaskResult::set_exception(std::exception_ptr ex) {
34✔
14
    exception_ = ex;
34✔
15
    publish(State::exception);
34✔
16
}
34✔
17

18
void TaskResult::set_cancelled() { publish(State::cancelled); }
×
19

20
void TaskResult::mark_running() {
1,570✔
21
    auto expected = static_cast<std::uint8_t>(State::pending);
1,570✔
22
    state_.compare_exchange_strong(
1,570✔
23
        expected, static_cast<std::uint8_t>(State::running),
24
        std::memory_order_release, std::memory_order_relaxed);
25
}
1,570✔
26

27
void TaskResult::add_reader() {
1,134✔
28
    pending_readers_.fetch_add(1, std::memory_order_relaxed);
1,134✔
29
}
1,134✔
30

31
void TaskResult::release_reader() {
1,066✔
32
    int prev = pending_readers_.fetch_sub(1, std::memory_order_acq_rel);
1,066✔
33
    if (prev == 1) {
1,066✔
34
        // Last reader released -- free value memory
35
        std::lock_guard<std::mutex> lock(mutex_);
664!
36
        value_ = std::any{};
663✔
37
    }
664✔
38
}
1,065✔
39

40
void TaskResult::publish(State s) {
1,567✔
41
    std::vector<std::coroutine_handle<>> to_resume;
1,567✔
42
    {
43
        std::lock_guard<std::mutex> lock(mutex_);
1,560!
44
        state_.store(static_cast<std::uint8_t>(s), std::memory_order_release);
1,566✔
45
        to_resume.swap(continuations_);
1,562✔
46
    }
1,563✔
47
    cv_.notify_all();
1,564✔
48
    // Resume coroutine continuations OUTSIDE the lock.
49
    for (auto h : to_resume) {
1,573!
50
        if (h && !h.done()) {
×
51
            h.resume();
×
52
        }
53
    }
54
}
1,564✔
55

56
bool TaskResult::wait(std::chrono::milliseconds timeout) const {
868✔
57
    auto ready = [this] {
1,302✔
58
        auto s = static_cast<State>(state_.load(std::memory_order_acquire));
868✔
59
        return s == State::value || s == State::exception ||
868!
60
               s == State::cancelled;
434✔
61
    };
434✔
62
    if (ready()) return true;
868!
63

64
    std::unique_lock<std::mutex> lock(mutex_);
×
65
    if (timeout.count() == 0) {
×
66
        cv_.wait(lock, ready);
×
67
        return true;
×
68
    }
69
    return cv_.wait_for(lock, timeout, ready);
×
70
}
434✔
71

72
std::any TaskResult::get() const {
690✔
73
    wait();
690!
74
    std::lock_guard<std::mutex> lock(mutex_);
690!
75
    auto s = static_cast<State>(state_.load(std::memory_order_acquire));
690✔
76
    if (s == State::exception) {
690✔
77
        std::rethrow_exception(exception_);
9!
78
    }
79
    if (s == State::cancelled) {
684✔
80
        throw DFTUtilsException(ErrorCode::PIPELINE, "Task was cancelled");
×
81
    }
82
    return value_;  // returns COPY
1,026!
83
}
690✔
84

85
std::any TaskResult::get_ready() const {
1,064✔
86
    std::lock_guard<std::mutex> lock(mutex_);
1,064!
87
    auto s = static_cast<State>(state_.load(std::memory_order_acquire));
1,066✔
88
    assert(s == State::value || s == State::exception || s == State::cancelled);
1,066!
89
    if (s == State::exception) {
1,066✔
90
        std::rethrow_exception(exception_);
×
91
    }
92
    if (s == State::cancelled) {
1,066✔
93
        throw DFTUtilsException(ErrorCode::PIPELINE, "Task was cancelled");
×
94
    }
95
    return value_;  // returns COPY
1,599!
96
}
1,066✔
97

98
std::exception_ptr TaskResult::get_exception() const { return exception_; }
10✔
99

100
bool TaskResult::is_ready() const {
14✔
101
    auto s = static_cast<State>(state_.load(std::memory_order_acquire));
14✔
102
    return s == State::value || s == State::exception || s == State::cancelled;
14!
103
}
104

105
bool TaskResult::has_exception() const {
1,587✔
106
    return static_cast<State>(state_.load(std::memory_order_acquire)) ==
1,587✔
107
           State::exception;
793✔
108
}
109

110
bool TaskResult::is_cancelled() const {
×
111
    return static_cast<State>(state_.load(std::memory_order_acquire)) ==
×
112
           State::cancelled;
113
}
114

115
TaskResult::State TaskResult::state() const {
×
116
    return static_cast<State>(state_.load(std::memory_order_acquire));
×
117
}
118

119
// WhenReadyAwaitable
120
bool TaskResult::WhenReadyAwaitable::await_ready() const noexcept {
×
121
    return result.is_ready();
×
122
}
123

124
bool TaskResult::WhenReadyAwaitable::await_suspend(std::coroutine_handle<> h) {
×
125
    std::lock_guard<std::mutex> lock(result.mutex_);
×
126
    // Double-check under lock -- result may have been published
127
    // between await_ready() and await_suspend().
128
    if (result.is_ready()) {
×
129
        return false;  // Don't suspend, resume immediately
×
130
    }
131
    result.continuations_.push_back(h);
×
132
    return true;       // Suspend
×
133
}
×
134

135
void TaskResult::WhenReadyAwaitable::await_resume() {
×
136
    if (result.has_exception()) {
×
137
        std::rethrow_exception(result.exception_);
×
138
    }
139
}
×
140

141
}  // namespace dftracer::utils
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