@@ -14,10 +14,12 @@ enum RealHandle {
14
14
impl RealHandle {
15
15
const USABLE_BITS : u32 = 31 ;
16
16
17
+ const THREAD_DISCRIMINANT : u32 = 1 ;
18
+
17
19
fn discriminant ( self ) -> u32 {
18
20
match self {
19
21
// can't use zero here because all zero handle is invalid
20
- Self :: Thread ( _) => 1 ,
22
+ Self :: Thread ( _) => Self :: THREAD_DISCRIMINANT ,
21
23
}
22
24
}
23
25
@@ -52,7 +54,7 @@ impl RealHandle {
52
54
53
55
fn new ( discriminant : u32 , data : u32 ) -> Option < Self > {
54
56
match discriminant {
55
- 1 => Some ( Self :: Thread ( data. into ( ) ) ) ,
57
+ Self :: THREAD_DISCRIMINANT => Some ( Self :: Thread ( data. into ( ) ) ) ,
56
58
_ => None ,
57
59
}
58
60
}
@@ -88,10 +90,12 @@ pub enum Handle {
88
90
}
89
91
90
92
impl Handle {
93
+ const CURRENT_THREAD_VALUE : i32 = -7 ;
94
+
91
95
fn to_packed ( self ) -> i32 {
92
96
match self {
93
97
Self :: Null => 0 ,
94
- Self :: CurrentThread => - 7 ,
98
+ Self :: CurrentThread => Self :: CURRENT_THREAD_VALUE ,
95
99
Self :: Thread ( thread) => RealHandle :: Thread ( thread) . to_packed ( ) ,
96
100
}
97
101
}
@@ -107,7 +111,7 @@ impl Handle {
107
111
fn from_packed ( handle : i64 ) -> Option < Self > {
108
112
if handle == 0 {
109
113
Some ( Self :: Null )
110
- } else if handle == - 7 {
114
+ } else if handle == Self :: CURRENT_THREAD_VALUE as i64 {
111
115
Some ( Self :: CurrentThread )
112
116
} else if let Ok ( handle) = handle. try_into ( ) {
113
117
match RealHandle :: from_packed ( handle) ? {
0 commit comments