Coverage Report

Created: 2026-05-06 07:53

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.76M
        do {
81
6.76M
            {
82
6.76M
                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.76M
                if (nNow) {
85
6.60M
                    if (local_result.has_value() && !m_result.has_value()) {
86
3.63k
                        std::swap(local_result, m_result);
87
3.63k
                    }
88
6.60M
                    nTodo -= nNow;
89
6.60M
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
1.20M
                        m_master_cv.notify_one();
92
1.20M
                    }
93
6.60M
                } else {
94
                    // first iteration
95
156k
                    nTotal++;
96
156k
                }
97
                // logically, the do loop starts here
98
10.3M
                while (queue.empty() && !m_request_stop) {
99
3.76M
                    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.60M
                    nIdle++;
108
3.60M
                    cond.wait(lock); // wait
109
3.60M
                    nIdle--;
110
3.60M
                }
111
6.60M
                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.60M
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
6.60M
                auto start_it = queue.end() - nNow;
123
6.60M
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
6.60M
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
6.60M
                do_work = !m_result.has_value();
127
6.60M
            }
128
            // execute work
129
6.60M
            if (do_work) {
130
11.8M
                for (T& check : vChecks) {
131
11.8M
                    local_result = check();
132
11.8M
                    if (local_result.has_value()) break;
133
11.8M
                }
134
6.59M
            }
135
6.60M
            vChecks.clear();
136
6.60M
        } 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
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.73M
        do {
81
5.73M
            {
82
5.73M
                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.73M
                if (nNow) {
85
5.73M
                    if (local_result.has_value() && !m_result.has_value()) {
86
0
                        std::swap(local_result, m_result);
87
0
                    }
88
5.73M
                    nTodo -= nNow;
89
5.73M
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
1.01M
                        m_master_cv.notify_one();
92
1.01M
                    }
93
5.73M
                } else {
94
                    // first iteration
95
14
                    nTotal++;
96
14
                }
97
                // logically, the do loop starts here
98
8.82M
                while (queue.empty() && !m_request_stop) {
99
3.09M
                    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
3.09M
                    nIdle++;
108
3.09M
                    cond.wait(lock); // wait
109
3.09M
                    nIdle--;
110
3.09M
                }
111
5.73M
                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.73M
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
5.73M
                auto start_it = queue.end() - nNow;
123
5.73M
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
5.73M
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
5.73M
                do_work = !m_result.has_value();
127
5.73M
            }
128
            // execute work
129
5.73M
            if (do_work) {
130
10.7M
                for (T& check : vChecks) {
131
10.7M
                    local_result = check();
132
10.7M
                    if (local_result.has_value()) break;
133
10.7M
                }
134
5.73M
            }
135
5.73M
            vChecks.clear();
136
5.73M
        } 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
366k
        do {
81
366k
            {
82
366k
                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
366k
                if (nNow) {
85
365k
                    if (local_result.has_value() && !m_result.has_value()) {
86
1.01k
                        std::swap(local_result, m_result);
87
1.01k
                    }
88
365k
                    nTodo -= nNow;
89
365k
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
67.8k
                        m_master_cv.notify_one();
92
67.8k
                    }
93
365k
                } else {
94
                    // first iteration
95
1.01k
                    nTotal++;
96
1.01k
                }
97
                // logically, the do loop starts here
98
566k
                while (queue.empty() && !m_request_stop) {
99
201k
                    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
200k
                    nIdle++;
108
200k
                    cond.wait(lock); // wait
109
200k
                    nIdle--;
110
200k
                }
111
365k
                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
365k
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
365k
                auto start_it = queue.end() - nNow;
123
365k
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
365k
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
365k
                do_work = !m_result.has_value();
127
365k
            }
128
            // execute work
129
365k
            if (do_work) {
130
404k
                for (T& check : vChecks) {
131
404k
                    local_result = check();
132
404k
                    if (local_result.has_value()) break;
133
404k
                }
134
355k
            }
135
365k
            vChecks.clear();
136
365k
        } 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
0
                        m_master_cv.notify_one();
92
0
                    }
93
805
                } else {
94
                    // first iteration
95
4
                    nTotal++;
96
4
                }
97
                // logically, the do loop starts here
98
812
                while (queue.empty() && !m_request_stop) {
99
4
                    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
3
                    nIdle++;
108
3
                    cond.wait(lock); // wait
109
3
                    nIdle--;
110
3
                }
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
485k
        do {
81
485k
            {
82
485k
                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
485k
                if (nNow) {
85
484k
                    if (local_result.has_value() && !m_result.has_value()) {
86
0
                        std::swap(local_result, m_result);
87
0
                    }
88
484k
                    nTodo -= nNow;
89
484k
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
96.3k
                        m_master_cv.notify_one();
92
96.3k
                    }
93
484k
                } else {
94
                    // first iteration
95
997
                    nTotal++;
96
997
                }
97
                // logically, the do loop starts here
98
771k
                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
484k
                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
484k
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
484k
                auto start_it = queue.end() - nNow;
123
484k
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
484k
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
484k
                do_work = !m_result.has_value();
127
484k
            }
