Coverage Report

Created: 2026-05-08 10:34

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
156k
    {
74
156k
        std::condition_variable& cond = fMaster ? m_master_cv : m_worker_cv;
75
156k
        std::vector<T> vChecks;
76
156k
        vChecks.reserve(nBatchSize);
77
156k
        unsigned int nNow = 0;
78
156k
        std::optional<R> local_result;
79
156k
        bool do_work;
80
6.47M
        do {
81
6.47M
            {
82
6.47M
                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.47M
                if (nNow) {
85
6.31M
                    if (local_result.has_value() && !m_result.has_value()) {
86
3.63k
                        std::swap(local_result, m_result);
87
3.63k
                    }
88
6.31M
                    nTodo -= nNow;
89
6.31M
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
1.13M
                        m_master_cv.notify_one();
92
1.13M
                    }
93
6.31M
                } else {
94
                    // first iteration
95
156k
                    nTotal++;
96
156k
                }
97
                // logically, the do loop starts here
98
9.87M
                while (queue.empty() && !m_request_stop) {
99
3.55M
                    if (fMaster && nTodo == 0) {
100
155k
                        nTotal--;
101
155k
                        std::optional<R> to_return = std::move(m_result);
102
                        // reset the status for new work later
103
155k
                        m_result = std::nullopt;
104
                        // return the current status
105
155k
                        return to_return;
106
155k
                    }
107
3.39M
                    nIdle++;
108
3.39M
                    cond.wait(lock); // wait
109
3.39M
                    nIdle--;
110
3.39M
                }
111
6.31M
                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.31M
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
6.31M
                auto start_it = queue.end() - nNow;
123
6.31M
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
6.31M
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
6.31M
                do_work = !m_result.has_value();
127
6.31M
            }
128
            // execute work
129
6.31M
            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.30M
            }
135
6.31M
            vChecks.clear();
136
6.31M
        } while (true);
137
156k
    }
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
225
    {
74
225
        std::condition_variable& cond = fMaster ? m_master_cv : m_worker_cv;
75
225
        std::vector<T> vChecks;
76
225
        vChecks.reserve(nBatchSize);
77
225
        unsigned int nNow = 0;
78
225
        std::optional<R> local_result;
79
225
        bool do_work;
80
5.42M
        do {
81
5.42M
            {
82
5.42M
                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.42M
                if (nNow) {
85
5.42M
                    if (local_result.has_value() && !m_result.has_value()) {
86
0
                        std::swap(local_result, m_result);
87
0
                    }
88
5.42M
                    nTodo -= nNow;
89
5.42M
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
946k
                        m_master_cv.notify_one();
92
946k
                    }
93
18.4E
                } else {
94
                    // first iteration
95
18.4E
                    nTotal++;
96
18.4E
                }
97
                // logically, the do loop starts here
98
8.30M
                while (queue.empty() && !m_request_stop) {
99
2.87M
                    if (fMaster && nTodo == 0) {
100
213
                        nTotal--;
101
213
                        std::optional<R> to_return = std::move(m_result);
102
                        // reset the status for new work later
103
213
                        m_result = std::nullopt;
104
                        // return the current status
105
213
                        return to_return;
106
213
                    }
107
2.87M
                    nIdle++;
108
2.87M
                    cond.wait(lock); // wait
109
2.87M
                    nIdle--;
110
2.87M
                }
111
5.42M
                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.42M
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
5.42M
                auto start_it = queue.end() - nNow;
123
5.42M
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
5.42M
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
5.42M
                do_work = !m_result.has_value();
127
5.42M
            }
128
            // execute work
129
5.42M
            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.42M
            }
135
5.42M
            vChecks.clear();
136
5.42M
        } while (true);
