Skip to content

Commit

Permalink
Bring back enqueue front
Browse files Browse the repository at this point in the history
  • Loading branch information
mjp41 committed Nov 21, 2024
1 parent c652738 commit 7994de4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/rt/ds/wrapindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ class WrapIndex
return index;
}

size_t operator--(int)
{
auto result = index;
if (result == 0)
index = N - 1;
else
index--;
return result;
}

operator size_t() const
{
return index;
Expand Down
13 changes: 11 additions & 2 deletions src/rt/sched/mpmcq.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,17 @@ namespace verona::rt

void enqueue_front(T* node)
{
// No longer support put on the back.
enqueue_segment({node, &node->next_in_queue});
auto old_front = acquire_front();
if (old_front == nullptr)
{
// Post to back.
enqueue(node);
return;
}

// Link into the front.
node->next_in_queue.store(old_front, std::memory_order_relaxed);
front.store(node, std::memory_order_release);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/rt/sched/workstealingqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ namespace verona::rt

void enqueue_front(Work* work)
{
// TODO should this be --dequeue_index?
queues[++enqueue_index].enqueue_front(work);
queues[dequeue_index--].enqueue_front(work);
}

// Dequeue a single node from any of the queues.
Expand Down

0 comments on commit 7994de4

Please sign in to comment.