cs431_homework/elim_stack/
elim.rs1use core::mem::ManuallyDrop;
2use core::ops::Deref;
3use core::ptr;
4use core::sync::atomic::Ordering;
5use std::thread;
6
7use crossbeam_epoch::{Guard, Owned, Shared};
8
9use super::base::{ELIM_DELAY, ElimStack, Stack, get_random_elim_index};
10
11impl<T, S: Stack<T>> Stack<T> for ElimStack<T, S> {
12 type PushReq = S::PushReq;
13
14 fn try_push(
15 &self,
16 req: Owned<Self::PushReq>,
17 guard: &Guard,
18 ) -> Result<(), Owned<Self::PushReq>> {
19 let Err(req) = self.inner.try_push(req, guard) else {
20 return Ok(());
21 };
22
23 let index = get_random_elim_index();
24 let slot_ref = unsafe { self.slots.get_unchecked(index) };
25 let slot = slot_ref.load(Ordering::Acquire, guard);
26
27 todo!()
28 }
29
30 fn try_pop(&self, guard: &Guard) -> Result<Option<T>, ()> {
31 if let Ok(result) = self.inner.try_pop(guard) {
32 return Ok(result);
33 }
34
35 let index = get_random_elim_index();
36 let slot_ref = unsafe { self.slots.get_unchecked(index) };
37 let slot = slot_ref.load(Ordering::Acquire, guard);
38
39 todo!()
40 }
41
42 fn is_empty(&self, guard: &Guard) -> bool {
43 self.inner.is_empty(guard)
44 }
45}