Coverage Report

Created: 2026-08-21 02:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/util/once.h
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/once.h
19
// and modified by Doris
20
21
#pragma once
22
23
#include <atomic>
24
#include <mutex>
25
#include <stdexcept>
26
27
#include "common/exception.h"
28
#include "storage/olap_common.h"
29
30
namespace doris {
31
32
// Utility class for implementing thread-safe call-once semantics.
33
//
34
// call() will return stored result regardless of whether the first invocation
35
// returns a success status or not.
36
//
37
// Example:
38
//   class Resource {
39
//   public:
40
//     Status init() {
41
//       _init_once.call([this] { return _do_init(); });
42
//     }
43
//
44
//     bool is_inited() const {
45
//       return _init_once.has_called() && _init_once.stored_result().ok();
46
//     }
47
//   private:
48
//     Status _do_init() { /* init logic here */ }
49
//     DorisCallOnce<Status> _init_once;
50
//   };
51
template <typename ReturnType>
52
class DorisCallOnce {
53
public:
54
1.70M
    DorisCallOnce() : _has_called(false) {}
_ZN5doris13DorisCallOnceIN2tl8expectedINS_21EncryptionAlgorithmPBENS_6StatusEEEEC2Ev
Line
Count
Source
54
517k
    DorisCallOnce() : _has_called(false) {}
_ZN5doris13DorisCallOnceINS_6StatusEEC2Ev
Line
Count
Source
54
1.19M
    DorisCallOnce() : _has_called(false) {}
55
56
    // this method is not exception safe, it will core when exception occurs in
57
    // callback method. I have tested the code https://en.cppreference.com/w/cpp/thread/call_once.
58
    // If the underlying `once_flag` has yet to be invoked, invokes the provided
59
    // lambda and stores its return value. Otherwise, returns the stored Status.
60
    // template <typename Fn>
61
    // ReturnType call(Fn fn) {
62
    //     std::call_once(_once_flag, [this, fn] {
63
    //         _status = fn();
64
    //         _has_called.store(true, std::memory_order_release);
65
    //     });
66
    //     return _status;
67
    // }
68
69
    // If exception occurs in the function, the call flag is set, if user call
70
    // it again, the same exception will be thrown.
71
    // It is different from std::call_once. This is because if a method is called once
72
    // some internal state is changed, it maybe not called again although exception
73
    // occurred.
74
    template <typename Fn>
75
573k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
573k
        if (has_called()) {
78
218k
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
218k
            return _status;
82
218k
        }
83
354k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
354k
        if (has_called()) {
86
178
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
178
            return _status;
90
178
        }
91
354k
        try {
92
354k
            _status = fn();
93
354k
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
354k
        _has_called.store(true, std::memory_order_release);
102
354k
        return _status;
103
354k
    }
Unexecuted instantiation: _ZN5doris13DorisCallOnceIN2tl8expectedINS_21EncryptionAlgorithmPBENS_6StatusEEEE4callIZNS_10RowsetMeta24set_encryption_algorithmES3_EUlvE_EES5_T_
_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v212ColumnReader22set_dict_encoding_typeENS5_16DictEncodingTypeEEUlvE_EES1_T_
Line
Count
Source
75
200
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
200
        if (has_called()) {
78
0
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
0
            return _status;
82
0
        }
83
200
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
200
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
200
        try {
92
200
            _status = fn();
93
200
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
200
        _has_called.store(true, std::memory_order_release);
102
200
        return _status;
103
200
    }
unity_24_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v225VariantExternalMetaReader13load_all_onceEPNS_14SubcolumnsTreeINS4_13SubcolumnMetaELb1EEEPNS4_17VariantStatisticsEPNS_20OlapReaderStatisticsEPKNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
601
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
601
        if (has_called()) {
78
276
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
276
            return _status;
82
276
        }
83
325
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
325
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
325
        try {
92
325
            _status = fn();
93
325
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
325
        _has_called.store(true, std::memory_order_release);
102
325
        return _status;
103
325
    }
unity_22_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v27Segment21_load_pk_bloom_filterEPNS_20OlapReaderStatisticsEPKNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
497
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
497
        if (has_called()) {
78
378
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
378
            return _status;
82
378
        }
83
119
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
119
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
119
        try {
92
119
            _status = fn();
93
119
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
119
        _has_called.store(true, std::memory_order_release);
102
119
        return _status;
103
119
    }
unity_22_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v27Segment10load_indexEPNS_20OlapReaderStatisticsEPKNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
13.0k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
13.0k
        if (has_called()) {
78
1.29k
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
1.29k
            return _status;
82
1.29k
        }
83
11.7k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
11.7k
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
11.7k
        try {
92
11.7k
            _status = fn();
93
11.7k
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
11.7k
        _has_called.store(true, std::memory_order_release);
102
11.7k
        return _status;
103
11.7k
    }
unity_22_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v27Segment24_create_column_meta_onceEPNS_20OlapReaderStatisticsEPKNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
203k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
203k
        if (has_called()) {
78
190k
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
190k
            return _status;
82
190k
        }
83
13.1k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
13.1k
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
13.1k
        try {
92
13.1k
            _status = fn();
93
13.1k
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
13.1k
        _has_called.store(true, std::memory_order_release);
102
13.1k
        return _status;
103
13.1k
    }
unity_22_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v27Segment18new_index_iteratorERKNS_12TabletColumnEPKNS_11TabletIndexERKNS_18StorageReadOptionsEPSt10unique_ptrINS4_13IndexIteratorESt14default_deleteISG_EEE3$_0EES1_T_
Line
Count
Source
75
2.85k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
2.85k
        if (has_called()) {
78
1.95k
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
1.95k
            return _status;
82
1.95k
        }
83
904
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
904
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
904
        try {
92
904
            _status = fn();
93
904
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
904
        _has_called.store(true, std::memory_order_release);
102
904
        return _status;
103
904
    }
unity_20_cxx.cxx:_ZN5doris13DorisCallOnceIN2tl8expectedINS_21EncryptionAlgorithmPBENS_6StatusEEEE4callIZNS_10RowsetMeta2fsEvE3$_0EES5_T_
Line
Count
Source
75
8.24k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
8.24k
        if (has_called()) {
78
7.84k
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
7.84k
            return _status;
82
7.84k
        }
83
402
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
402
        if (has_called()) {
86
2
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
2
            return _status;
90
2
        }
91
400
        try {
92
400
            _status = fn();
93
400
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
400
        _has_called.store(true, std::memory_order_release);
102
400
        return _status;
103
400
    }
unity_19_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10BetaRowset20get_segment_num_rowsEPSt6vectorIjSaIjEEbPNS_20OlapReaderStatisticsEPKNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
8.14k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
8.14k
        if (has_called()) {
78
6.51k
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
6.51k
            return _status;
82
6.51k
        }
83
1.63k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
1.63k
        if (has_called()) {
86
176
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
176
            return _status;
90
176
        }
91
1.45k
        try {
92
1.45k
            _status = fn();
93
1.45k
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
1.45k
        _has_called.store(true, std::memory_order_release);
102
1.45k
        return _status;
103
1.45k
    }
unity_19_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_16BetaRowsetReader19_init_iterator_onceEvE3$_0EES1_T_
Line
Count
Source
75
33.9k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
33.9k
        if (has_called()) {
78
9.06k
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
9.06k
            return _status;
82
9.06k
        }
83
24.9k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
24.9k
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
24.9k
        try {
92
24.9k
            _status = fn();
93
24.9k
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
24.8k
        _has_called.store(true, std::memory_order_release);
102
24.8k
        return _status;
103
24.9k
    }
unity_10_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v218OrdinalIndexReader4loadEbbPNS_20OlapReaderStatisticsEPKNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
20.1k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
20.1k
        if (has_called()) {
78
1.23k
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
1.23k
            return _status;
82
1.23k
        }
83
18.9k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
18.9k
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
18.9k
        try {
92
18.9k
            _status = fn();
93
18.9k
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
18.9k
        _has_called.store(true, std::memory_order_release);
102
18.9k
        return _status;
103
18.9k
    }
unity_1_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v222BloomFilterIndexReader4loadEbbPNS_20OlapReaderStatisticsEPKNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
379
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
379
        if (has_called()) {
78
0
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
0
            return _status;
82
0
        }
83
379
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
379
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
379
        try {
92
379
            _status = fn();
93
379
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
379
        _has_called.store(true, std::memory_order_release);
102
379
        return _status;
103
379
    }
zone_map_index.cpp:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v218ZoneMapIndexReader4loadEbbPNS_20OlapReaderStatisticsEPKNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
549
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
549
        if (has_called()) {
78
0
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
0
            return _status;
82
0
        }
83
549
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
549
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
549
        try {
92
549
            _status = fn();
93
549
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
549
        _has_called.store(true, std::memory_order_release);
102
549
        return _status;
103
549
    }
tablet.cpp:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_6Tablet4initEvE3$_0EES1_T_
Line
Count
Source
75
281k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
281k
        if (has_called()) {
78
136
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
136
            return _status;
82
136
        }
83
281k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
281k
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
281k
        try {
92
281k
            _status = fn();
93
281k
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
281k
        _has_called.store(true, std::memory_order_release);
102
281k
        return _status;
103
281k
    }
unity_1_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_11LoadPathMgr12allocate_dirERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESC_PSA_lE3$_0EES1_T_
Line
Count
Source
75
2
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
2
        if (has_called()) {
78
1
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
1
            return _status;
82
1
        }
83
1
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
1
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
1
        try {
92
1
            _status = fn();
93
1
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
1
        _has_called.store(true, std::memory_order_release);
102
1
        return _status;
103
1
    }
unity_0_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v214AnnIndexReader10load_indexEPNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
20
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
20
        if (has_called()) {
78
0
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
0
            return _status;
82
0
        }
83
20
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
20
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
20
        try {
92
20
            _status = fn();
93
20
        } catch (...) {
94
            // Save the exception for next call.
95
0
            _eptr = std::current_exception();
96
0
            _has_called.store(true, std::memory_order_release);
97
0
            std::rethrow_exception(_eptr);
98
0
        }
99
        // This memory order make sure both status and eptr is set
100
        // and will be seen in another thread.
101
20
        _has_called.store(true, std::memory_order_release);
102
20
        return _status;
103
20
    }
104
105
    // Has to pay attention to memory order
106
    // see https://en.cppreference.com/w/cpp/atomic/memory_order
107
    // Return whether `call` has been invoked or not.
108
30.8M
    bool has_called() const {
109
        // std::memory_order_acquire here and std::memory_order_release in
110
        // init(), taken together, mean that threads can safely synchronize on
111
        // _has_called.
112
30.8M
        return _has_called.load(std::memory_order_acquire);
113
30.8M
    }
_ZNK5doris13DorisCallOnceIN2tl8expectedINS_21EncryptionAlgorithmPBENS_6StatusEEEE10has_calledEv
Line
Count
Source
108
8.64k
    bool has_called() const {
109
        // std::memory_order_acquire here and std::memory_order_release in
110
        // init(), taken together, mean that threads can safely synchronize on
111
        // _has_called.
112
8.64k
        return _has_called.load(std::memory_order_acquire);
113
8.64k
    }
_ZNK5doris13DorisCallOnceINS_6StatusEE10has_calledEv
Line
Count
Source
108
30.8M
    bool has_called() const {
109
        // std::memory_order_acquire here and std::memory_order_release in
110
        // init(), taken together, mean that threads can safely synchronize on
111
        // _has_called.
112
30.8M
        return _has_called.load(std::memory_order_acquire);
113
30.8M
    }
114
115
    // Return the stored result. The result is only meaningful when `has_called() == true`.
116
14.9M
    ReturnType stored_result() const {
117
14.9M
        if (!has_called()) {
118
            // Could not return status if the method not called.
119
0
            throw doris::Exception(doris::ErrorCode::INTERNAL_ERROR,
120
0
                                   "calling stored_result while has not been called");
121
0
        }
122
14.9M
        if (_eptr) {
123
1
            std::rethrow_exception(_eptr);
124
1
        }
125
14.9M
        return _status;
126
14.9M
    }
127
128
private:
129
    std::atomic<bool> _has_called;
130
    // std::once_flag _once_flag;
131
    std::mutex _flag_lock;
132
    std::exception_ptr _eptr;
133
    ReturnType _status;
134
};
135
136
} // namespace doris