Skip to content

Commit

Permalink
Small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dragostis committed Sep 23, 2024
1 parent 9c60b7a commit d0de899
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,20 +264,20 @@ impl JobQueue {
/// Any `Job` pushed onto the queue should alive at least until it gets
/// popped.
pub unsafe fn push_back<T>(&mut self, job: &Job<T>) {
let next_tail = unsafe { &*(job as *const Job<T> as *const Job) };
self.0.push_back(NonNull::from(next_tail).cast());
self.0.push_back(NonNull::from(job).cast());
}

pub fn pop_back(&mut self) {
self.0.pop_back();
}

pub fn pop_front(&mut self) -> Option<Job> {
let val = self.0.pop_front()?;
// SAFETY:
// `Job` is still alive as per contract in `push_back`
let job = unsafe { val.as_ref() };
job.fut.set(Some(Box::leak(Box::new(Future::default())).into()));
// `Job` is still alive as per contract in `push_back`.
let job = unsafe { self.0.pop_front()?.as_ref() };
job.fut
.set(Some(Box::leak(Box::new(Future::default())).into()));

Some(job.clone())
}
}
12 changes: 2 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,7 @@ impl<'s> Scope<'s> {

let time = lock.time;
if let Entry::Vacant(e) = lock.shared_jobs.entry(self.heartbeat_id()) {
// SAFETY:
// Any `Job` previously pushed onto the queue will be waited upon
// and will be alive until that point.
if let Some(job) = unsafe { self.job_queue.pop_front() } {
if let Some(job) = self.job_queue.pop_front() {
e.insert((time, job));

lock.time += 1;
Expand Down Expand Up @@ -384,12 +381,7 @@ impl<'s> Scope<'s> {
let rb = b(self);

if job.is_waiting() {
// SAFETY:
// `job` is alive until the end of this scope and there has been no
// other pop up to this point.
unsafe {
self.job_queue.pop_back();
}
self.job_queue.pop_back();

// SAFETY:
// Since the `job` was popped from the back of the queue, it cannot
Expand Down

0 comments on commit d0de899

Please sign in to comment.