137
225
    }
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
398k
        do {
81
398k
            {
82
398k
                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
398k
                if (nNow) {
85
397k
                    if (local_result.has_value() && !m_result.has_value()) {
86
1.01k
                        std::swap(local_result, m_result);
87
1.01k
                    }
88
397k
                    nTodo -= nNow;
89
397k
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
77.6k
                        m_master_cv.notify_one();
92
77.6k
                    }
93
397k
                } else {
94
                    // first iteration
95
1.02k
                    nTotal++;
96
1.02k
                }
97
                // logically, the do loop starts here
98
627k
                while (queue.empty() && !m_request_stop) {
99
230k
                    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
229k
                    nIdle++;
108
229k
                    cond.wait(lock); // wait
109
229k
                    nIdle--;
110
229k
                }
111
397k
                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
397k
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
397k
                auto start_it = queue.end() - nNow;
123
397k
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
397k
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
397k
                do_work = !m_result.has_value();
127
397k
            }
128
            // execute work
129
397k
            if (do_work) {
130
417k
                for (T& check : vChecks) {
131
417k
                    local_result = check();
132
417k
                    if (local_result.has_value()) break;
133
417k
                }
134
388k
            }
135
397k
            vChecks.clear();
136
397k
        } while (true);
137
1.02k
    }
CCheckQueue<UniqueCheck, int>::Loop(bool)
Line
Count
Source
73
3
    {
74
3
        std::condition_variable& cond = fMaster ? m_master_cv : m_worker_cv;
75
3
        std::vector<T> vChecks;
76
3
        vChecks.reserve(nBatchSize);
77
3
        unsigned int nNow = 0;
78
3
        std::optional<R> local_result;
79
3
        bool do_work;
80
808
        do {
81
808
            {
82
808
                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
808
                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
3
                    nTotal++;
96
3
                }
97
                // logically, the do loop starts here
98
812
                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
807
                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
804
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
804
                auto start_it = queue.end() - nNow;
123
804
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
804
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
804
                do_work = !m_result.has_value();
127
804
            }
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
804
            vChecks.clear();
136
804
        } while (true);
137
3
    }
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
461k
        do {
81
461k
            {
82
461k
                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
461k
                if (nNow) {
85
460k
                    if (local_result.has_value() && !m_result.has_value()) {
86
0
                        std::swap(local_result, m_result);
87
0
                    }
88
460k
                    nTodo -= nNow;
89
460k
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
89.0k
                        m_master_cv.notify_one();
92
89.0k
                    }
93
460k
                } else {
94
                    // first iteration
95
984
                    nTotal++;
96
984
                }
97
                // logically, the do loop starts here
98
724k
                while (queue.empty() && !m_request_stop) {
99
263k
                    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
262k
                    nIdle++;
108
262k
                    cond.wait(lock); // wait
109
262k
                    nIdle--;
110
262k
                }
111
460k
                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
460k
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
460k
                auto start_it = queue.end() - nNow;
123
460k
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
460k
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
460k
                do_work = !m_result.has_value();
127
460k
            }
128
            // execute work
129
460k
            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
460k
            }
135
460k
            vChecks.clear();
136
460k
        } 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
154k
    {
74
154k
        std::condition_variable& cond = fMaster ? m_master_cv : m_worker_cv;
75
154k
        std::vector<T> vChecks;
76
154k
        vChecks.reserve(nBatchSize);
77
154k
        unsigned int nNow = 0;
78
154k
        std::optional<R> local_result;
79
154k
        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
30.2k
                    if (local_result.has_value() && !m_result.has_value()) {
86
2.62k
                        std::swap(local_result, m_result);
87
2.62k
                    }
88
30.2k
                    nTodo -= nNow;
89
30.2k
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
21.6k
                        m_master_cv.notify_one();
92
21.6k
                    }
93
154k
                } else {
94
                    // first iteration
95
154k
                    nTotal++;
96
154k
                }
97
                // logically, the do loop starts here
98
211k
                while (queue.empty() && !m_request_stop) {
99
180k
                    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
26.9k
                    nIdle++;
108
26.9k
                    cond.wait(lock); // wait
109
26.9k
                    nIdle--;
110
26.9k
                }
111
31.6k
                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
30.2k
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
30.2k
                auto start_it = queue.end() - nNow;
