Coverage Report

Created: 2026-04-29 19:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/tmp/bitcoin/src/checkqueue.h
Line
Count
Source
1
// Copyright (c) 2012-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_CHECKQUEUE_H
6
#define BITCOIN_CHECKQUEUE_H
7
8
#include <sync.h>
9
#include <tinyformat.h>
10
#include <util/log.h>
11
#include <util/threadnames.h>
12
13
#include <algorithm>
14
#include <iterator>
15
#include <optional>
16
#include <vector>
17
18
/**
19
 * Queue for verifications that have to be performed.
20
  * The verifications are represented by a type T, which must provide an
21
  * operator(), returning an std::optional<R>.
22
  *
23
  * The overall result of the computation is std::nullopt if all invocations
24
  * return std::nullopt, or one of the other results otherwise.
25
  *
26
  * One thread (the master) is assumed to push batches of verifications
27
  * onto the queue, where they are processed by N-1 worker threads. When
28
  * the master is done adding work, it temporarily joins the worker pool
29
  * as an N'th worker, until all jobs are done.
30
  *
31
  */
32
template <typename T, typename R = std::remove_cvref_t<decltype(std::declval<T>()().value())>>
33
class CCheckQueue
34
{
35
private:
36
    //! Mutex to protect the inner state
37
    Mutex m_mutex;
38
39
    //! Worker threads block on this when out of work
40
    std::condition_variable m_worker_cv;
41
42
    //! Master thread blocks on this when out of work
43
    std::condition_variable m_master_cv;
44
45
    //! The queue of elements to be processed.
46
    //! As the order of booleans doesn't matter, it is used as a LIFO (stack)
47
    std::vector<T> queue GUARDED_BY(m_mutex);
48
49
    //! The number of workers (including the master) that are idle.
50
    int nIdle GUARDED_BY(m_mutex){0};
51
52
    //! The total number of workers (including the master).
53
    int nTotal GUARDED_BY(m_mutex){0};
54
55
    //! The temporary evaluation result.
56
    std::optional<R> m_result GUARDED_BY(m_mutex);
57
58
    /**
59
     * Number of verifications that haven't completed yet.
60
     * This includes elements that are no longer queued, but still in the
61
     * worker's own batches.
62
     */
63
    unsigned int nTodo GUARDED_BY(m_mutex){0};
64
65
    //! The maximum number of elements to be processed in one batch
66
    const unsigned int nBatchSize;
67
68
    std::vector<std::thread> m_worker_threads;
69
    bool m_request_stop GUARDED_BY(m_mutex){false};
70
71
    /** Internal function that does bulk of the verification work. If fMaster, return the final result. */
72
    std::optional<R> Loop(bool fMaster) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
73
157k
    {
74
157k
        std::condition_variable& cond = fMaster ? m_master_cv : m_worker_cv;
75
157k
        std::vector<T> vChecks;
76
157k
        vChecks.reserve(nBatchSize);
77
157k
        unsigned int nNow = 0;
78
157k
        std::optional<R> local_result;
79
157k
        bool do_work;
80
6.46M
        do {
81
6.46M
            {
82
6.46M
                WAIT_LOCK(m_mutex, lock);
83
                // first do the clean-up of the previous loop run (allowing us to do it in the same critsect)
84
6.46M
                if (nNow) {
85
6.30M
                    if (local_result.has_value() && !m_result.has_value()) {
86
3.63k
                        std::swap(local_result, m_result);
87
3.63k
                    }
88
6.30M
                    nTodo -= nNow;
89
6.30M
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
1.16M
                        m_master_cv.notify_one();
92
1.16M
                    }
93
6.30M
                } else {
94
                    // first iteration
95
157k
                    nTotal++;
96
157k
                }
97
                // logically, the do loop starts here
98
9.94M
                while (queue.empty() && !m_request_stop) {
99
3.63M
                    if (fMaster && nTodo == 0) {
100
156k
                        nTotal--;
101
156k
                        std::optional<R> to_return = std::move(m_result);
102
                        // reset the status for new work later
103
156k
                        m_result = std::nullopt;
104
                        // return the current status
105
156k
                        return to_return;
106
156k
                    }
107
3.48M
                    nIdle++;
108
3.48M
                    cond.wait(lock); // wait
109
3.48M
                    nIdle--;
110
3.48M
                }
111
6.30M
                if (m_request_stop) {
112
                    // return value does not matter, because m_request_stop is only set in the destructor.
113
1.39k
                    return std::nullopt;
114
1.39k
                }
115
116
                // Decide how many work units to process now.
117
                // * Do not try to do everything at once, but aim for increasingly smaller batches so
118
                //   all workers finish approximately simultaneously.
119
                // * Try to account for idle jobs which will instantly start helping.
120
                // * Don't do batches smaller than 1 (duh), or larger than nBatchSize.
121
6.30M
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
6.30M
                auto start_it = queue.end() - nNow;
123
6.30M
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
6.30M
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
6.30M
                do_work = !m_result.has_value();
127
6.30M
            }
128
            // execute work
129
6.30M
            if (do_work) {
130
11.6M
                for (T& check : vChecks) {
131
11.6M
                    local_result = check();
132
11.6M
                    if (local_result.has_value()) break;
133
11.6M
                }
134
6.29M
            }
135
6.30M
            vChecks.clear();
136
6.30M
        } while (true);
137
157k
    }
