lockfree_object_pool/
spin_lock_owned_reusable.rs
1use crate::spin_lock_object_pool::SpinLockObjectPool;
2use std::mem::ManuallyDrop;
3use std::ops::{Deref, DerefMut};
4use std::sync::Arc;
5
6pub struct SpinLockOwnedReusable<T> {
26 pool: Arc<SpinLockObjectPool<T>>,
27 data: ManuallyDrop<T>,
28}
29
30impl<T> SpinLockOwnedReusable<T> {
31 #[inline]
37 pub fn new(pool: Arc<SpinLockObjectPool<T>>, data: ManuallyDrop<T>) -> Self {
38 Self { pool, data }
39 }
40}
41
42impl<T> DerefMut for SpinLockOwnedReusable<T> {
43 #[inline]
44 fn deref_mut(&mut self) -> &mut Self::Target {
45 &mut self.data
46 }
47}
48
49impl<T> Deref for SpinLockOwnedReusable<T> {
50 type Target = T;
51
52 #[inline]
53 fn deref(&self) -> &Self::Target {
54 &self.data
55 }
56}
57
58impl<T> Drop for SpinLockOwnedReusable<T> {
59 #[inline]
60 fn drop(&mut self) {
61 let data = unsafe {
62 ManuallyDrop::take(&mut self.data)
64 };
65 self.pool.attach(data);
66 }
67}