123
30.2k
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
30.2k
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
30.2k
                do_work = !m_result.has_value();
127
30.2k
            }
128
            // execute work
129
30.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
29.2k
            }
135
30.2k
            vChecks.clear();
136
30.2k
        } while (true);
137
154k
    }
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
2
            m_worker_threads.emplace_back([this, n]() {
151
2
                util::ThreadRename(strprintf("scriptch.%i", n));
152
2
                Loop(false /* worker thread */);
153
2
            });
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
155k
    {
168
155k
        return Loop(true /* master thread */);
169
155k
    }
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
213
    {
168
213
        return Loop(true /* master thread */);
169
213
    }
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.66M
    {
174
2.66M
        if (vChecks.empty()) {
175
292k
            return;
176
292k
        }
177
178
2.37M
        {
179
2.37M
            LOCK(m_mutex);
180
2.37M
            queue.insert(queue.end(), std::make_move_iterator(vChecks.begin()), std::make_move_iterator(vChecks.end()));
181
2.37M
            nTodo += vChecks.size();
182
2.37M
        }
183
184
2.37M
        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.37M
    }
CCheckQueue<FakeCheckCheckCompletion, int>::Add(std::vector<FakeCheckCheckCompletion, std::allocator<FakeCheckCheckCompletion>>&&)
Line
Count
Source
173
2.35M
    {
174
2.35M
        if (vChecks.empty()) {
175
235k
            return;
176
235k
        }
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
236k
            m_worker_cv.notify_one();
186
1.88M
        } else {
187
1.88M
            m_worker_cv.notify_all();
188
1.88M
        }
189
2.11M
    }
CCheckQueue<FixedCheck, int>::Add(std::vector<FixedCheck, std::allocator<FixedCheck>>&&)
Line
Count
Source
173
112k
    {
174
112k
        if (vChecks.empty()) {
175
11.3k
            return;
176
11.3k
        }
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.22k
            return;
176
2.22k
        }
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.22k
            m_worker_cv.notify_one();
186
17.8k
        } else {
187
17.8k
            m_worker_cv.notify_all();
188
17.8k
        }
189
20.0k
    }
CCheckQueue<MemoryCheck, int>::Add(std::vector<MemoryCheck, std::allocator<MemoryCheck>>&&)
Line
Count
Source
173
111k
    {
174
111k
        if (vChecks.empty()) {
175
11.2k
            return;
176
11.2k
        }
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
65.0k
    {
174
65.0k
        if (vChecks.empty()) {
175
31.7k
            return;
176
31.7k
        }
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
155k
    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
213
    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
155k
    {
223
155k
        auto ret = m_queue.Complete();
224
155k
        fDone = true;
225
155k
        return ret;
226
155k
    }
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
213
    {
223
213
        auto ret = m_queue.Complete();
224
213
        fDone = true;
225
213
        return ret;
226
213
    }
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.66M
    {
230
2.66M
        m_queue.Add(std::move(vChecks));
231
2.66M
    }
CCheckQueueControl<FakeCheckCheckCompletion, int>::Add(std::vector<FakeCheckCheckCompletion, std::allocator<FakeCheckCheckCompletion>>&&)
Line
Count
Source
229
2.35M
    {
230
2.35M
        m_queue.Add(std::move(vChecks));
231
2.35M
    }
CCheckQueueControl<FixedCheck, int>::Add(std::vector<FixedCheck, std::allocator<FixedCheck>>&&)
Line
Count
Source
229
112k
    {
230
112k
        m_queue.Add(std::move(vChecks));
231
112k
    }
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
65.0k
    {
230
65.0k
        m_queue.Add(std::move(vChecks));
231
65.0k
    }
232
233
    ~CCheckQueueControl() UNLOCK_FUNCTION()
234
155k
    {
235
155k
        if (!fDone)
236
1.00k
            Complete();
237
155k
    }
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
213
    {
235
213
        if (!fDone)
236
0
            Complete();
237
213
    }
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