Skip to content

Commit

Permalink
chore refactor: use prepare to clean Fiber.source, move signal0(Fiber…
Browse files Browse the repository at this point in the history
…) to FiberCondition
  • Loading branch information
areyouok committed Dec 25, 2024
1 parent e96bdec commit e97df5a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ private void processScheduleFibers() {
if (f.source != null) {
f.source.removeWaiter(f);
f.source.prepare(f, true);
f.source = null;
}
f.cleanSchedule();
f.fiberGroup.tryMakeFiberReady(f, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ protected void prepare(Fiber waitFiber, boolean timeout) {
} else {
waitFiber.inputObj = null;
}
waitFiber.source = null;
}

public FrameCallResult join(FrameCall<Void> resumePoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public String toString() {
return "Condition:" + name + "@" + Integer.toHexString(hashCode());
}

@Override
protected void prepare(Fiber waitFiber, boolean timeout) {
waitFiber.source = null;
}

public void signal() {
Dispatcher.getCurrentFiberAndCheck(fiberGroup);
signal0(true);
Expand All @@ -43,7 +48,14 @@ public void signalLater() {

public void signal(Fiber targetFiber) {
Dispatcher.getCurrentFiberAndCheck(fiberGroup);
signal0(targetFiber);
if (fiberGroup.finished) {
return;
}
if (targetFiber.source != this) {
return;
}
removeWaiter(targetFiber);
signalFiber(targetFiber, true);
}

public void signalAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected void prepare(Fiber currentFiber, boolean timeout) {
currentFiber.inputObj = execResult;
}
}
currentFiber.source = null;
}

public T getResult() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected void prepare(Fiber fiber, boolean timeout) {
fiber.inputObj = null;
}
updateOwnerAndHeldCount(fiber);
fiber.source = null;
}

private void updateOwnerAndHeldCount(Fiber fiber) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected void prepare(Fiber fiber, boolean timeout) {
fiber.inputObj = null;
}
heldCount++;
fiber.source = null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public WaitSource(String name, FiberGroup group) {
this.name = name;
}

protected void prepare(Fiber waitFiber, boolean timeout){
}
protected abstract void prepare(Fiber waitFiber, boolean timeout);


void addWaiter(Fiber f) {
Expand Down Expand Up @@ -93,17 +92,6 @@ Fiber popHeadWaiter() {
return result;
}

void signal0(Fiber f) {
if (fiberGroup.finished) {
return;
}
if (f.source != this) {
return;
}
removeWaiter(f);
signalFiber(f, true);
}

void signal0(boolean addFirst) {
if (fiberGroup.finished) {
return;
Expand All @@ -114,12 +102,11 @@ void signal0(boolean addFirst) {
}
}

private void signalFiber(Fiber f, boolean addFirst) {
void signalFiber(Fiber f, boolean addFirst) {
if (f.scheduleTimeoutMillis > 0) {
fiberGroup.dispatcher.removeFromScheduleQueue(f);
}
prepare(f, false);
f.source = null;
f.cleanSchedule();
fiberGroup.tryMakeFiberReady(f, addFirst);
}
Expand Down

0 comments on commit e97df5a

Please sign in to comment.