CCheckQueue<FakeCheck, int>::Loop(bool)
Line
Count
Source
73
7
    {
74
7
        std::condition_variable& cond = fMaster ? m_master_cv : m_worker_cv;
75
7
        std::vector<T> vChecks;
76
7
        vChecks.reserve(nBatchSize);
77
7
        unsigned int nNow = 0;
78
7
        std::optional<R> local_result;
79
7
        bool do_work;
80
7
        do {
81
7
            {
82
7
                WAIT_LOCK(m_mutex, lock);
83
                // first do the clean-up of the previous loop run (allowing us to do it in the same critsect)
84
7
                if (nNow) {
85
0
                    if (local_result.has_value() && !m_result.has_value()) {
86
0
                        std::swap(local_result, m_result);
87
0
                    }
88
0
                    nTodo -= nNow;
89
0
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
0
                        m_master_cv.notify_one();
92
0
                    }
93
7
                } else {
94
                    // first iteration
95
7
                    nTotal++;
96
7
                }
97
                // logically, the do loop starts here
98
10
                while (queue.empty() && !m_request_stop) {
99
7
                    if (fMaster && nTodo == 0) {
100
4
                        nTotal--;
101
4
                        std::optional<R> to_return = std::move(m_result);
102
                        // reset the status for new work later
103
4
                        m_result = std::nullopt;
104
                        // return the current status
105
4
                        return to_return;
106
4
                    }
107
3
                    nIdle++;
108
3
                    cond.wait(lock); // wait
109
3
                    nIdle--;
110
3
                }
111
3
                if (m_request_stop) {
112
                    // return value does not matter, because m_request_stop is only set in the destructor.
113
3
                    return std::nullopt;
114
3
                }
115
116
                // Decide how many work units to process now.
117
                // * Do not try to do everything at once, but aim for increasingly smaller batches so
118
                //   all workers finish approximately simultaneously.
119
                // * Try to account for idle jobs which will instantly start helping.
120
                // * Don't do batches smaller than 1 (duh), or larger than nBatchSize.
121
0
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
0
                auto start_it = queue.end() - nNow;
123
0
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
0
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
0
                do_work = !m_result.has_value();
127
0
            }
128
            // execute work
129
0
            if (do_work) {
130
0
                for (T& check : vChecks) {
131
0
                    local_result = check();
132
0
                    if (local_result.has_value()) break;
133
0
                }
134
0
            }
135
0
            vChecks.clear();
136
0
        } while (true);
137
7
    }
CCheckQueue<FakeCheckCheckCompletion, int>::Loop(bool)
Line
Count
Source
73
221
    {
74
221
        std::condition_variable& cond = fMaster ? m_master_cv : m_worker_cv;
75
221
        std::vector<T> vChecks;
76
221
        vChecks.reserve(nBatchSize);
77
221
        unsigned int nNow = 0;
78
221
        std::optional<R> local_result;
79
221
        bool do_work;
80
5.37M
        do {
81
5.37M
            {
82
5.37M
                WAIT_LOCK(m_mutex, lock);
83
                // first do the clean-up of the previous loop run (allowing us to do it in the same critsect)
84
5.37M
                if (nNow) {
85
5.37M
                    if (local_result.has_value() && !m_result.has_value()) {
86
0
                        std::swap(local_result, m_result);
87
0
                    }
88
5.37M
                    nTodo -= nNow;
89
5.37M
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
965k
                        m_master_cv.notify_one();
92
965k
                    }
93
18.4E
                } else {
94
                    // first iteration
95
18.4E
                    nTotal++;
96
18.4E
                }
97
                // logically, the do loop starts here
98
8.29M
                while (queue.empty() && !m_request_stop) {
99
2.92M
                    if (fMaster && nTodo == 0) {
100
209
                        nTotal--;
101
209
                        std::optional<R> to_return = std::move(m_result);
102
                        // reset the status for new work later
103
209
                        m_result = std::nullopt;
104
                        // return the current status
105
209
                        return to_return;
106
209
                    }
107
2.92M
                    nIdle++;
108
2.92M
                    cond.wait(lock); // wait
109
2.92M
                    nIdle--;
110
2.92M
                }
111
5.36M
                if (m_request_stop) {
112
                    // return value does not matter, because m_request_stop is only set in the destructor.
113
12
                    return std::nullopt;
114
12
                }
115
116
                // Decide how many work units to process now.
117
                // * Do not try to do everything at once, but aim for increasingly smaller batches so
118
                //   all workers finish approximately simultaneously.
119
                // * Try to account for idle jobs which will instantly start helping.
120
                // * Don't do batches smaller than 1 (duh), or larger than nBatchSize.
121
5.36M
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
5.36M
                auto start_it = queue.end() - nNow;
123
5.36M
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
5.36M
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
5.36M
                do_work = !m_result.has_value();
127
5.36M
            }
128
            // execute work
129
5.36M
            if (do_work) {
130
10.5M
                for (T& check : vChecks) {
131
10.5M
                    local_result = check();
132
10.5M
                    if (local_result.has_value()) break;
133
10.5M
                }
134
5.36M
            }
135
5.36M
            vChecks.clear();
136
5.36M
        } while (true);
137
221
    }
CCheckQueue<FixedCheck, int>::Loop(bool)
Line
Count
Source
73
1.02k
    {
74
1.02k
        std::condition_variable& cond = fMaster ? m_master_cv : m_worker_cv;
75
1.02k
        std::vector<T> vChecks;
76
1.02k
        vChecks.reserve(nBatchSize);
77
1.02k
        unsigned int nNow = 0;
78
1.02k
        std::optional<R> local_result;
79
1.02k
        bool do_work;
80
419k
        do {
81
419k
            {
82
419k
                WAIT_LOCK(m_mutex, lock);
83
                // first do the clean-up of the previous loop run (allowing us to do it in the same critsect)
84
419k
                if (nNow) {
85
418k
                    if (local_result.has_value() && !m_result.has_value()) {
86
1.01k
                        std::swap(local_result, m_result);
87
1.01k
                    }
88
418k
                    nTodo -= nNow;
89
418k
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
81.8k
                        m_master_cv.notify_one();
92
81.8k
                    }
93
418k
                } else {
94
                    // first iteration
95
1.01k
                    nTotal++;
96
1.01k
                }
97
                // logically, the do loop starts here
98
661k
                while (queue.empty() && !m_request_stop) {
99
243k
                    if (fMaster && nTodo == 0) {
100
1.02k
                        nTotal--;
101
1.02k
                        std::optional<R> to_return = std::move(m_result);
102
                        // reset the status for new work later
103
1.02k
                        m_result = std::nullopt;
104
                        // return the current status
105
1.02k
                        return to_return;
106
1.02k
                    }
107
242k
                    nIdle++;
108
242k
                    cond.wait(lock); // wait
109
242k
                    nIdle--;
110
242k
                }
111
418k
                if (m_request_stop) {
112
                    // return value does not matter, because m_request_stop is only set in the destructor.
113
6
                    return std::nullopt;
114
6
                }
115
116
                // Decide how many work units to process now.
117
                // * Do not try to do everything at once, but aim for increasingly smaller batches so
118
                //   all workers finish approximately simultaneously.
119
                // * Try to account for idle jobs which will instantly start helping.
120
                // * Don't do batches smaller than 1 (duh), or larger than nBatchSize.
121
418k
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
418k
                auto start_it = queue.end() - nNow;
123
418k
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
418k
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
418k
                do_work = !m_result.has_value();
127
418k
            }
128
            // execute work
129
418k
            if (do_work) {
130
431k
                for (T& check : vChecks) {
131
431k
                    local_result = check();
132
431k
                    if (local_result.has_value()) break;
133
431k
                }
134
409k
            }
135
418k
            vChecks.clear();
136
418k
        } while (true);
