Split out _runWorkItems
This commit is contained in:
parent
d91bb6dc02
commit
882b47602d
|
@ -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) {
|
public void execute(WorkItem item) {
|
||||||
tail.getAndSet(item).set(item);
|
tail.getAndSet(item).set(item);
|
||||||
if (workItemCount.getAndIncrement() == 0) {
|
if (workItemCount.getAndIncrement() == 0) {
|
||||||
_executor.execute(() -> {
|
_executor.execute(this::_runWorkItems);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue