Coverage Report

Created: 2026-10-09 14:54

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
20.8M
    DorisCallOnce() : _has_called(false) {}
_ZN5doris13DorisCallOnceIN2tl8expectedINS_21EncryptionAlgorithmPBENS_6StatusEEEEC2Ev
Line
Count
Source
54
1.11M
    DorisCallOnce() : _has_called(false) {}
_ZN5doris13DorisCallOnceINS_6StatusEEC2Ev
Line
Count
Source
54
19.7M
    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
52.4M
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
52.4M
        if (has_called()) {
78
47.9M
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
47.9M
            return _status;
82
47.9M
        }
83
4.50M
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
4.50M
        if (has_called()) {
86
10.7k
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
10.7k
            return _status;
90
10.7k
        }
91
4.49M
        try {
92
4.49M
            _status = fn();
93
4.49M
        } 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
4.50M
        _has_called.store(true, std::memory_order_release);
102
4.50M
        return _status;
103
4.49M
    }
_ZN5doris13DorisCallOnceIN2tl8expectedINS_21EncryptionAlgorithmPBENS_6StatusEEEE4callIZNS_10RowsetMeta24set_encryption_algorithmES3_EUlvE_EES5_T_
Line
Count
Source
75
177k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
177k
        if (has_called()) {
78
22.9k
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
22.9k
            return _status;
82
22.9k
        }
83
154k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
154k
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
154k
        try {
92
154k
            _status = fn();
93
154k
        } 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
154k
        _has_called.store(true, std::memory_order_release);
102
154k
        return _status;
103
154k
    }
_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v212ColumnReader22set_dict_encoding_typeENS5_16DictEncodingTypeEEUlvE_EES1_T_
Line
Count
Source
75
7.78k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
7.78k
        if (has_called()) {
78
319
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
319
            return _status;
82
319
        }
83
7.47k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
7.47k
        if (has_called()) {
86
32
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
32
            return _status;
90
32
        }
91
7.43k
        try {
92
7.43k
            _status = fn();
93
7.43k
        } 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
7.50k
        _has_called.store(true, std::memory_order_release);
102
7.50k
        return _status;
103
7.43k
    }
unity_25_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v225VariantExternalMetaReader13load_all_onceEPNS_14SubcolumnsTreeINS4_13SubcolumnMetaELb1EEEPNS4_17VariantStatisticsEPNS_20OlapReaderStatisticsEPKNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
13.5k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
13.5k
        if (has_called()) {
78
11.5k
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
11.5k
            return _status;
82
11.5k
        }
83
2.05k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
2.05k
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
2.05k
        try {
92
2.05k
            _status = fn();
93
2.05k
        } 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
2.06k
        _has_called.store(true, std::memory_order_release);
102
2.06k
        return _status;
103
2.05k
    }
unity_23_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v27Segment21_load_pk_bloom_filterEPNS_20OlapReaderStatisticsEPKNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
3.94M
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
3.94M
        if (has_called()) {
78
3.90M
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
3.90M
            return _status;
82
3.90M
        }
83
41.3k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
41.3k
        if (has_called()) {
86
96
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
96
            return _status;
90
96
        }
91
41.3k
        try {
92
41.3k
            _status = fn();
93
41.3k
        } 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
40.0k
        _has_called.store(true, std::memory_order_release);
102
40.0k
        return _status;
103
41.3k
    }
unity_23_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v27Segment10load_indexEPNS_20OlapReaderStatisticsEPKNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
5.31M
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
5.31M
        if (has_called()) {
78
5.21M
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
5.21M
            return _status;
82
5.21M
        }
83
101k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
101k
        if (has_called()) {
86
1.88k
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
1.88k
            return _status;
90
1.88k
        }
91
99.5k
        try {
92
99.5k
            _status = fn();
93
99.5k
        } 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
104k
        _has_called.store(true, std::memory_order_release);
102
104k
        return _status;
103
99.5k
    }
unity_23_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v27Segment24_create_column_meta_onceEPNS_20OlapReaderStatisticsEPKNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
37.3M
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
37.3M
        if (has_called()) {
78
37.2M
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
37.2M
            return _status;
82
37.2M
        }
83
126k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
126k
        if (has_called()) {
86
5.54k
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
5.54k
            return _status;
90
5.54k
        }
91
120k
        try {
92
120k
            _status = fn();
93
120k
        } 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
128k
        _has_called.store(true, std::memory_order_release);
102
128k
        return _status;
103
120k
    }
unity_23_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v27Segment18new_index_iteratorERKNS_12TabletColumnEPKNS_11TabletIndexERKNS_18StorageReadOptionsEPSt10unique_ptrINS4_13IndexIteratorESt14default_deleteISG_EEE3$_0EES1_T_
Line
Count
Source
75
86.2k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
86.2k
        if (has_called()) {
78
80.5k
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
80.5k
            return _status;
82
80.5k
        }
83
5.76k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
5.76k
        if (has_called()) {
86
7
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
7
            return _status;
90
7
        }
91
5.75k
        try {
92
5.75k
            _status = fn();
93
5.75k
        } 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
5.78k
        _has_called.store(true, std::memory_order_release);
102
5.78k
        return _status;
103
5.75k
    }
unity_20_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_16BetaRowsetReader19_init_iterator_onceEvE3$_0EES1_T_
Line
Count
Source
75
2.95M
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
2.95M
        if (has_called()) {
78
301k
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
301k
            return _status;
82
301k
        }
