diff --git a/src/praetor/mod.rs b/src/praetor/mod.rs index 02b803c..5583431 100644 --- a/src/praetor/mod.rs +++ b/src/praetor/mod.rs @@ -739,17 +739,19 @@ mod job { } } - pub fn execute(&self, scope: &super::Scope) { + pub fn execute(job: NonNull, scope: &super::Scope) { // SAFETY: self is non-null unsafe { - let (ptr, state) = self.harness_and_state.ptr_and_tag(Ordering::Relaxed); - debug_assert_eq!(state, JobState::Pending as usize); + let this = job.as_ref(); + let (ptr, state) = this.harness_and_state.ptr_and_tag(Ordering::Relaxed); + debug_assert_eq!(state, JobState::Pending as usize); let harness: unsafe fn(*const (), *const Self, scope: &super::Scope) = mem::transmute(ptr.as_ptr()); - let this = (*self.val_or_this.get()).this; - harness(this.as_ptr().cast(), (self as *const Self).cast(), scope); + let this = (*this.val_or_this.get()).this; + + harness(this.as_ptr().cast(), job.as_ptr(), scope); } } @@ -1096,9 +1098,9 @@ impl Scope { } #[inline] - fn execute(&self, job: &Job) { + fn execute(&self, job: NonNull) { self.tick(); - job.execute(self); + Job::execute(job, self); } #[cold] @@ -1125,9 +1127,7 @@ impl Scope { if ptr.as_ptr() == &*job as *const _ as *mut _ { return None; } else { - unsafe { - self.execute(ptr.as_ref()); - } + self.execute(ptr); } } @@ -1148,9 +1148,7 @@ impl Scope { break; }; - unsafe { - self.execute(job.as_ref()); - } + self.execute(job); } // while job isn't done, run other jobs. Some(job.wait()) @@ -1279,9 +1277,7 @@ fn worker(ctx: Arc, barrier: Arc) { let mut job = ctx.shared.lock().jobs.pop_first(); loop { if let Some((_, job)) = job { - unsafe { - scope.execute(job.as_ref()); - } + scope.execute(job); } let mut guard = ctx.shared.lock();