137
1.02k
    }
CCheckQueue<UniqueCheck, int>::Loop(bool)
Line
Count
Source
73
4
    {
74
4
        std::condition_variable& cond = fMaster ? m_master_cv : m_worker_cv;
75
4
        std::vector<T> vChecks;
76
4
        vChecks.reserve(nBatchSize);
77
4
        unsigned int nNow = 0;
78
4
        std::optional<R> local_result;
79
4
        bool do_work;
80
809
        do {
81
809
            {
82
809
                WAIT_LOCK(m_mutex, lock);
83
                // first do the clean-up of the previous loop run (allowing us to do it in the same critsect)
84
809
                if (nNow) {
85
805
                    if (local_result.has_value() && !m_result.has_value()) {
86
0
                        std::swap(local_result, m_result);
87
0
                    }
88
805
                    nTodo -= nNow;
89
805
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
1
                        m_master_cv.notify_one();
92
1
                    }
93
805
                } else {
94
                    // first iteration
95
4
                    nTotal++;
96
4
                }
97
                // logically, the do loop starts here
98
813
                while (queue.empty() && !m_request_stop) {
99
5
                    if (fMaster && nTodo == 0) {
100
1
                        nTotal--;
101
1
                        std::optional<R> to_return = std::move(m_result);
102
                        // reset the status for new work later
103
1
                        m_result = std::nullopt;
104
                        // return the current status
105
1
                        return to_return;
106
1
                    }
107
4
                    nIdle++;
108
4
                    cond.wait(lock); // wait
109
4
                    nIdle--;
110
4
                }
111
808
                if (m_request_stop) {
112
                    // return value does not matter, because m_request_stop is only set in the destructor.
113
3
                    return std::nullopt;
114
3
                }
115
116
                // Decide how many work units to process now.
117
                // * Do not try to do everything at once, but aim for increasingly smaller batches so
118
                //   all workers finish approximately simultaneously.
119
                // * Try to account for idle jobs which will instantly start helping.
120
                // * Don't do batches smaller than 1 (duh), or larger than nBatchSize.
121
805
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
805
                auto start_it = queue.end() - nNow;
123
805
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
805
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
805
                do_work = !m_result.has_value();
127
805
            }
128
            // execute work
129
805
            if (do_work) {
130
99.9k
                for (T& check : vChecks) {
131
99.9k
                    local_result = check();
132
99.9k
                    if (local_result.has_value()) break;
133
99.9k
                }
134
805
            }
135
805
            vChecks.clear();
136
805
        } while (true);
137
4
    }
CCheckQueue<MemoryCheck, int>::Loop(bool)
Line
Count
Source
73
1.00k
    {
74
1.00k
        std::condition_variable& cond = fMaster ? m_master_cv : m_worker_cv;
75
1.00k
        std::vector<T> vChecks;
76
1.00k
        vChecks.reserve(nBatchSize);
77
1.00k
        unsigned int nNow = 0;
78
1.00k
        std::optional<R> local_result;
79
1.00k
        bool do_work;
80
486k
        do {
81
486k
            {
82
486k
                WAIT_LOCK(m_mutex, lock);
83
                // first do the clean-up of the previous loop run (allowing us to do it in the same critsect)
84
486k
                if (nNow) {
85
485k
                    if (local_result.has_value() && !m_result.has_value()) {
86
0
                        std::swap(local_result, m_result);
87
0
                    }
88
485k
                    nTodo -= nNow;
89
485k
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
96.9k
                        m_master_cv.notify_one();
92
96.9k
                    }
93
485k
                } else {
94
                    // first iteration
95
993
                    nTotal++;
96
993
                }
97
                // logically, the do loop starts here
98
773k
                while (queue.empty() && !m_request_stop) {
99
287k
                    if (fMaster && nTodo == 0) {
100
1.00k
                        nTotal--;
101
1.00k
                        std::optional<R> to_return = std::move(m_result);
102
                        // reset the status for new work later
103
1.00k
                        m_result = std::nullopt;
104
                        // return the current status
105
1.00k
                        return to_return;
106
1.00k
                    }
107
286k
                    nIdle++;
108
286k
                    cond.wait(lock); // wait
109
286k
                    nIdle--;
110
286k
                }
111
485k
                if (m_request_stop) {
112
                    // return value does not matter, because m_request_stop is only set in the destructor.
113
3
                    return std::nullopt;
114
3
                }
115
116
                // Decide how many work units to process now.
117
                // * Do not try to do everything at once, but aim for increasingly smaller batches so
118
                //   all workers finish approximately simultaneously.
119
                // * Try to account for idle jobs which will instantly start helping.
120
                // * Don't do batches smaller than 1 (duh), or larger than nBatchSize.
121
485k
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
485k
                auto start_it = queue.end() - nNow;
123
485k
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
485k
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
485k
                do_work = !m_result.has_value();
127
485k
            }
128
            // execute work
129
485k
            if (do_work) {
130
499k
                for (T& check : vChecks) {
131
499k
                    local_result = check();
132
499k
                    if (local_result.has_value()) break;
133
499k
                }
134
485k
            }
135
485k
            vChecks.clear();
136
485k
        } while (true);
137
1.00k
    }
