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 0469fe7
Show file tree
Hide file tree
Showing 2 changed files with 31 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::AcqRel)
),
before_start: self.before_start.clone(),
after_complete: self.after_complete.clone(),
after_panic: self.after_panic.clone(),
}
}
}
14 changes: 14 additions & 0 deletions lightproc/tests/stack.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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);
}

0 comments on commit 0469fe7

Please sign in to comment.