gpui: Fix race condition when upgrading a weak reference (#30952)
Release Notes: - N/A
This commit is contained in:
parent
97c01c6720
commit
c4dbaa91f0
3 changed files with 28 additions and 13 deletions
|
@ -52,6 +52,7 @@ use uuid::Uuid;
|
|||
|
||||
mod prompts;
|
||||
|
||||
use crate::util::atomic_incr_if_not_zero;
|
||||
pub use prompts::*;
|
||||
|
||||
pub(crate) const DEFAULT_WINDOW_SIZE: Size<Pixels> = size(px(1024.), px(700.));
|
||||
|
@ -263,15 +264,13 @@ impl FocusHandle {
|
|||
pub(crate) fn for_id(id: FocusId, handles: &Arc<FocusMap>) -> Option<Self> {
|
||||
let lock = handles.read();
|
||||
let ref_count = lock.get(id)?;
|
||||
if ref_count.load(SeqCst) == 0 {
|
||||
None
|
||||
} else {
|
||||
ref_count.fetch_add(1, SeqCst);
|
||||
Some(Self {
|
||||
id,
|
||||
handles: handles.clone(),
|
||||
})
|
||||
if atomic_incr_if_not_zero(ref_count) == 0 {
|
||||
return None;
|
||||
}
|
||||
Some(Self {
|
||||
id,
|
||||
handles: handles.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Converts this focus handle into a weak variant, which does not prevent it from being released.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue