1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::ptr::NonNull;
use crate::counter::Counter;
use crate::handle::RefBox;
use crate::pointer::Pointer;
use crate::pool::PoolInner;
use crate::stack::Stack;
#[cfg(feature = "sync")]
use crate::pointer::NonNullAtomicPtr;
#[cfg(feature = "sync")]
use crossbeam_queue::ArrayQueue;
#[cfg(feature = "sync")]
use std::sync::atomic::AtomicUsize;
#[doc(hidden)]
pub trait PoolSyncType<A>: Sized {
type Counter: Counter;
type Stack: Stack<Self::ElementPointer>;
type ElementPointer: Pointer<RefBox<A, Self>>;
type PoolPointer: Pointer<PoolInner<A, Self>>;
}
#[cfg(feature = "sync")]
#[derive(Debug)]
pub struct PoolSync;
#[derive(Debug)]
pub struct PoolUnsync;
#[cfg(feature = "sync")]
impl<A> PoolSyncType<A> for PoolSync {
type Counter = AtomicUsize;
type Stack = ArrayQueue<Self::ElementPointer>;
type ElementPointer = NonNullAtomicPtr<RefBox<A, Self>>;
type PoolPointer = NonNullAtomicPtr<PoolInner<A, Self>>;
}
impl<A> PoolSyncType<A> for PoolUnsync {
type Counter = usize;
type Stack = Vec<Self::ElementPointer>;
type ElementPointer = NonNull<RefBox<A, Self>>;
type PoolPointer = NonNull<PoolInner<A, Self>>;
}