diff --git a/lightproc/src/proc_stack.rs b/lightproc/src/proc_stack.rs index c1e02fb9..b33deecb 100644 --- a/lightproc/src/proc_stack.rs +++ b/lightproc/src/proc_stack.rs @@ -45,6 +45,10 @@ impl ProcStack { self.after_panic = Some(Arc::new(callback)); self } + + pub fn get_pid(&self) -> usize { + self.pid.load(Ordering::Acquire) + } } impl fmt::Debug for ProcStack { @@ -54,3 +58,16 @@ impl fmt::Debug for ProcStack { .finish() } } + +impl Clone for ProcStack { + fn clone(&self) -> Self { + ProcStack { + pid: AtomicUsize::new( + self.pid.load(Ordering::Acquire) + ), + before_start: self.before_start.clone(), + after_complete: self.after_complete.clone(), + after_panic: self.after_panic.clone(), + } + } +} diff --git a/lightproc/tests/stack.rs b/lightproc/tests/stack.rs new file mode 100644 index 00000000..6cded332 --- /dev/null +++ b/lightproc/tests/stack.rs @@ -0,0 +1,15 @@ +use lightproc::proc_stack::ProcStack; + +#[test] +fn stack_copy() { + let stack = ProcStack::default() + .with_pid(12) + .with_after_panic(|| { + println!("After panic!"); + }); + + let stack2 = stack.clone(); + + assert_eq!(stack2.get_pid(), 12); + stack2.after_panic.unwrap()(); +}