MCPcopy Index your code
hub / github.com/RustPython/RustPython / safe_inc

Method safe_inc

crates/common/src/refcount.rs:123–143  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

121 #[inline]
122 #[must_use]
123 pub fn safe_inc(&self) -> bool {
124 let mut old = State::from_raw(self.state.load(Ordering::Relaxed));
125 loop {
126 if old.destructed() || old.strong() == 0 {
127 return false;
128 }
129 if (old.strong() as usize) >= STRONG {
130 refcount_overflow();
131 }
132 let new_state = old.add_strong(1);
133 match self.state.compare_exchange_weak(
134 old.as_raw(),
135 new_state.as_raw(),
136 Ordering::Relaxed,
137 Ordering::Relaxed,
138 ) {
139 Ok(_) => return true,
140 Err(curr) => old = State::from_raw(curr),
141 }
142 }
143 }
144
145 /// Decrement strong count. Returns true when count drops to 0.
146 #[inline]

Callers 8

addMethod · 0.80
clearMethod · 0.80
get_weak_referencesMethod · 0.80
upgradeMethod · 0.80
try_to_ownedMethod · 0.80
try_to_owned_from_ptrMethod · 0.80
get_weakrefsMethod · 0.80

Calls 6

refcount_overflowFunction · 0.85
destructedMethod · 0.80
strongMethod · 0.80
add_strongMethod · 0.80
loadMethod · 0.45
as_rawMethod · 0.45

Tested by

no test coverage detected