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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use ;
// `Brand` and `Tag` both count *down* from u32::MAX. This drastically reduces
// the chance that an expired alloc's tag will trigger a false positive: it's
// more likely to be a very low number, like 1 or 2, than a very high number.
//
// This is *not* a soundness issue: since `Alloc`s aren't safely clonable, nor
// able to be deallocated in the wrong allocator, the only way the situation
// could arise is if someone unsoundly cloned an `Alloc` and tried to
// double-drop it, which breaks the safety invariants of `Alloc::clone`.
/// A unique identifier for an [`Allocator`](crate::Allocator).
;
/*
pub struct Tag {
parent: Brand,
id: u32,
}
impl Tag {
pub fn new(brand: &Brand) -> Self {
static INC: AtomicU32 = AtomicU32::new(u32::MAX);
let id = INC.fetch_sub(1, Ordering::Relaxed);
debug_assert!(id != 0, "allocation tag counter overflowed");
Tag { parent: Brand(brand.0), id }
}
pub fn parent(&self) -> &Brand {
&self.parent
}
pub fn id(&self) -> u32 {
self.id
}
/// You probably don't want to do this.
///
/// # Safety
///
/// *Must not* be used to double-drop an [allocation](crate::Alloc).
pub(crate) unsafe fn clone(&self) -> Self {
Self {
parent: Brand(self.parent.0),
id: self.id,
}
}
}
*/