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
#[derive(Copy, Clone, Debug)]
#[repr(transparent)]
pub struct SyncPtr<T>(*mut T);
impl<T> SyncPtr<T> {
pub unsafe fn new(ptr: *mut T) -> Self {
Self(ptr)
}
pub unsafe fn from_const(ptr: *const T) -> Self {
Self(ptr as *mut T)
}
pub fn new_null() -> Self {
Self(std::ptr::null_mut())
}
#[inline(always)]
pub fn get(self) -> *mut T {
self.0
}
pub fn is_null(&self) -> bool {
self.0.is_null()
}
pub unsafe fn deref_unchecked(&self) -> &'static T {
&*(self.0 as *const T)
}
}
unsafe impl<T> Sync for SyncPtr<T> {}
unsafe impl<T> Send for SyncPtr<T> {}