CCheckQueue<FrozenCleanupCheck, int>::Loop(bool)
Line
Count
Source
73
4
    {
74
4
        std::condition_variable& cond = fMaster ? m_master_cv : m_worker_cv;
75
4
        std::vector<T> vChecks;
76
4
        vChecks.reserve(nBatchSize);
77
4
        unsigned int nNow = 0;
78
4
        std::optional<R> local_result;
79
4
        bool do_work;
80
5
        do {
81
5
            {
82
5
                WAIT_LOCK(m_mutex, lock);
83
                // first do the clean-up of the previous loop run (allowing us to do it in the same critsect)
84
5
                if (nNow) {
85
1
                    if (local_result.has_value() && !m_result.has_value()) {
86
0
                        std::swap(local_result, m_result);
87
0
                    }
88
1
                    nTodo -= nNow;
89
1
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
1
                        m_master_cv.notify_one();
92
1
                    }
93
4
                } else {
94
                    // first iteration
95
4
                    nTotal++;
96
4
                }
97
                // logically, the do loop starts here
98
9
                while (queue.empty() && !m_request_stop) {
99
5
                    if (fMaster && nTodo == 0) {
100
1
                        nTotal--;
101
1
                        std::optional<R> to_return = std::move(m_result);
102
                        // reset the status for new work later
103
1
                        m_result = std::nullopt;
104
                        // return the current status
105
1
                        return to_return;
106
1
                    }
107
4
                    nIdle++;
108
4
                    cond.wait(lock); // wait
109
4
                    nIdle--;
110
4
                }
111
4
                if (m_request_stop) {
112
                    // return value does not matter, because m_request_stop is only set in the destructor.
113
3
                    return std::nullopt;
114
3
                }
115
116
                // Decide how many work units to process now.
117
                // * Do not try to do everything at once, but aim for increasingly smaller batches so
118
                //   all workers finish approximately simultaneously.
119
                // * Try to account for idle jobs which will instantly start helping.
120
                // * Don't do batches smaller than 1 (duh), or larger than nBatchSize.
121
1
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
1
                auto start_it = queue.end() - nNow;
123
1
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
1
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
1
                do_work = !m_result.has_value();
127
1
            }
128
            // execute work
129
1
            if (do_work) {
130
1
                for (T& check : vChecks) {
131
1
                    local_result = check();
132
1
                    if (local_result.has_value()) break;
133
1
                }
134
1
            }
135
1
            vChecks.clear();
136
1
        } while (true);
137
4
    }
CCheckQueue<CScriptCheck, std::pair<ScriptError_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>::Loop(bool)
Line
Count
Source
73
155k
    {
74
155k
        std::condition_variable& cond = fMaster ? m_master_cv : m_worker_cv;
75
155k
        std::vector<T> vChecks;
76
155k
        vChecks.reserve(nBatchSize);
77
155k
        unsigned int nNow = 0;
78
155k
        std::optional<R> local_result;
79
155k
        bool do_work;
80
184k
        do {
81
184k
            {
82
184k
                WAIT_LOCK(m_mutex, lock);
83
                // first do the clean-up of the previous loop run (allowing us to do it in the same critsect)
84
184k
                if (nNow) {
85
29.2k
                    if (local_result.has_value() && !m_result.has_value()) {
86
2.62k
                        std::swap(local_result, m_result);
87
2.62k
                    }
88
29.2k
                    nTodo -= nNow;
89
29.2k
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
18.9k
                        m_master_cv.notify_one();
92
18.9k
                    }
93
155k
                } else {
94
                    // first iteration
95
155k
                    nTotal++;
96
155k
                }
97
                // logically, the do loop starts here
98
209k
                while (queue.empty() && !m_request_stop) {
99
179k
                    if (fMaster && nTodo == 0) {
100
153k
                        nTotal--;
101
153k
                        std::optional<R> to_return = std::move(m_result);
102
                        // reset the status for new work later
103
153k
                        m_result = std::nullopt;
104
                        // return the current status
105
153k
                        return to_return;
106
153k
                    }
107
25.3k
                    nIdle++;
108
25.3k
                    cond.wait(lock); // wait
109
25.3k
                    nIdle--;
110
25.3k
                }
111
30.5k
                if (m_request_stop) {
112
                    // return value does not matter, because m_request_stop is only set in the destructor.
113
1.36k
                    return std::nullopt;
114
1.36k
                }
115
116
                // Decide how many work units to process now.
117
                // * Do not try to do everything at once, but aim for increasingly smaller batches so
118
                //   all workers finish approximately simultaneously.
119
                // * Try to account for idle jobs which will instantly start helping.
120
                // * Don't do batches smaller than 1 (duh), or larger than nBatchSize.
121
29.2k
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
29.2k
                auto start_it = queue.end() - nNow;
123
29.2k
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
29.2k
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
29.2k
                do_work = !m_result.has_value();
127
29.2k
            }
128
            // execute work
129
29.2k
            if (do_work) {
130
48.2k
                for (T& check : vChecks) {
131
48.2k
                    local_result = check();
132
48.2k
                    if (local_result.has_value()) break;
133
48.2k
                }
134
28.2k
            }
135
29.2k
            vChecks.clear();
136
29.2k
        } while (true);
137
155k
    }
138
139
public:
140
    //! Mutex to ensure only one concurrent CCheckQueueControl
141
    Mutex m_control_mutex;
142
143
    //! Create a new check queue
144
    explicit CCheckQueue(unsigned int batch_size, int worker_threads_num)
145
1.20k
        : nBatchSize(batch_size)
146
1.20k
    {
147
1.20k
        LogInfo("Script verification uses %d additional threads", worker_threads_num);
148
1.20k
        m_worker_threads.reserve(worker_threads_num);
149
2.60k
        for (int n = 0; n < worker_threads_num; ++n) {
150
1.39k
            m_worker_threads.emplace_back([this, n]() {
151
1.39k
                util::ThreadRename(strprintf("scriptch.%i", n));
152
1.39k
                Loop(false /* worker thread */);
153
1.39k
            });
CCheckQueue<FakeCheckCheckCompletion, int>::CCheckQueue(unsigned int, int)::'lambda'()::operator()() const
Line
Count
Source
150
12
            m_worker_threads.emplace_back([this, n]() {
151
12
                util::ThreadRename(strprintf("scriptch.%i", n));
152
12
                Loop(false /* worker thread */);
153
12
            });
CCheckQueue<FixedCheck, int>::CCheckQueue(unsigned int, int)::'lambda'()::operator()() const
Line
Count
Source
150
6
            m_worker_threads.emplace_back([this, n]() {
151
6
                util::ThreadRename(strprintf("scriptch.%i", n));
152
6
                Loop(false /* worker thread */);
153
6
            });
CCheckQueue<UniqueCheck, int>::CCheckQueue(unsigned int, int)::'lambda'()::operator()() const
Line
Count
Source
150
3
            m_worker_threads.emplace_back([this, n]() {
151
3
                util::ThreadRename(strprintf("scriptch.%i", n));
152
3
                Loop(false /* worker thread */);
153
3
            });
CCheckQueue<MemoryCheck, int>::CCheckQueue(unsigned int, int)::'lambda'()::operator()() const
Line
Count
Source
150
3
            m_worker_threads.emplace_back([this, n]() {
151
3
                util::ThreadRename(strprintf("scriptch.%i", n));
152
3
                Loop(false /* worker thread */);
153
3
            });
CCheckQueue<FrozenCleanupCheck, int>::CCheckQueue(unsigned int, int)::'lambda'()::operator()() const
Line
Count
Source
150
3
            m_worker_threads.emplace_back([this, n]() {
151
3
                util::ThreadRename(strprintf("scriptch.%i", n));
152
3
                Loop(false /* worker thread */);
153
3
            });
CCheckQueue<FakeCheck, int>::CCheckQueue(unsigned int, int)::'lambda'()::operator()() const
Line
Count
Source
150
3
            m_worker_threads.emplace_back([this, n]() {
151
3
                util::ThreadRename(strprintf("scriptch.%i", n));
152
3
                Loop(false /* worker thread */);
153
3
            });
CCheckQueue<CScriptCheck, std::pair<ScriptError_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>::CCheckQueue(unsigned int, int)::'lambda'()::operator()() const
Line
Count
Source
150
1.36k
            m_worker_threads.emplace_back([this, n]() {
151
1.36k
                util::ThreadRename(strprintf("scriptch.%i", n));
152
1.36k
                Loop(false /* worker thread */);
153
1.36k
            });
154
1.39k
        }
155
1.20k
    }