83
2.65M
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
2.65M
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
2.65M
        try {
92
2.65M
            _status = fn();
93
2.65M
        } 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
2.64M
        _has_called.store(true, std::memory_order_release);
102
2.64M
        return _status;
103
2.65M
    }
unity_20_cxx.cxx:_ZN5doris13DorisCallOnceIN2tl8expectedINS_21EncryptionAlgorithmPBENS_6StatusEEEE4callIZNS_10RowsetMeta2fsEvE3$_0EES5_T_
Line
Count
Source
75
268k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
268k
        if (has_called()) {
78
208k
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
208k
            return _status;
82
208k
        }
83
59.5k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
59.5k
        if (has_called()) {
86
29
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
29
            return _status;
90
29
        }
91
59.5k
        try {
92
59.5k
            _status = fn();
93
59.5k
        } 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
59.1k
        _has_called.store(true, std::memory_order_release);
102
59.1k
        return _status;
103
59.5k
    }
unity_11_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v218OrdinalIndexReader4loadEbbPNS_20OlapReaderStatisticsEPKNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
1.89M
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
1.89M
        if (has_called()) {
78
908k
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
908k
            return _status;
82
908k
        }
83
989k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
989k
        if (has_called()) {
86
1.20k
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
1.20k
            return _status;
90
1.20k
        }
91
987k
        try {
92
987k
            _status = fn();
93
987k
        } 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
989k
        _has_called.store(true, std::memory_order_release);
102
989k
        return _status;
103
987k
    }
unity_1_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v222BloomFilterIndexReader4loadEbbPNS_20OlapReaderStatisticsEPKNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
40.5k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
40.5k
        if (has_called()) {
78
123
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
123
            return _status;
82
123
        }
83
40.3k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
40.3k
        if (has_called()) {
86
3
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
3
            return _status;
90
3
        }
91
40.3k
        try {
92
40.3k
            _status = fn();
93
40.3k
        } 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
40.7k
        _has_called.store(true, std::memory_order_release);
102
40.7k
        return _status;
103
40.3k
    }
zone_map_index.cpp:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v218ZoneMapIndexReader4loadEbbPNS_20OlapReaderStatisticsEPKNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
74.9k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
74.9k
        if (has_called()) {
78
44.2k
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
44.2k
            return _status;
82
44.2k
        }
83
30.7k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
30.7k
        if (has_called()) {
86
2.00k
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
2.00k
            return _status;
90
2.00k
        }
91
28.7k
        try {
92
28.7k
            _status = fn();
93
28.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
29.0k
        _has_called.store(true, std::memory_order_release);
102
29.0k
        return _status;
103
28.7k
    }
tablet.cpp:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_6Tablet4initEvE3$_0EES1_T_
Line
Count
Source
75
294k
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
294k
        if (has_called()) {
78
136
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
136
            return _status;
82
136
        }
83
294k
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
294k
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
294k
        try {
92
294k
            _status = fn();
93
294k
        } 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
294k
        _has_called.store(true, std::memory_order_release);
102
294k
        return _status;
103
294k
    }
unity_1_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_11LoadPathMgr12allocate_dirERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESC_PSA_lE3$_0EES1_T_
Line
Count
Source
75
21
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
21
        if (has_called()) {
78
19
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
19
            return _status;
82
19
        }
83
2
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
2
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
2
        try {
92
2
            _status = fn();
93
2
        } 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
2
        _has_called.store(true, std::memory_order_release);
102
2
        return _status;
103
2
    }
unity_0_cxx.cxx:_ZN5doris13DorisCallOnceINS_6StatusEE4callIZNS_10segment_v214AnnIndexReader10load_indexEPNS_2io9IOContextEE3$_0EES1_T_
Line
Count
Source
75
103
    ReturnType call(Fn fn) {
76
        // Avoid lock to improve performance
77
103
        if (has_called()) {
78
38
            if (_eptr) {
79
0
                std::rethrow_exception(_eptr);
80
0
            }
81
38
            return _status;
82
38
        }
83
65
        std::lock_guard l(_flag_lock);
84
        // should check again because maybe another thread call successfully.
85
65
        if (has_called()) {
86
0
            if (_eptr) {
87
0
                std::rethrow_exception(_eptr);
88
0
            }
89
0
            return _status;
90
0
        }
91
65
        try {
92
65
            _status = fn();
93
65
        } 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
65
        _has_called.store(true, std::memory_order_release);
102
65
        return _status;
103
65
    }
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
105M
    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
105M
        return _has_called.load(std::memory_order_acquire);
113
105M
    }
_ZNK5doris13DorisCallOnceIN2tl8expectedINS_21EncryptionAlgorithmPBENS_6StatusEEEE10has_calledEv
Line
Count
Source
108
659k
    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
659k
        return _has_called.load(std::memory_order_acquire);
113
659k
    }
_ZNK5doris13DorisCallOnceINS_6StatusEE10has_calledEv
Line
Count
Source
108
105M
    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
105M
        return _has_called.load(std::memory_order_acquire);
113
105M
    }
114
115
    // Return the stored result. The result is only meaningful when `has_called() == true`.
116
23.4M
    ReturnType stored_result() const {
117
23.4M
        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
23.4M
        if (_eptr) {
123
1
            std::rethrow_exception(_eptr);
124
1
        }
125
23.4M
        return _status;
126
23.4M
    }
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