Skip to content

Commit

Permalink
chore: better code style
Browse files Browse the repository at this point in the history
  • Loading branch information
okg-cxf committed Aug 31, 2024
1 parent e9cfc31 commit 1bef7b3
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1266,25 +1266,23 @@ public void execute(Runnable task) {
cur = this.owner;
if (isOwnerCurrentThreadAndPreemptPrevented(cur)) {
// already prevented preemption, safe to skip expensive add/done calls
executeInOwnerWithPreemptPrevention(task, false);
task.run();
return;
}
} while (!OWNER.compareAndSet(this, cur, cur.toAdd(1)));

if (cur.isCurrentThread()) {
executeInOwnerWithPreemptPrevention(task, true);
executeInOwnerWithPreemptPrevention(task);
} else {
cur.thread.execute(() -> executeInOwnerWithPreemptPrevention(task, true));
cur.thread.execute(() -> executeInOwnerWithPreemptPrevention(task));
}
}

private void executeInOwnerWithPreemptPrevention(Runnable task, boolean added) {
private void executeInOwnerWithPreemptPrevention(Runnable task) {
try {
task.run();
} finally {
if (added) {
done(1);
}
done(1);
}
}

Expand Down

0 comments on commit 1bef7b3

Please sign in to comment.