Skip to content

Commit

Permalink
Stack copy implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vertexclique committed Oct 27, 2019
1 parent 8902488 commit e41926a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lightproc/src/proc_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
}
}
}
15 changes: 15 additions & 0 deletions lightproc/tests/stack.rs
Original file line number Diff line number Diff line change
@@ -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()();
}

0 comments on commit e41926a

Please sign in to comment.