CCheckQueue<FakeCheckCheckCompletion, int>::CCheckQueue(unsigned int, int)
Line
Count
Source
145
4
        : nBatchSize(batch_size)
146
4
    {
147
4
        LogInfo("Script verification uses %d additional threads", worker_threads_num);
148
4
        m_worker_threads.reserve(worker_threads_num);
149
16
        for (int n = 0; n < worker_threads_num; ++n) {
150
12
            m_worker_threads.emplace_back([this, n]() {
151
12
                util::ThreadRename(strprintf("scriptch.%i", n));
152
12
                Loop(false /* worker thread */);
153
12
            });
154
12
        }
155
4
    }
CCheckQueue<FixedCheck, int>::CCheckQueue(unsigned int, int)
Line
Count
Source
145
2
        : nBatchSize(batch_size)
146
2
    {
147
2
        LogInfo("Script verification uses %d additional threads", worker_threads_num);
148
2
        m_worker_threads.reserve(worker_threads_num);
149
8
        for (int n = 0; n < worker_threads_num; ++n) {
150
6
            m_worker_threads.emplace_back([this, n]() {
151
6
                util::ThreadRename(strprintf("scriptch.%i", n));
152
6
                Loop(false /* worker thread */);
153
6
            });
154
6
        }
155
2
    }
CCheckQueue<UniqueCheck, int>::CCheckQueue(unsigned int, int)
Line
Count
Source
145
1
        : nBatchSize(batch_size)
146
1
    {
147
1
        LogInfo("Script verification uses %d additional threads", worker_threads_num);
148
1
        m_worker_threads.reserve(worker_threads_num);
149
4
        for (int n = 0; n < worker_threads_num; ++n) {
150
3
            m_worker_threads.emplace_back([this, n]() {
151
3
                util::ThreadRename(strprintf("scriptch.%i", n));
152
3
                Loop(false /* worker thread */);
153
3
            });
154
3
        }
155
1
    }
CCheckQueue<MemoryCheck, int>::CCheckQueue(unsigned int, int)
Line
Count
Source
145
1
        : nBatchSize(batch_size)
146
1
    {
147
1
        LogInfo("Script verification uses %d additional threads", worker_threads_num);
148
1
        m_worker_threads.reserve(worker_threads_num);
149
4
        for (int n = 0; n < worker_threads_num; ++n) {
150
3
            m_worker_threads.emplace_back([this, n]() {
151
3
                util::ThreadRename(strprintf("scriptch.%i", n));
152
3
                Loop(false /* worker thread */);
153
3
            });
154
3
        }
155
1
    }
CCheckQueue<FrozenCleanupCheck, int>::CCheckQueue(unsigned int, int)
Line
Count
Source
145
1
        : nBatchSize(batch_size)
146
1
    {
147
1
        LogInfo("Script verification uses %d additional threads", worker_threads_num);
148
1
        m_worker_threads.reserve(worker_threads_num);
149
4
        for (int n = 0; n < worker_threads_num; ++n) {
150
3
            m_worker_threads.emplace_back([this, n]() {
151
3
                util::ThreadRename(strprintf("scriptch.%i", n));
152
3
                Loop(false /* worker thread */);
153
3
            });
154
3
        }
155
1
    }
CCheckQueue<FakeCheck, int>::CCheckQueue(unsigned int, int)
Line
Count
Source
145
1
        : nBatchSize(batch_size)
146
1
    {
147
1
        LogInfo("Script verification uses %d additional threads", worker_threads_num);
148
1
        m_worker_threads.reserve(worker_threads_num);
149
4
        for (int n = 0; n < worker_threads_num; ++n) {
150
3
            m_worker_threads.emplace_back([this, n]() {
151
3
                util::ThreadRename(strprintf("scriptch.%i", n));
152
3
                Loop(false /* worker thread */);
153
3
            });
154
3
        }
155
1
    }
CCheckQueue<CScriptCheck, std::pair<ScriptError_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>::CCheckQueue(unsigned int, int)
Line
Count
Source
145
1.19k
        : nBatchSize(batch_size)
146
1.19k
    {
147
1.19k
        LogInfo("Script verification uses %d additional threads", worker_threads_num);
148
1.19k
        m_worker_threads.reserve(worker_threads_num);
149
2.56k
        for (int n = 0; n < worker_threads_num; ++n) {
150
1.36k
            m_worker_threads.emplace_back([this, n]() {
151
1.36k
                util::ThreadRename(strprintf("scriptch.%i", n));
152
1.36k
                Loop(false /* worker thread */);
153
1.36k
            });
154
1.36k
        }
155
1.19k
    }
156
157
    // Since this class manages its own resources, which is a thread
158
    // pool `m_worker_threads`, copy and move operations are not appropriate.
159
    CCheckQueue(const CCheckQueue&) = delete;
160
    CCheckQueue& operator=(const CCheckQueue&) = delete;
161
    CCheckQueue(CCheckQueue&&) = delete;
162
    CCheckQueue& operator=(CCheckQueue&&) = delete;
163
164
    //! Join the execution until completion. If at least one evaluation wasn't successful, return
165
    //! its error.
166
    std::optional<R> Complete() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
167
156k
    {
168
156k
        return Loop(true /* master thread */);
169
156k
    }
CCheckQueue<FakeCheck, int>::Complete()
Line
Count
Source
167
4
    {
168
4
        return Loop(true /* master thread */);
169
4
    }
CCheckQueue<FakeCheckCheckCompletion, int>::Complete()
Line
Count
Source
167
209
    {
168
209
        return Loop(true /* master thread */);
169
209
    }
