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
#[derive(Debug, Clone)]
pub struct RcMemorySource<MS: MemorySource>(Rc<MS>);
impl<MS: MemorySource> MemorySource for RcMemorySource<MS>
{
#[inline(always)]
fn obtain(&self, non_zero_size: NonZeroUsize) -> Result<MemoryAddress, AllocErr>
{
self.0.obtain(non_zero_size)
}
#[inline(always)]
fn release(&self, non_zero_size: NonZeroUsize, current_memory: MemoryAddress)
{
self.0.release(non_zero_size, current_memory)
}
}
impl<MS: MemorySource> RcMemorySource<MS>
{
#[inline(always)]
pub fn new_thread_local<GTACSA: GlobalThreadAndCoroutineSwitchableAllocator>(global_allocator: >ACSA, underlying_memory_source: MS) -> Self
{
Self(global_allocator.callback_with_thread_local_allocator(|| Rc::new(underlying_memory_source)))
}
#[inline(always)]
pub fn new_coroutine_local<GTACSA: GlobalThreadAndCoroutineSwitchableAllocator>(global_allocator: >ACSA, underlying_memory_source: MS) -> Self
{
Self(global_allocator.callback_with_coroutine_local_allocator(|| Rc::new(underlying_memory_source)))
}
}