File tree 1 file changed +16
-8
lines changed
opentelemetry-sdk/src/metrics/internal
1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -69,14 +69,22 @@ impl<T: Number<T>> ValueMap<T> {
69
69
}
70
70
71
71
fn try_increment ( & self ) -> bool {
72
- let current = self . total_unique_entries . load ( Ordering :: Acquire ) ;
73
- if is_under_cardinality_limit ( current) {
74
- // Attempt to increment atomically
75
- self . total_unique_entries
76
- . compare_exchange ( current, current + 1 , Ordering :: AcqRel , Ordering :: Acquire )
77
- . is_ok ( )
78
- } else {
79
- false // Limit reached, do not increment
72
+ loop {
73
+ let current = self . total_unique_entries . load ( Ordering :: Acquire ) ;
74
+ if is_under_cardinality_limit ( current) {
75
+ // Attempt to increment atomically
76
+ match self . total_unique_entries . compare_exchange (
77
+ current,
78
+ current + 1 ,
79
+ Ordering :: AcqRel ,
80
+ Ordering :: Acquire ,
81
+ ) {
82
+ Ok ( _) => return true , // Increment successful
83
+ Err ( _) => continue , // Failed to increment due to concurrent modification, retry
84
+ }
85
+ } else {
86
+ return false ; // Limit reached, do not increment
87
+ }
80
88
}
81
89
}
82
90
}
You can’t perform that action at this time.
0 commit comments