1212
1313public class EventLoopScheduler {
1414
15- public static final class SchedulerRef {
15+ public static final class SharedRef {
1616
1717 private volatile EventLoopScheduler ref ;
1818
19- private SchedulerRef (EventLoopScheduler ref ) {
19+ private SharedRef (EventLoopScheduler ref ) {
2020 this .ref = ref ;
2121 }
2222
@@ -31,13 +31,13 @@ public EventLoopScheduler get() {
3131 * This means that if they try to unpark some virtual thread which belong to this scheduler,
3232 * they can still wakeup the carrier thread. It's more a performance defect, but won't affect correctness.
3333 */
34- public record SchedulerContext (long vThreadId , SchedulerRef scheduler ) {
34+ public record SchedulingContext (long vThreadId , SharedRef scheduler ) {
3535
3636 /**
3737 * Get the assigned scheduler for the current thread, or null if this thread is not assigned to any scheduler.
3838 */
3939 @ Override
40- public SchedulerRef scheduler () {
40+ public SharedRef scheduler () {
4141 // TODO consider returning EMPTY_SCHEDULER_REF instead of null
4242 return (Thread .currentThread ().threadId () == vThreadId ) ? scheduler : null ;
4343 }
@@ -50,8 +50,8 @@ public SchedulerRef scheduler() {
5050 private static final long RUNNING_YIELD_US = TimeUnit .MICROSECONDS .toNanos (Integer .getInteger ("io.netty.loom.running.yield.us" , 1 ));
5151 private static final long IDLE_YIELD_US = TimeUnit .MICROSECONDS .toNanos (Integer .getInteger ("io.netty.loom.idle.yield.us" , 1 ));
5252 // This is required to allow sub-pollers to run on the correct scheduler
53- private static final ScopedValue <SchedulerContext > CURRENT_SCHEDULER = ScopedValue .newInstance ();
54- private static final SchedulerContext EMPTY_SCHEDULER_CONTEXT = new SchedulerContext (-1 , null );
53+ private static final ScopedValue <SchedulingContext > CURRENT_SCHEDULER = ScopedValue .newInstance ();
54+ private static final SchedulingContext EMPTY_SCHEDULER_CONTEXT = new SchedulingContext (-1 , null );
5555 private final MpscUnboundedStream <Runnable > runQueue ;
5656 private final ManualIoEventLoop ioEventLoop ;
5757 private final Thread eventLoopThread ;
@@ -60,10 +60,10 @@ public SchedulerRef scheduler() {
6060 private volatile Runnable eventLoopContinuatioToRun ;
6161 private final ThreadFactory vThreadFactory ;
6262 private final AtomicBoolean eventLoopIsRunning ;
63- private final SchedulerRef sharedRef ;
63+ private final SharedRef sharedRef ;
6464
6565 public EventLoopScheduler (IoEventLoopGroup parent , ThreadFactory threadFactory , IoHandlerFactory ioHandlerFactory , int resumedContinuationsExpectedCount ) {
66- sharedRef = new SchedulerRef (this );
66+ sharedRef = new SharedRef (this );
6767 eventLoopIsRunning = new AtomicBoolean (false );
6868 runQueue = new MpscUnboundedStream <>(resumedContinuationsExpectedCount );
6969 carrierThread = threadFactory .newThread (this ::virtualThreadSchedulerLoop );
@@ -72,7 +72,7 @@ public EventLoopScheduler(IoEventLoopGroup parent, ThreadFactory threadFactory,
7272 NettyScheduler .assignUnstarted (rawVTFactory .newThread (
7373 () -> // this can be inherited by any thread created in the context of this virtual thread
7474 // but only the original virtual thread will have the correct scheduler context
75- ScopedValue .where (CURRENT_SCHEDULER , new SchedulerContext (Thread .currentThread ().threadId (), sharedRef )).run (runnable )
75+ ScopedValue .where (CURRENT_SCHEDULER , new SchedulingContext (Thread .currentThread ().threadId (), sharedRef )).run (runnable )
7676 ), sharedRef );
7777 eventLoopThread = vThreadFactory .newThread (() -> FastThreadLocalThread .runWithFastThreadLocal (this ::nettyEventLoop ));
7878 ioEventLoop = new ManualIoEventLoop (parent , eventLoopThread ,
@@ -240,7 +240,7 @@ public boolean execute(Thread.VirtualThreadTask task) {
240240 return true ;
241241 }
242242
243- public static SchedulerContext currentThreadSchedulerContext () {
243+ public static SchedulingContext currentThreadSchedulerContext () {
244244 return CURRENT_SCHEDULER .orElse (EMPTY_SCHEDULER_CONTEXT );
245245 }
246246}
0 commit comments