Coverage Report

Created: 2026-10-27 17:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/util/blocking_queue.hpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
// This file is copied from
18
// https://github.com/apache/impala/blob/branch-2.9.0/be/src/util/blocking-queue.hpp
19
// and modified by Doris
20
21
#pragma once
22
23
#include <unistd.h>
24
25
#include <atomic>
26
#include <condition_variable>
27
#include <list>
28
#include <mutex>
29
30
#include "common/logging.h"
31
#include "util/stopwatch.hpp"
32
33
#ifdef BE_TEST
34
#include "cpp/sync_point.h"
35
#endif
36
37
namespace doris {
38
#include "common/compile_check_begin.h"
39
// Fixed capacity FIFO queue, where both BlockingGet and BlockingPut operations block
40
// if the queue is empty or full, respectively.
41
template <typename T>
42
class BlockingQueue {
43
public:
44
    BlockingQueue(uint32_t max_elements)
45
228
            : _shutdown(false),
46
228
              _max_elements(max_elements),
47
228
              _total_get_wait_time(0),
48
228
              _total_put_wait_time(0),
49
228
              _get_waiting(0),
50
228
              _put_waiting(0) {}
_ZN5doris13BlockingQueueINS_14WorkThreadPoolILb0EE4TaskEEC2Ej
Line
Count
Source
45
204
            : _shutdown(false),
46
204
              _max_elements(max_elements),
47
204
              _total_get_wait_time(0),
48
204
              _total_put_wait_time(0),
49
204
              _get_waiting(0),
50
204
              _put_waiting(0) {}
_ZN5doris13BlockingQueueIiEC2Ej
Line
Count
Source
45
8
            : _shutdown(false),
46
8
              _max_elements(max_elements),
47
8
              _total_get_wait_time(0),
48
8
              _total_put_wait_time(0),
49
8
              _get_waiting(0),
50
8
              _put_waiting(0) {}
_ZN5doris13BlockingQueueIlEC2Ej
Line
Count
Source
45
2
            : _shutdown(false),
46
2
              _max_elements(max_elements),
47
2
              _total_get_wait_time(0),
48
2
              _total_put_wait_time(0),
49
2
              _get_waiting(0),
50
2
              _put_waiting(0) {}
_ZN5doris13BlockingQueueISt10shared_ptrIN5arrow11RecordBatchEEEC2Ej
Line
Count
Source
45
12
            : _shutdown(false),
46
12
              _max_elements(max_elements),
47
12
              _total_get_wait_time(0),
48
12
              _total_put_wait_time(0),
49
12
              _get_waiting(0),
50
12
              _put_waiting(0) {}
_ZN5doris13BlockingQueueIPN7RdKafka7MessageEEC2Ej
Line
Count
Source
45
2
            : _shutdown(false),
46
2
              _max_elements(max_elements),
47
2
              _total_get_wait_time(0),
48
2
              _total_put_wait_time(0),
49
2
              _get_waiting(0),
50
2
              _put_waiting(0) {}
51
52
    // Get an element from the queue, waiting indefinitely for one to become available.
53
    // Returns false if we were shut down prior to getting the element, and there
54
    // are no more elements available.
55
122k
    bool blocking_get(T* out) { return controlled_blocking_get(out, MAX_CV_WAIT_TIMEOUT_MS); }
_ZN5doris13BlockingQueueINS_14WorkThreadPoolILb0EE4TaskEE12blocking_getEPS3_
Line
Count
Source
55
2.21k
    bool blocking_get(T* out) { return controlled_blocking_get(out, MAX_CV_WAIT_TIMEOUT_MS); }
_ZN5doris13BlockingQueueIiE12blocking_getEPi
Line
Count
Source
55
119k
    bool blocking_get(T* out) { return controlled_blocking_get(out, MAX_CV_WAIT_TIMEOUT_MS); }
_ZN5doris13BlockingQueueIlE12blocking_getEPl
Line
Count
Source
55
4
    bool blocking_get(T* out) { return controlled_blocking_get(out, MAX_CV_WAIT_TIMEOUT_MS); }
_ZN5doris13BlockingQueueISt10shared_ptrIN5arrow11RecordBatchEEE12blocking_getEPS4_
Line
Count
Source
55
4
    bool blocking_get(T* out) { return controlled_blocking_get(out, MAX_CV_WAIT_TIMEOUT_MS); }
_ZN5doris13BlockingQueueIPN7RdKafka7MessageEE12blocking_getEPS3_
Line
Count
Source
55
2
    bool blocking_get(T* out) { return controlled_blocking_get(out, MAX_CV_WAIT_TIMEOUT_MS); }
56
57
    // Blocking_get and blocking_put may cause deadlock,
58
    // but we still don't find root cause,
59
    // introduce condition variable wait timeout to avoid blocking queue deadlock temporarily.
60
122k
    bool controlled_blocking_get(T* out, int64_t cv_wait_timeout_ms) {
61
122k
        MonotonicStopWatch timer;
62
122k
        timer.start();
63
122k
        std::unique_lock<std::mutex> unique_lock(_lock);
64
122k
#ifdef BE_TEST
65
122k
        TEST_SYNC_POINT("BlockingQueue::controlled_blocking_get::after_lock");
66
122k
#endif
67
124k
        while (!(_shutdown || !_list.empty())) {
68
2.45k
            ++_get_waiting;
69
2.45k
#ifdef BE_TEST
70
2.45k
            TEST_SYNC_POINT("BlockingQueue::controlled_blocking_get::before_wait");
71
2.45k
#endif
72
2.45k
            _get_cv.wait_for(unique_lock, std::chrono::milliseconds(cv_wait_timeout_ms));
73
2.45k
            DCHECK_GT(_get_waiting, 0);
74
2.45k
            --_get_waiting;
75
2.45k
        }
76
122k
        _total_get_wait_time += timer.elapsed_time();
77
78
122k
        if (!_list.empty()) {
79
100k
            *out = _list.front();
80
100k
            _list.pop_front();
81
100k
            const bool has_put_waiter = _put_waiting > 0;
82
100k
            unique_lock.unlock();
83
100k
            if (has_put_waiter) {
84
45.9k
                _put_cv.notify_one();
85
45.9k
            }
86
100k
            return true;
87
100k
        } else {
88
21.9k
            assert(_shutdown);
89
22.0k
            return false;
90
21.9k
        }
91
122k
    }
_ZN5doris13BlockingQueueINS_14WorkThreadPoolILb0EE4TaskEE23controlled_blocking_getEPS3_l
Line
Count
Source
60
2.21k
    bool controlled_blocking_get(T* out, int64_t cv_wait_timeout_ms) {
61
2.21k
        MonotonicStopWatch timer;
62
2.21k
        timer.start();
63
2.21k
        std::unique_lock<std::mutex> unique_lock(_lock);
64
2.21k
#ifdef BE_TEST
65
2.21k
        TEST_SYNC_POINT("BlockingQueue::controlled_blocking_get::after_lock");
66
2.21k
#endif
67
4.43k
        while (!(_shutdown || !_list.empty())) {
68
2.21k
            ++_get_waiting;
69
2.21k
#ifdef BE_TEST
70
2.21k
            TEST_SYNC_POINT("BlockingQueue::controlled_blocking_get::before_wait");
71
2.21k
#endif
72
2.21k
            _get_cv.wait_for(unique_lock, std::chrono::milliseconds(cv_wait_timeout_ms));
73
2.21k
            DCHECK_GT(_get_waiting, 0);
74
2.21k
            --_get_waiting;
75
2.21k
        }
76
2.21k
        _total_get_wait_time += timer.elapsed_time();
77
78
2.21k
        if (!_list.empty()) {
79
154
            *out = _list.front();
80
154
            _list.pop_front();
81
154
            const bool has_put_waiter = _put_waiting > 0;
82
154
            unique_lock.unlock();
83
154
            if (has_put_waiter) {
84
0
                _put_cv.notify_one();
85
0
            }
86
154
            return true;
87
2.06k
        } else {
88
2.06k
            assert(_shutdown);
89
2.06k
            return false;
90
2.06k
        }
91
2.21k
    }
_ZN5doris13BlockingQueueIiE23controlled_blocking_getEPil
Line
Count
Source
60
119k
    bool controlled_blocking_get(T* out, int64_t cv_wait_timeout_ms) {
61
119k
        MonotonicStopWatch timer;
62
119k
        timer.start();
63
119k
        std::unique_lock<std::mutex> unique_lock(_lock);
64
119k
#ifdef BE_TEST
65
119k
        TEST_SYNC_POINT("BlockingQueue::controlled_blocking_get::after_lock");
66
119k
#endif
67
120k
        while (!(_shutdown || !_list.empty())) {
68
228
            ++_get_waiting;
69
228
#ifdef BE_TEST
70
228
            TEST_SYNC_POINT("BlockingQueue::controlled_blocking_get::before_wait");
71
228
#endif
72
228
            _get_cv.wait_for(unique_lock, std::chrono::milliseconds(cv_wait_timeout_ms));
73
228
            DCHECK_GT(_get_waiting, 0);
74
228
            --_get_waiting;
75
228
        }
76
119k
        _total_get_wait_time += timer.elapsed_time();
77
78
119k
        if (!_list.empty()) {
79
100k
            *out = _list.front();
80
100k
            _list.pop_front();
81
100k
            const bool has_put_waiter = _put_waiting > 0;
82
100k
            unique_lock.unlock();
83
100k
            if (has_put_waiter) {
84
45.9k
                _put_cv.notify_one();
85
45.9k
            }
86
100k
            return true;
87
100k
        } else {
88
19.8k
            assert(_shutdown);
89
20.0k
            return false;
90
19.8k
        }
91
119k
    }
_ZN5doris13BlockingQueueIlE23controlled_blocking_getEPll
Line
Count
Source
60
4
    bool controlled_blocking_get(T* out, int64_t cv_wait_timeout_ms) {
61
4
        MonotonicStopWatch timer;
62
4
        timer.start();
63
4
        std::unique_lock<std::mutex> unique_lock(_lock);
64
4
#ifdef BE_TEST
65
4
        TEST_SYNC_POINT("BlockingQueue::controlled_blocking_get::after_lock");
66
4
#endif
67
4
        while (!(_shutdown || !_list.empty())) {
68
0
            ++_get_waiting;
69
0
#ifdef BE_TEST
70
0
            TEST_SYNC_POINT("BlockingQueue::controlled_blocking_get::before_wait");
71
0
#endif
72
0
            _get_cv.wait_for(unique_lock, std::chrono::milliseconds(cv_wait_timeout_ms));
73
0
            DCHECK_GT(_get_waiting, 0);
74
0
            --_get_waiting;
75
0
        }
76
4
        _total_get_wait_time += timer.elapsed_time();
77
78
4
        if (!_list.empty()) {
79
2
            *out = _list.front();
80
2
            _list.pop_front();
81
2
            const bool has_put_waiter = _put_waiting > 0;
82
2
            unique_lock.unlock();
83
2
            if (has_put_waiter) {
84
0
                _put_cv.notify_one();
85
0
            }
86
2
            return true;
87
2
        } else {
88
2
            assert(_shutdown);
89
2
            return false;
90
2
        }
91
4
    }
_ZN5doris13BlockingQueueISt10shared_ptrIN5arrow11RecordBatchEEE23controlled_blocking_getEPS4_l
Line
Count
Source
60
4
    bool controlled_blocking_get(T* out, int64_t cv_wait_timeout_ms) {
61
4
        MonotonicStopWatch timer;
62
4
        timer.start();
63
4
        std::unique_lock<std::mutex> unique_lock(_lock);
64
4
#ifdef BE_TEST
65
4
        TEST_SYNC_POINT("BlockingQueue::controlled_blocking_get::after_lock");
66
4
#endif
67
4
        while (!(_shutdown || !_list.empty())) {
68
0
            ++_get_waiting;
69
0
#ifdef BE_TEST
70
0
            TEST_SYNC_POINT("BlockingQueue::controlled_blocking_get::before_wait");
71
0
#endif
72
0
            _get_cv.wait_for(unique_lock, std::chrono::milliseconds(cv_wait_timeout_ms));
73
0
            DCHECK_GT(_get_waiting, 0);
74
0
            --_get_waiting;
75
0
        }
76
4
        _total_get_wait_time += timer.elapsed_time();
77
78
4
        if (!_list.empty()) {
79
4
            *out = _list.front();
80
4
            _list.pop_front();
81
4
            const bool has_put_waiter = _put_waiting > 0;
82
4
            unique_lock.unlock();
83
4
            if (has_put_waiter) {
84
0
                _put_cv.notify_one();
85
0
            }
86
4
            return true;
87
4
        } else {
88
0
            assert(_shutdown);
89
0
            return false;
90
0
        }
91
4
    }
_ZN5doris13BlockingQueueIPN7RdKafka7MessageEE23controlled_blocking_getEPS3_l
Line
Count
Source
60
4
    bool controlled_blocking_get(T* out, int64_t cv_wait_timeout_ms) {
61
4
        MonotonicStopWatch timer;
62
4
        timer.start();
63
4
        std::unique_lock<std::mutex> unique_lock(_lock);
64
4
#ifdef BE_TEST
65
4
        TEST_SYNC_POINT("BlockingQueue::controlled_blocking_get::after_lock");
66
4
#endif
67
16
        while (!(_shutdown || !_list.empty())) {
68
12
            ++_get_waiting;
69
12
#ifdef BE_TEST
70
12
            TEST_SYNC_POINT("BlockingQueue::controlled_blocking_get::before_wait");
71
12
#endif
72
12
            _get_cv.wait_for(unique_lock, std::chrono::milliseconds(cv_wait_timeout_ms));
73
12
            DCHECK_GT(_get_waiting, 0);
74
12
            --_get_waiting;
75
12
        }
76
4
        _total_get_wait_time += timer.elapsed_time();
77
78
4
        if (!_list.empty()) {
79
0
            *out = _list.front();
80
0
            _list.pop_front();
81
0
            const bool has_put_waiter = _put_waiting > 0;
82
0
            unique_lock.unlock();
83
0
            if (has_put_waiter) {
84
0
                _put_cv.notify_one();
85
0
            }
86
0
            return true;
87
4
        } else {
88
4
            assert(_shutdown);
89
4
            return false;
90
4
        }
91
4
    }
92
93
    // Puts an element into the queue, waiting indefinitely until there is space.
94
    // If the queue is shut down, returns false.
95
99.9k
    bool blocking_put(const T& val) { return controlled_blocking_put(val, MAX_CV_WAIT_TIMEOUT_MS); }
Unexecuted instantiation: _ZN5doris13BlockingQueueINS_14WorkThreadPoolILb0EE4TaskEE12blocking_putERKS3_
_ZN5doris13BlockingQueueISt10shared_ptrIN5arrow11RecordBatchEEE12blocking_putERKS4_
Line
Count
Source
95
8
    bool blocking_put(const T& val) { return controlled_blocking_put(val, MAX_CV_WAIT_TIMEOUT_MS); }
_ZN5doris13BlockingQueueIiE12blocking_putERKi
Line
Count
Source
95
99.9k
    bool blocking_put(const T& val) { return controlled_blocking_put(val, MAX_CV_WAIT_TIMEOUT_MS); }
_ZN5doris13BlockingQueueIlE12blocking_putERKl
Line
Count
Source
95
4
    bool blocking_put(const T& val) { return controlled_blocking_put(val, MAX_CV_WAIT_TIMEOUT_MS); }
96
97
    // Blocking_get and blocking_put may cause deadlock,
98
    // but we still don't find root cause,
99
    // introduce condition variable wait timeout to avoid blocking queue deadlock temporarily.
100
99.9k
    bool controlled_blocking_put(const T& val, int64_t cv_wait_timeout_ms) {
101
99.9k
        MonotonicStopWatch timer;
102
99.9k
        timer.start();
103
99.9k
        std::unique_lock<std::mutex> unique_lock(_lock);
104
113k
        while (!(_shutdown || _list.size() < _max_elements)) {
105
13.4k
            ++_put_waiting;
106
13.4k
#ifdef BE_TEST
107
13.4k
            TEST_SYNC_POINT("BlockingQueue::controlled_blocking_put::before_wait");
108
13.4k
#endif
109
13.4k
            _put_cv.wait_for(unique_lock, std::chrono::milliseconds(cv_wait_timeout_ms));
110
13.4k
            DCHECK_GT(_put_waiting, 0);
111
13.4k
            --_put_waiting;
112
13.4k
        }
113
99.9k
        _total_put_wait_time += timer.elapsed_time();
114
115
99.9k
        if (_shutdown) {
116
2
            return false;
117
2
        }
118
119
99.9k
        _list.push_back(val);
120
99.9k
        const bool has_get_waiter = _get_waiting > 0;
121
99.9k
        unique_lock.unlock();
122
99.9k
        if (has_get_waiter) {
123
838
            _get_cv.notify_one();
124
838
        }
125
99.9k
        return true;
126
99.9k
    }
Unexecuted instantiation: _ZN5doris13BlockingQueueINS_14WorkThreadPoolILb0EE4TaskEE23controlled_blocking_putERKS3_l
_ZN5doris13BlockingQueueISt10shared_ptrIN5arrow11RecordBatchEEE23controlled_blocking_putERKS4_l
Line
Count
Source
100
8
    bool controlled_blocking_put(const T& val, int64_t cv_wait_timeout_ms) {
101
8
        MonotonicStopWatch timer;
102
8
        timer.start();
103
8
        std::unique_lock<std::mutex> unique_lock(_lock);
104
8
        while (!(_shutdown || _list.size() < _max_elements)) {
105
0
            ++_put_waiting;
106
0
#ifdef BE_TEST
107
0
            TEST_SYNC_POINT("BlockingQueue::controlled_blocking_put::before_wait");
108
0
#endif
109
0
            _put_cv.wait_for(unique_lock, std::chrono::milliseconds(cv_wait_timeout_ms));
110
0
            DCHECK_GT(_put_waiting, 0);
111
0
            --_put_waiting;
112
0
        }
113
8
        _total_put_wait_time += timer.elapsed_time();
114
115
8
        if (_shutdown) {
116
0
            return false;
117
0
        }
118
119
8
        _list.push_back(val);
120
8
        const bool has_get_waiter = _get_waiting > 0;
121
8
        unique_lock.unlock();
122
8
        if (has_get_waiter) {
123
0
            _get_cv.notify_one();
124
0
        }
125
8
        return true;
126
8
    }
_ZN5doris13BlockingQueueIiE23controlled_blocking_putERKil
Line
Count
Source
100
99.9k
    bool controlled_blocking_put(const T& val, int64_t cv_wait_timeout_ms) {
101
99.9k
        MonotonicStopWatch timer;
102
99.9k
        timer.start();
103
99.9k
        std::unique_lock<std::mutex> unique_lock(_lock);
104
113k
        while (!(_shutdown || _list.size() < _max_elements)) {
105
13.4k
            ++_put_waiting;
106
13.4k
#ifdef BE_TEST
107
13.4k
            TEST_SYNC_POINT("BlockingQueue::controlled_blocking_put::before_wait");
108
13.4k
#endif
109
13.4k
            _put_cv.wait_for(unique_lock, std::chrono::milliseconds(cv_wait_timeout_ms));
110
13.4k
            DCHECK_GT(_put_waiting, 0);
111
13.4k
            --_put_waiting;
112
13.4k
        }
113
99.9k
        _total_put_wait_time += timer.elapsed_time();
114
115
99.9k
        if (_shutdown) {
116
0
            return false;
117
0
        }
118
119
99.9k
        _list.push_back(val);
120
99.9k
        const bool has_get_waiter = _get_waiting > 0;
121
99.9k
        unique_lock.unlock();
122
99.9k
        if (has_get_waiter) {
123
838
            _get_cv.notify_one();
124
838
        }
125
99.9k
        return true;
126
99.9k
    }
_ZN5doris13BlockingQueueIlE23controlled_blocking_putERKll
Line
Count
Source
100
4
    bool controlled_blocking_put(const T& val, int64_t cv_wait_timeout_ms) {
101
4
        MonotonicStopWatch timer;
102
4
        timer.start();
103
4
        std::unique_lock<std::mutex> unique_lock(_lock);
104
4
        while (!(_shutdown || _list.size() < _max_elements)) {
105
0
            ++_put_waiting;
106
0
#ifdef BE_TEST
107
0
            TEST_SYNC_POINT("BlockingQueue::controlled_blocking_put::before_wait");
108
0
#endif
109
0
            _put_cv.wait_for(unique_lock, std::chrono::milliseconds(cv_wait_timeout_ms));
110
0
            DCHECK_GT(_put_waiting, 0);
111
0
            --_put_waiting;
112
0
        }
113
4
        _total_put_wait_time += timer.elapsed_time();
114
115
4
        if (_shutdown) {
116
2
            return false;
117
2
        }
118
119
2
        _list.push_back(val);
120
2
        const bool has_get_waiter = _get_waiting > 0;
121
2
        unique_lock.unlock();
122
2
        if (has_get_waiter) {
123
0
            _get_cv.notify_one();
124
0
        }
125
2
        return true;
126
4
    }
Unexecuted instantiation: _ZN5doris13BlockingQueueIPN7RdKafka7MessageEE23controlled_blocking_putERKS3_l
127
128
    // Return false if queue full or has been shutdown.
129
188
    bool try_put(const T& val) {
130
188
        MonotonicStopWatch timer;
131
188
        timer.start();
132
188
        std::unique_lock<std::mutex> unique_lock(_lock);
133
188
#ifdef BE_TEST
134
188
        TEST_SYNC_POINT("BlockingQueue::try_put::after_lock");
135
188
#endif
136
188
        _total_put_wait_time += timer.elapsed_time();
137
138
188
        if (_shutdown || _list.size() >= _max_elements) {
139
12
            return false;
140
12
        }
141
142
176
        _list.push_back(val);
143
176
        const bool has_get_waiter = _get_waiting > 0;
144
176
        unique_lock.unlock();
145
176
        if (has_get_waiter) {
146
155
            _get_cv.notify_one();
147
155
        }
148
176
        return true;
149
188
    }
_ZN5doris13BlockingQueueINS_14WorkThreadPoolILb0EE4TaskEE7try_putERKS3_
Line
Count
Source
129
182
    bool try_put(const T& val) {
130
182
        MonotonicStopWatch timer;
131
182
        timer.start();
132
182
        std::unique_lock<std::mutex> unique_lock(_lock);
133
182
#ifdef BE_TEST
134
182
        TEST_SYNC_POINT("BlockingQueue::try_put::after_lock");
135
182
#endif
136
182
        _total_put_wait_time += timer.elapsed_time();
137
138
182
        if (_shutdown || _list.size() >= _max_elements) {
139
12
            return false;
140
12
        }
141
142
170
        _list.push_back(val);
143
170
        const bool has_get_waiter = _get_waiting > 0;
144
170
        unique_lock.unlock();
145
170
        if (has_get_waiter) {
146
151
            _get_cv.notify_one();
147
151
        }
148
170
        return true;
149
182
    }
_ZN5doris13BlockingQueueIiE7try_putERKi
Line
Count
Source
129
6
    bool try_put(const T& val) {
130
6
        MonotonicStopWatch timer;
131
6
        timer.start();
132
6
        std::unique_lock<std::mutex> unique_lock(_lock);
133
6
#ifdef BE_TEST
134
6
        TEST_SYNC_POINT("BlockingQueue::try_put::after_lock");
135
6
#endif
136
6
        _total_put_wait_time += timer.elapsed_time();
137
138
6
        if (_shutdown || _list.size() >= _max_elements) {
139
0
            return false;
140
0
        }
141
142
6
        _list.push_back(val);
143
6
        const bool has_get_waiter = _get_waiting > 0;
144
6
        unique_lock.unlock();
145
6
        if (has_get_waiter) {
146
4
            _get_cv.notify_one();
147
4
        }
148
6
        return true;
149
6
    }
150
151
    // Shut down the queue. Wakes up all threads waiting on BlockingGet or BlockingPut.
152
254
    void shutdown() {
153
254
        {
154
254
            std::lock_guard<std::mutex> guard(_lock);
155
254
            _shutdown = true;
156
254
        }
157
158
254
        _get_cv.notify_all();
159
254
        _put_cv.notify_all();
160
254
    }
_ZN5doris13BlockingQueueINS_14WorkThreadPoolILb0EE4TaskEE8shutdownEv
Line
Count
Source
152
236
    void shutdown() {
153
236
        {
154
236
            std::lock_guard<std::mutex> guard(_lock);
155
236
            _shutdown = true;
156
236
        }
157
158
236
        _get_cv.notify_all();
159
236
        _put_cv.notify_all();
160
236
    }
_ZN5doris13BlockingQueueIlE8shutdownEv
Line
Count
Source
152
2
    void shutdown() {
153
2
        {
154
2
            std::lock_guard<std::mutex> guard(_lock);
155
2
            _shutdown = true;
156
2
        }
157
158
2
        _get_cv.notify_all();
159
2
        _put_cv.notify_all();
160
2
    }
_ZN5doris13BlockingQueueIiE8shutdownEv
Line
Count
Source
152
6
    void shutdown() {
153
6
        {
154
6
            std::lock_guard<std::mutex> guard(_lock);
155
6
            _shutdown = true;
156
6
        }
157
158
6
        _get_cv.notify_all();
159
6
        _put_cv.notify_all();
160
6
    }
_ZN5doris13BlockingQueueISt10shared_ptrIN5arrow11RecordBatchEEE8shutdownEv
Line
Count
Source
152
4
    void shutdown() {
153
4
        {
154
4
            std::lock_guard<std::mutex> guard(_lock);
155
4
            _shutdown = true;
156
4
        }
157
158
4
        _get_cv.notify_all();
159
4
        _put_cv.notify_all();
160
4
    }
_ZN5doris13BlockingQueueIPN7RdKafka7MessageEE8shutdownEv
Line
Count
Source
152
6
    void shutdown() {
153
6
        {
154
6
            std::lock_guard<std::mutex> guard(_lock);
155
6
            _shutdown = true;
156
6
        }
157
158
6
        _get_cv.notify_all();
159
6
        _put_cv.notify_all();
160
6
    }
161
162
2.24k
    uint32_t get_size() const {
163
2.24k
        std::lock_guard<std::mutex> l(_lock);
164
2.24k
        return static_cast<uint32_t>(_list.size());
165
2.24k
    }
_ZNK5doris13BlockingQueueINS_14WorkThreadPoolILb0EE4TaskEE8get_sizeEv
Line
Count
Source
162
2.24k
    uint32_t get_size() const {
163
2.24k
        std::lock_guard<std::mutex> l(_lock);
164
2.24k
        return static_cast<uint32_t>(_list.size());
165
2.24k
    }
Unexecuted instantiation: _ZNK5doris13BlockingQueueISt10shared_ptrIN5arrow11RecordBatchEEE8get_sizeEv
_ZNK5doris13BlockingQueueIPN7RdKafka7MessageEE8get_sizeEv
Line
Count
Source
162
2
    uint32_t get_size() const {
163
2
        std::lock_guard<std::mutex> l(_lock);
164
2
        return static_cast<uint32_t>(_list.size());
165
2
    }
166
167
14
    uint32_t get_capacity() const { return _max_elements; }
168
169
#ifdef BE_TEST
170
16
    size_t get_waiting_count_for_test() const {
171
16
        std::lock_guard<std::mutex> guard(_lock);
172
16
        return _get_waiting;
173
16
    }
174
175
16
    size_t put_waiting_count_for_test() const {
176
16
        std::lock_guard<std::mutex> guard(_lock);
177
16
        return _put_waiting;
178
16
    }
179
#endif
180
181
    // Returns the total amount of time threads have blocked in BlockingGet.
182
16
    uint64_t total_get_wait_time() const { return _total_get_wait_time; }
_ZNK5doris13BlockingQueueINS_14WorkThreadPoolILb0EE4TaskEE19total_get_wait_timeEv
Line
Count
Source
182
14
    uint64_t total_get_wait_time() const { return _total_get_wait_time; }
_ZNK5doris13BlockingQueueIPN7RdKafka7MessageEE19total_get_wait_timeEv
Line
Count
Source
182
2
    uint64_t total_get_wait_time() const { return _total_get_wait_time; }
183
184
    // Returns the total amount of time threads have blocked in BlockingPut.
185
16
    uint64_t total_put_wait_time() const { return _total_put_wait_time; }
_ZNK5doris13BlockingQueueINS_14WorkThreadPoolILb0EE4TaskEE19total_put_wait_timeEv
Line
Count
Source
185
14
    uint64_t total_put_wait_time() const { return _total_put_wait_time; }
_ZNK5doris13BlockingQueueIPN7RdKafka7MessageEE19total_put_wait_timeEv
Line
Count
Source
185
2
    uint64_t total_put_wait_time() const { return _total_put_wait_time; }
186
187
private:
188
    static constexpr int64_t MAX_CV_WAIT_TIMEOUT_MS = 60 * 60 * 1000; // 1 hour
189
    bool _shutdown;
190
    const int _max_elements;
191
    std::condition_variable _get_cv; // 'get' callers wait on this
192
    std::condition_variable _put_cv; // 'put' callers wait on this
193
    // _lock guards access to _shutdown, _get_waiting, _put_waiting, _list, total_get_wait_time, and total_put_wait_time
194
    mutable std::mutex _lock;
195
    std::list<T> _list;
196
    std::atomic<uint64_t> _total_get_wait_time;
197
    std::atomic<uint64_t> _total_put_wait_time;
198
    // Number of threads currently inside the corresponding wait_for() call. The waiter that
199
    // increments a counter is also responsible for decrementing it after every wakeup reason.
200
    // Notifiers only inspect these counters and never consume a waiter's registration.
201
    size_t _get_waiting;
202
    size_t _put_waiting;
203
};
204
#include "common/compile_check_end.h"
205
} // namespace doris