128
            // execute work
129
484k
            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
484k
            }
135
484k
            vChecks.clear();
136
484k
        } 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
180k
        do {
81
180k
            {
82
180k
                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
180k
                if (nNow) {
85
25.9k
                    if (local_result.has_value() && !m_result.has_value()) {
86
2.62k
                        std::swap(local_result, m_result);
87
2.62k
                    }
88
25.9k
                    nTodo -= nNow;
89
25.9k
                    if (nTodo == 0 && !fMaster) {
90
                        // We processed the last element; inform the master it can exit and return the result
91
18.2k
                        m_master_cv.notify_one();
92
18.2k
                    }
93
154k
                } else {
94
                    // first iteration
95
154k
                    nTotal++;
96
154k
                }
97
                // logically, the do loop starts here
98
203k
                while (queue.empty() && !m_request_stop) {
99
175k
                    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
22.4k
                    nIdle++;
108
22.4k
                    cond.wait(lock); // wait
109
22.4k
                    nIdle--;
110
22.4k
                }
111
27.3k
                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
25.9k
                nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
122
25.9k
                auto start_it = queue.end() - nNow;
123
25.9k
                vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
124
25.9k
                queue.erase(start_it, queue.end());
125
                // Check whether we need to do work at all
126
25.9k
                do_work = !m_result.has_value();
127
25.9k
            }
128
            // execute work
129
25.9k
            if (do_work) {
130
48.3k
                for (T& check : vChecks) {
131
48.3k
                    local_result = check();
132
48.3k
                    if (local_result.has_value()) break;
133
48.3k
                }
134
25.0k
            }
135
25.9k
            vChecks.clear();
136
25.9k
        } 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.69M
    {
174
2.69M
        if (vChecks.empty()) {
175
293k
            return;
176
293k
        }
177
178
2.40M
        {
179
2.40M
            LOCK(m_mutex);
180
2.40M
            queue.insert(queue.end(), std::make_move_iterator(vChecks.begin()), std::make_move_iterator(vChecks.end()));
181
2.40M
            nTodo += vChecks.size();
182
2.40M
        }
183
184
2.40M
        if (vChecks.size() == 1) {
185
286k
            m_worker_cv.notify_one();
186
2.11M
        } else {
187
2.11M
            m_worker_cv.notify_all();
188
2.11M
        }
189
2.40M
    }
CCheckQueue<FakeCheckCheckCompletion, int>::Add(std::vector<FakeCheckCheckCompletion, std::allocator<FakeCheckCheckCompletion>>&&)
Line
Count
Source
173
2.38M
    {
174
2.38M
        if (vChecks.empty()) {
175
238k
            return;
176
238k
        }
177
178
2.15M
        {
179
2.15M
            LOCK(m_mutex);
180
2.15M
            queue.insert(queue.end(), std::make_move_iterator(vChecks.begin()), std::make_move_iterator(vChecks.end()));
181
2.15M
            nTodo += vChecks.size();
182
2.15M
        }
183
184
2.15M
        if (vChecks.size() == 1) {
185
238k
            m_worker_cv.notify_one();
186
1.91M
        } else {
187
1.91M
            m_worker_cv.notify_all();
188
1.91M
        }
189
2.15M
    }
CCheckQueue<FixedCheck, int>::Add(std::vector<FixedCheck, std::allocator<FixedCheck>>&&)
Line
Count
Source
173
111k
    {
174
111k
        if (vChecks.empty()) {
175
11.1k
            return;
176
11.1k
        }
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.3k
            m_worker_cv.notify_one();
186
89.3k
        } else {
187
89.3k
            m_worker_cv.notify_all();
188
89.3k
        }
189
100k
    }
CCheckQueue<UniqueCheck, int>::Add(std::vector<UniqueCheck, std::allocator<UniqueCheck>>&&)
Line
Count
Source
173
22.3k
    {
174
22.3k
        if (vChecks.empty()) {
175
2.29k
            return;
176
2.29k
        }
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.25k
            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
11.1k
            return;
176
11.1k
        }
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.3k
            m_worker_cv.notify_one();
186
89.1k
        } else {
187
89.1k
            m_worker_cv.notify_all();
188
89.1k
        }
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
64.2k
    {
174
64.2k
        if (vChecks.empty()) {
175
30.8k
            return;
176
30.8k
        }
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.7k
            m_worker_cv.notify_one();
186
22.7k
        } 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.69M
    {
230
2.69M
        m_queue.Add(std::move(vChecks));
231
2.69M
    }
CCheckQueueControl<FakeCheckCheckCompletion, int>::Add(std::vector<FakeCheckCheckCompletion, std::allocator<FakeCheckCheckCompletion>>&&)
Line
Count
Source
229
2.38M
    {
230
2.38M
        m_queue.Add(std::move(vChecks));
231
2.38M
    }
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.3k
    {
230
22.3k
        m_queue.Add(std::move(vChecks));
231
22.3k
    }
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
64.2k
    {
230
64.2k
        m_queue.Add(std::move(vChecks));
231
64.2k
    }
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