Split out _runWorkItems

This commit is contained in:
Tony Garnock-Jones 2023-10-28 19:07:38 +02:00
parent d91bb6dc02
commit 882b47602d
1 changed files with 15 additions and 15 deletions

View File

@ -198,24 +198,24 @@ public class Actor {
}
}
synchronized void _runWorkItems() {
long batch = workItemCount.get();
while (batch > 0) {
for (int count = 0; count < batch; count++) {
WorkItem i = null;
while (i == null) i = head.get();
head = i;
this._perform(i);
i.clear();
}
batch = workItemCount.addAndGet(-batch);
}
}
public void execute(WorkItem item) {
tail.getAndSet(item).set(item);
if (workItemCount.getAndIncrement() == 0) {
_executor.execute(() -> {
synchronized (this) {
long batch = workItemCount.get();
while (batch > 0) {
for (int count = 0; count < batch; count++) {
WorkItem i = null;
while (i == null) i = head.get();
head = i;
this._perform(i);
i.clear();
}
batch = workItemCount.addAndGet(-batch);
}
}
});
_executor.execute(this::_runWorkItems);
}
}