Skip to content

Commit

Permalink
fix: wait for extended objects before invalidating reference to extender
Browse files Browse the repository at this point in the history
  • Loading branch information
zetanumbers committed May 28, 2024
1 parent 59d9a77 commit 6691e0c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ where
scope: PhantomData,
env: PhantomData,
};
let guard = ReferenceGuard {
extender: &extender,
};
scope(&extender);
drop(guard);
}

pub struct Extender<'scope, 'env> {
Expand Down Expand Up @@ -169,7 +173,6 @@ impl<'scope, 'env> Extender<'scope, 'env> {
// TODO: Add futures
}

/// Waits for true on drop
struct ReferenceCounter<'a> {
counter: &'a RwLock<()>,
}
Expand All @@ -186,10 +189,15 @@ impl<'a> ReferenceCounter<'a> {
}
}

impl Drop for ReferenceCounter<'_> {
/// Waits for true on drop
struct ReferenceGuard<'scope, 'env> {
extender: &'scope Extender<'scope, 'env>,
}

impl Drop for ReferenceGuard<'_, '_> {
fn drop(&mut self) {
// faster to not unlock and just drop
mem::forget(self.counter.write());
mem::forget(self.extender.rc.counter.write());
}
}

Expand Down

0 comments on commit 6691e0c

Please sign in to comment.