CCheckQueue<FixedCheck, int>::Complete()
Line
Count
Source
167
1.02k
    {
168
1.02k
        return Loop(true /* master thread */);
169
1.02k
    }
CCheckQueue<UniqueCheck, int>::Complete()
Line
Count
Source
167
1
    {
168
1
        return Loop(true /* master thread */);
169
1
    }
CCheckQueue<MemoryCheck, int>::Complete()
Line
Count
Source
167
1.00k
    {
168
1.00k
        return Loop(true /* master thread */);
169
1.00k
    }
CCheckQueue<FrozenCleanupCheck, int>::Complete()
Line
Count
Source
167
1
    {
168
1
        return Loop(true /* master thread */);
169
1
    }
CCheckQueue<CScriptCheck, std::pair<ScriptError_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>::Complete()
Line
Count
Source
167
153k
    {
168
153k
        return Loop(true /* master thread */);
169
153k
    }
170
171
    //! Add a batch of checks to the queue
172
    void Add(std::vector<T>&& vChecks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
173
2.65M
    {
174
2.65M
        if (vChecks.empty()) {
175
290k
            return;
176
290k
        }
177
178
2.36M
        {
179
2.36M
            LOCK(m_mutex);
180
2.36M
            queue.insert(queue.end(), std::make_move_iterator(vChecks.begin()), std::make_move_iterator(vChecks.end()));
181
2.36M
            nTodo += vChecks.size();
182
2.36M
        }
183
184
2.36M
        if (vChecks.size() == 1) {
185
284k
            m_worker_cv.notify_one();
186
2.08M
        } else {
187
2.08M
            m_worker_cv.notify_all();
188
2.08M
        }
189
2.36M
    }
CCheckQueue<FakeCheckCheckCompletion, int>::Add(std::vector<FakeCheckCheckCompletion, std::allocator<FakeCheckCheckCompletion>>&&)
Line
Count
Source
173
2.34M
    {
174
2.34M
        if (vChecks.empty()) {
175
234k
            return;
176
234k
        }
177
178
2.11M
        {
179
2.11M
            LOCK(m_mutex);
180
2.11M
            queue.insert(queue.end(), std::make_move_iterator(vChecks.begin()), std::make_move_iterator(vChecks.end()));
181
2.11M
            nTodo += vChecks.size();
182
2.11M
        }
183
184
2.11M
        if (vChecks.size() == 1) {
185
235k
            m_worker_cv.notify_one();
186
1.87M
        } else {
187
1.87M
            m_worker_cv.notify_all();
188
1.87M
        }
189
2.11M
    }
CCheckQueue<FixedCheck, int>::Add(std::vector<FixedCheck, std::allocator<FixedCheck>>&&)
Line
Count
Source
173
111k
    {
174
111k
        if (vChecks.empty()) {
175
11.0k
            return;
176
11.0k
        }
177
178
100k
        {
179
100k
            LOCK(m_mutex);
180
100k
            queue.insert(queue.end(), std::make_move_iterator(vChecks.begin()), std::make_move_iterator(vChecks.end()));
181
100k
            nTodo += vChecks.size();
182
100k
        }
183
184
100k
        if (vChecks.size() == 1) {
185
11.5k
            m_worker_cv.notify_one();
186
89.2k
        } else {
187
89.2k
            m_worker_cv.notify_all();
188
89.2k
        }
189
100k
    }
CCheckQueue<UniqueCheck, int>::Add(std::vector<UniqueCheck, std::allocator<UniqueCheck>>&&)
Line
Count
Source
173
22.2k
    {
174
22.2k
        if (vChecks.empty()) {
175
2.11k
            return;
176
2.11k
        }
177
178
20.0k
        {
179
20.0k
            LOCK(m_mutex);
180
20.0k
            queue.insert(queue.end(), std::make_move_iterator(vChecks.begin()), std::make_move_iterator(vChecks.end()));
181
20.0k
            nTodo += vChecks.size();
182
20.0k
        }
183
184
20.0k
        if (vChecks.size() == 1) {
185
2.32k
            m_worker_cv.notify_one();
186
17.7k
        } else {
187
17.7k
            m_worker_cv.notify_all();
188
17.7k
        }
189
20.0k
    }
CCheckQueue<MemoryCheck, int>::Add(std::vector<MemoryCheck, std::allocator<MemoryCheck>>&&)
Line
Count
Source
173
111k
    {
174
111k
        if (vChecks.empty()) {
175
10.9k
            return;
176
10.9k
        }
177
178
100k
        {
179
100k
            LOCK(m_mutex);
180
100k
            queue.insert(queue.end(), std::make_move_iterator(vChecks.begin()), std::make_move_iterator(vChecks.end()));
181
100k
            nTodo += vChecks.size();
182
100k
        }
183
184
100k
        if (vChecks.size() == 1) {
185
11.4k
            m_worker_cv.notify_one();
186
89.0k
        } else {
187
89.0k
            m_worker_cv.notify_all();
188
89.0k
        }
189
100k
    }
CCheckQueue<FrozenCleanupCheck, int>::Add(std::vector<FrozenCleanupCheck, std::allocator<FrozenCleanupCheck>>&&)
Line
Count
Source
173
1
    {
174
1
        if (vChecks.empty()) {
175
0
            return;
176
0
        }
177
178
1
        {
179
1
            LOCK(m_mutex);
180
1
            queue.insert(queue.end(), std::make_move_iterator(vChecks.begin()), std::make_move_iterator(vChecks.end()));
181
1
            nTodo += vChecks.size();
182
1
        }
183
184
1
        if (vChecks.size() == 1) {
185
1
            m_worker_cv.notify_one();
186
1
        } else {
187
0
            m_worker_cv.notify_all();
188
0
        }
189
1
    }
CCheckQueue<CScriptCheck, std::pair<ScriptError_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>::Add(std::vector<CScriptCheck, std::allocator<CScriptCheck>>&&)
Line
Count
Source
173
66.0k
    {
174
66.0k
        if (vChecks.empty()) {
175
32.6k
            return;
176
32.6k
        }
177
178
33.3k
        {
179
33.3k
            LOCK(m_mutex);
180
33.3k
            queue.insert(queue.end(), std::make_move_iterator(vChecks.begin()), std::make_move_iterator(vChecks.end()));
181
33.3k
            nTodo += vChecks.size();
182
33.3k
        }
183
184
33.3k
        if (vChecks.size() == 1) {
185
22.6k
            m_worker_cv.notify_one();
186
22.6k
        } else {
187
10.6k
            m_worker_cv.notify_all();
188
10.6k
        }
189
33.3k
    }
190
191
    ~CCheckQueue()
192
1.20k
    {
193
1.20k
        WITH_LOCK(m_mutex, m_request_stop = true);
194
1.20k
        m_worker_cv.notify_all();
195
1.39k
        for (std::thread& t : m_worker_threads) {
196
1.39k
            t.join();
197
1.39k
        }
198
1.20k
    }
CCheckQueue<FakeCheckCheckCompletion, int>::~CCheckQueue()
Line
Count
Source
192
4
    {
193
4
        WITH_LOCK(m_mutex, m_request_stop = true);
194
4
        m_worker_cv.notify_all();
195
12
        for (std::thread& t : m_worker_threads) {
196
12
            t.join();
197
12
        }
198
4
    }
CCheckQueue<FixedCheck, int>::~CCheckQueue()
Line
Count
Source
192
2
    {
193
2
        WITH_LOCK(m_mutex, m_request_stop = true);
194
2
        m_worker_cv.notify_all();
195
6
        for (std::thread& t : m_worker_threads) {
196
6
            t.join();
197
6
        }
198
2
    }
CCheckQueue<UniqueCheck, int>::~CCheckQueue()
Line
Count
Source
192
1
    {
193
1
        WITH_LOCK(m_mutex, m_request_stop = true);
194
1
        m_worker_cv.notify_all();
195
3
        for (std::thread& t : m_worker_threads) {
196
3
            t.join();
197
3
        }
198
1
    }
CCheckQueue<MemoryCheck, int>::~CCheckQueue()
Line
Count
Source
192
1
    {
193
1
        WITH_LOCK(m_mutex, m_request_stop = true);
194
1
        m_worker_cv.notify_all();
195
3
        for (std::thread& t : m_worker_threads) {
196
3
            t.join();
197
3
        }
198
1
    }
CCheckQueue<FrozenCleanupCheck, int>::~CCheckQueue()
Line
Count
Source
192
1
    {
193
1
        WITH_LOCK(m_mutex, m_request_stop = true);
194
1
        m_worker_cv.notify_all();
195
3
        for (std::thread& t : m_worker_threads) {
196
3
            t.join();
197
3
        }
198
1
    }
CCheckQueue<FakeCheck, int>::~CCheckQueue()
Line
Count
Source
192
1
    {
193
1
        WITH_LOCK(m_mutex, m_request_stop = true);
194
1
        m_worker_cv.notify_all();
195
3
        for (std::thread& t : m_worker_threads) {
196
3
            t.join();
197
3
        }
198
1
    }
CCheckQueue<CScriptCheck, std::pair<ScriptError_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>::~CCheckQueue()
Line
Count
Source
192
1.19k
    {
193
1.19k
        WITH_LOCK(m_mutex, m_request_stop = true);
194
1.19k
        m_worker_cv.notify_all();
195
1.36k
        for (std::thread& t : m_worker_threads) {
196
1.36k
            t.join();
197
1.36k
        }
198
1.19k
    }
199
200
154k
    bool HasThreads() const { return !m_worker_threads.empty(); }
201
};
202
203
/**
204
 * RAII-style controller object for a CCheckQueue that guarantees the passed
205
 * queue is finished before continuing.
206
 */
