@@ -14,10 +14,12 @@ enum RealHandle {
1414impl RealHandle {
1515 const USABLE_BITS: u32 = 31;
1616
17+ const THREAD_DISCRIMINANT: u32 = 1;
18+
1719 fn discriminant(self) -> u32 {
1820 match self {
1921 // can't use zero here because all zero handle is invalid
20- Self::Thread(_) => 1 ,
22+ Self::Thread(_) => Self::THREAD_DISCRIMINANT ,
2123 }
2224 }
2325
@@ -52,7 +54,7 @@ impl RealHandle {
5254
5355 fn new(discriminant: u32, data: u32) -> Option<Self> {
5456 match discriminant {
55- 1 => Some(Self::Thread(data.into())),
57+ Self::THREAD_DISCRIMINANT => Some(Self::Thread(data.into())),
5658 _ => None,
5759 }
5860 }
@@ -88,10 +90,12 @@ pub enum Handle {
8890}
8991
9092impl Handle {
93+ const CURRENT_THREAD_VALUE: i32 = -7;
94+
9195 fn to_packed(self) -> i32 {
9296 match self {
9397 Self::Null => 0,
94- Self::CurrentThread => -7 ,
98+ Self::CurrentThread => Self::CURRENT_THREAD_VALUE ,
9599 Self::Thread(thread) => RealHandle::Thread(thread).to_packed(),
96100 }
97101 }
@@ -107,7 +111,7 @@ impl Handle {
107111 fn from_packed(handle: i64) -> Option<Self> {
108112 if handle == 0 {
109113 Some(Self::Null)
110- } else if handle == -7 {
114+ } else if handle == Self::CURRENT_THREAD_VALUE as i64 {
111115 Some(Self::CurrentThread)
112116 } else if let Ok(handle) = handle.try_into() {
113117 match RealHandle::from_packed(handle)? {
0 commit comments