Skip to content

Commit 6203252

Browse files
committed
Add newEventLoopScheduledThread method to NettyScheduler and update thread factory in EventLoopScheduler
1 parent dd7b088 commit 6203252

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

core/src/main/java/io/netty/loom/EventLoopScheduler.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,14 @@ public EventLoopScheduler(IoEventLoopGroup parent, ThreadFactory threadFactory,
8888
}
8989

9090
private static ThreadFactory newEventLoopSchedulerFactory(SharedRef sharedRef) {
91-
var rawVTFactory = Thread.ofVirtual().attach(sharedRef).factory();
92-
return runnable -> rawVTFactory.newThread(() -> ScopedValue
91+
// in the future we could create a SchedulerAssignment object a with modifiable
92+
// SharedRef into
93+
// and share it between the thread attachment and the SchedulingContext,
94+
// enabling
95+
// work-stealing to change it for both
96+
return runnable -> NettyScheduler.newEventLoopScheduledThread(() -> ScopedValue
9397
.where(CURRENT_SCHEDULER, new SchedulingContext(Thread.currentThread().threadId(), sharedRef))
94-
.run(runnable));
98+
.run(runnable), sharedRef);
9599
}
96100

97101
int externalContinuationsCount() {

core/src/main/java/io/netty/loom/NettyScheduler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ public void onContinue(Thread.VirtualThreadTask virtualThreadTask) {
117117
jdkBuildinScheduler.onContinue(virtualThreadTask);
118118
}
119119

120+
static Thread newEventLoopScheduledThread(Runnable task, SharedRef sharedRef) {
121+
return ensureInstalled().newThread(task, sharedRef);
122+
}
123+
120124
public static boolean perCarrierPollers() {
121125
return ensureInstalled().perCarrierPollers;
122126
}

0 commit comments

Comments
 (0)