207
template <typename T, typename R = std::remove_cvref_t<decltype(std::declval<T>()().value())>>
208
class SCOPED_LOCKABLE CCheckQueueControl
209
{
210
private:
211
    CCheckQueue<T, R>& m_queue;
212
    UniqueLock<Mutex> m_lock;
213
    bool fDone;
214
215
public:
216
    CCheckQueueControl() = delete;
217
    CCheckQueueControl(const CCheckQueueControl&) = delete;
218
    CCheckQueueControl& operator=(const CCheckQueueControl&) = delete;
219
156k
    explicit CCheckQueueControl(CCheckQueue<T>& queueIn) EXCLUSIVE_LOCK_FUNCTION(queueIn.m_control_mutex) : m_queue(queueIn), m_lock(LOCK_ARGS(queueIn.m_control_mutex)), fDone(false) {}
CCheckQueueControl<FakeCheck, int>::CCheckQueueControl(CCheckQueue<FakeCheck, int>&)
Line
Count
Source
219
4
    explicit CCheckQueueControl(CCheckQueue<T>& queueIn) EXCLUSIVE_LOCK_FUNCTION(queueIn.m_control_mutex) : m_queue(queueIn), m_lock(LOCK_ARGS(queueIn.m_control_mutex)), fDone(false) {}
CCheckQueueControl<FakeCheckCheckCompletion, int>::CCheckQueueControl(CCheckQueue<FakeCheckCheckCompletion, int>&)
Line
Count
Source
219
209
    explicit CCheckQueueControl(CCheckQueue<T>& queueIn) EXCLUSIVE_LOCK_FUNCTION(queueIn.m_control_mutex) : m_queue(queueIn), m_lock(LOCK_ARGS(queueIn.m_control_mutex)), fDone(false) {}
CCheckQueueControl<FixedCheck, int>::CCheckQueueControl(CCheckQueue<FixedCheck, int>&)
Line
Count
Source
219
1.02k
    explicit CCheckQueueControl(CCheckQueue<T>& queueIn) EXCLUSIVE_LOCK_FUNCTION(queueIn.m_control_mutex) : m_queue(queueIn), m_lock(LOCK_ARGS(queueIn.m_control_mutex)), fDone(false) {}
CCheckQueueControl<UniqueCheck, int>::CCheckQueueControl(CCheckQueue<UniqueCheck, int>&)
Line
Count
Source
219
1
    explicit CCheckQueueControl(CCheckQueue<T>& queueIn) EXCLUSIVE_LOCK_FUNCTION(queueIn.m_control_mutex) : m_queue(queueIn), m_lock(LOCK_ARGS(queueIn.m_control_mutex)), fDone(false) {}
CCheckQueueControl<MemoryCheck, int>::CCheckQueueControl(CCheckQueue<MemoryCheck, int>&)
Line
Count
Source
219
1.00k
    explicit CCheckQueueControl(CCheckQueue<T>& queueIn) EXCLUSIVE_LOCK_FUNCTION(queueIn.m_control_mutex) : m_queue(queueIn), m_lock(LOCK_ARGS(queueIn.m_control_mutex)), fDone(false) {}
CCheckQueueControl<FrozenCleanupCheck, int>::CCheckQueueControl(CCheckQueue<FrozenCleanupCheck, int>&)
Line
Count
Source
219
1
    explicit CCheckQueueControl(CCheckQueue<T>& queueIn) EXCLUSIVE_LOCK_FUNCTION(queueIn.m_control_mutex) : m_queue(queueIn), m_lock(LOCK_ARGS(queueIn.m_control_mutex)), fDone(false) {}
CCheckQueueControl<CScriptCheck, std::pair<ScriptError_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>::CCheckQueueControl(CCheckQueue<CScriptCheck, std::pair<ScriptError_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&)
Line
Count
Source
219
153k
    explicit CCheckQueueControl(CCheckQueue<T>& queueIn) EXCLUSIVE_LOCK_FUNCTION(queueIn.m_control_mutex) : m_queue(queueIn), m_lock(LOCK_ARGS(queueIn.m_control_mutex)), fDone(false) {}
220
221
    std::optional<R> Complete()
222
156k
    {
223
156k
        auto ret = m_queue.Complete();
224
156k
        fDone = true;
225
156k
        return ret;
226
156k
    }
CCheckQueueControl<FakeCheck, int>::Complete()
Line
Count
Source
222
4
    {
223
4
        auto ret = m_queue.Complete();
224
4
        fDone = true;
225
4
        return ret;
226
4
    }
CCheckQueueControl<FakeCheckCheckCompletion, int>::Complete()
Line
Count
Source
222
209
    {
223
209
        auto ret = m_queue.Complete();
224
209
        fDone = true;
225
209
        return ret;
226
209
    }
CCheckQueueControl<FixedCheck, int>::Complete()
Line
Count
Source
222
1.02k
    {
223
1.02k
        auto ret = m_queue.Complete();
224
1.02k
        fDone = true;
225
1.02k
        return ret;
226
1.02k
    }
CCheckQueueControl<UniqueCheck, int>::Complete()
Line
Count
Source
222
1
    {
223
1
        auto ret = m_queue.Complete();
224
1
        fDone = true;
225
1
        return ret;
226
1
    }
CCheckQueueControl<MemoryCheck, int>::Complete()
Line
Count
Source
222
1.00k
    {
223
1.00k
        auto ret = m_queue.Complete();
224
1.00k
        fDone = true;
225
1.00k
        return ret;
226
1.00k
    }
CCheckQueueControl<FrozenCleanupCheck, int>::Complete()
Line
Count
Source
222
1
    {
223
1
        auto ret = m_queue.Complete();
224
1
        fDone = true;
225
1
        return ret;
226
1
    }
CCheckQueueControl<CScriptCheck, std::pair<ScriptError_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>::Complete()
Line
Count
Source
222
153k
    {
223
153k
        auto ret = m_queue.Complete();
224
153k
        fDone = true;
225
153k
        return ret;
226
153k
    }
227
228
    void Add(std::vector<T>&& vChecks)
229
2.65M
    {
230
2.65M
        m_queue.Add(std::move(vChecks));
231
2.65M
    }
CCheckQueueControl<FakeCheckCheckCompletion, int>::Add(std::vector<FakeCheckCheckCompletion, std::allocator<FakeCheckCheckCompletion>>&&)
Line
Count
Source
229
2.34M
    {
230
2.34M
        m_queue.Add(std::move(vChecks));
231
2.34M
    }
CCheckQueueControl<FixedCheck, int>::Add(std::vector<FixedCheck, std::allocator<FixedCheck>>&&)
Line
Count
Source
229
111k
    {
230
111k
        m_queue.Add(std::move(vChecks));
231
111k
    }
CCheckQueueControl<UniqueCheck, int>::Add(std::vector<UniqueCheck, std::allocator<UniqueCheck>>&&)
Line
Count
Source
229
22.2k
    {
230
22.2k
        m_queue.Add(std::move(vChecks));
231
22.2k
    }
CCheckQueueControl<MemoryCheck, int>::Add(std::vector<MemoryCheck, std::allocator<MemoryCheck>>&&)
Line
Count
Source
229
111k
    {
230
111k
        m_queue.Add(std::move(vChecks));
231
111k
    }
CCheckQueueControl<FrozenCleanupCheck, int>::Add(std::vector<FrozenCleanupCheck, std::allocator<FrozenCleanupCheck>>&&)
Line
Count
Source
229
1
    {
230
1
        m_queue.Add(std::move(vChecks));
231
1
    }
CCheckQueueControl<CScriptCheck, std::pair<ScriptError_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>::Add(std::vector<CScriptCheck, std::allocator<CScriptCheck>>&&)
Line
Count
Source
229
66.0k
    {
230
66.0k
        m_queue.Add(std::move(vChecks));
231
66.0k
    }
232
233
    ~CCheckQueueControl() UNLOCK_FUNCTION()
234
156k
    {
235
156k
        if (!fDone)
236
1.00k
            Complete();
237
156k
    }
CCheckQueueControl<FakeCheck, int>::~CCheckQueueControl()
Line
Count
Source
234
4
    {
235
4
        if (!fDone)
236
4
            Complete();
237
4
    }
CCheckQueueControl<FakeCheckCheckCompletion, int>::~CCheckQueueControl()
Line
Count
Source
234
209
    {
235
209
        if (!fDone)
236
0
            Complete();
237
209
    }
CCheckQueueControl<FixedCheck, int>::~CCheckQueueControl()
Line
Count
Source
234
1.02k
    {
235
1.02k
        if (!fDone)
236
0
            Complete();
237
1.02k
    }
CCheckQueueControl<UniqueCheck, int>::~CCheckQueueControl()
Line
Count
Source
234
1
    {
235
1
        if (!fDone)
236
1
            Complete();
237
1
    }
CCheckQueueControl<MemoryCheck, int>::~CCheckQueueControl()
Line
Count
Source
234
1.00k
    {
235
1.00k
        if (!fDone)
236
1.00k
            Complete();
237
1.00k
    }
CCheckQueueControl<FrozenCleanupCheck, int>::~CCheckQueueControl()
Line
Count
Source
234
1
    {
235
1
        if (!fDone)
236
0
            Complete();
237
1
    }
CCheckQueueControl<CScriptCheck, std::pair<ScriptError_t, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>::~CCheckQueueControl()
Line
Count
Source
234
153k
    {
235
153k
        if (!fDone)
236
0
            Complete();
237
153k
    }
238
};
239
240
#endif // BITCOIN_CHECKQUEUE_H