Skip to content

Commit

Permalink
fixed performance issue in job system
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Oct 9, 2024
1 parent 279692b commit 48eaa5c
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/core/job_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,38 @@ struct WorkQueue {
{}

LUMIX_FORCE_INLINE void push(const Work& obj) {
Lumix::MutexGuard guard(mutex);
if (write - read >= lengthOf(objects)) {
// ring buffer full, push to fallback
fallback.push(obj);
semaphore.signal();
return;
{
Lumix::MutexGuard guard(mutex);
if (write - read >= lengthOf(objects)) {
// ring buffer full, push to fallback
fallback.push(obj);
semaphore.signal();
return;
}

objects[write % lengthOf(objects)] = obj;
++write;
}

objects[write % lengthOf(objects)] = obj;
++write;
semaphore.signal();
}

LUMIX_FORCE_INLINE bool pop(Work& obj) {
Lumix::MutexGuard guard(mutex);
if (read == write) {
// ring buffer empty, check fallback lifo
if (fallback.empty()) return false;

obj = fallback.back();
fallback.pop();
semaphore.wait(0);
return true;
}
{
Lumix::MutexGuard guard(mutex);
if (read == write) {
// ring buffer empty, check fallback lifo
if (fallback.empty()) return false;

obj = fallback.back();
fallback.pop();
semaphore.wait(0);
return true;
}

// pop from ring buffer
obj = objects[read % lengthOf(objects)];
++read;
// pop from ring buffer
obj = objects[read % lengthOf(objects)];
++read;
}
semaphore.wait(0);
return true;
}
Expand Down

0 comments on commit 48eaa5c

Please sign in to comment.