Skip to content

Commit b608652

Browse files
kpamnanyKristofferC
authored andcommitted
Revert "Scheduler: Use a "scheduler" task for thread sleep (#57544)"
This reverts commit 640c4e1.
1 parent 08f6ee9 commit b608652

File tree

3 files changed

+19
-40
lines changed

3 files changed

+19
-40
lines changed

base/task.jl

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,16 +1145,6 @@ function throwto(t::Task, @nospecialize exc)
11451145
return try_yieldto(identity)
11461146
end
11471147

1148-
@inline function wait_forever()
1149-
while true
1150-
wait()
1151-
end
1152-
end
1153-
1154-
const get_sched_task = OncePerThread{Task}() do
1155-
Task(wait_forever)
1156-
end
1157-
11581148
function ensure_rescheduled(othertask::Task)
11591149
ct = current_task()
11601150
W = workqueue_for(Threads.threadid())
@@ -1191,39 +1181,25 @@ end
11911181

11921182
checktaskempty = Partr.multiq_check_empty
11931183

1184+
@noinline function poptask(W::StickyWorkqueue)
1185+
task = trypoptask(W)
1186+
if !(task isa Task)
1187+
task = ccall(:jl_task_get_next, Ref{Task}, (Any, Any, Any), trypoptask, W, checktaskempty)
1188+
end
1189+
set_next_task(task)
1190+
nothing
1191+
end
1192+
11941193
function wait()
11951194
ct = current_task()
11961195
# [task] user_time -yield-or-done-> wait_time
11971196
record_running_time!(ct)
1198-
# let GC run
11991197
GC.safepoint()
1200-
# check for libuv events
1201-
process_events()
1202-
1203-
# get the next task to run
1204-
result = nothing
1205-
have_result = false
12061198
W = workqueue_for(Threads.threadid())
1207-
task = trypoptask(W)
1208-
if !(task isa Task)
1209-
# No tasks to run; switch to the scheduler task to run the
1210-
# thread sleep logic.
1211-
sched_task = get_sched_task()
1212-
if ct !== sched_task
1213-
result = yieldto(sched_task)
1214-
have_result = true
1215-
else
1216-
task = ccall(:jl_task_get_next, Ref{Task}, (Any, Any, Any),
1217-
trypoptask, W, checktaskempty)
1218-
end
1219-
end
1220-
# We may have already switched tasks (via the scheduler task), so
1221-
# only switch if we haven't.
1222-
if !have_result
1223-
@assert task isa Task
1224-
set_next_task(task)
1225-
result = try_yieldto(ensure_rescheduled)
1226-
end
1199+
poptask(W)
1200+
result = try_yieldto(ensure_rescheduled)
1201+
process_events()
1202+
# return when we come out of the queue
12271203
return result
12281204
end
12291205

stdlib/Sockets/test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,14 @@ end
547547
fetch(r)
548548
end
549549

550-
let addr = Sockets.InetAddr(ip"192.0.2.5", 4444)
550+
let addr = Sockets.InetAddr(ip"127.0.0.1", 4444)
551+
srv = listen(addr)
551552
s = Sockets.TCPSocket()
552553
Sockets.connect!(s, addr)
553554
r = @async close(s)
554555
@test_throws Base._UVError("connect", Base.UV_ECANCELED) Sockets.wait_connected(s)
555556
fetch(r)
557+
close(srv)
556558
end
557559
end
558560

test/channels.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,15 @@ end
463463
cb = first(async.cond.waitq)
464464
@test isopen(async)
465465
ccall(:uv_async_send, Cvoid, (Ptr{Cvoid},), async)
466+
ccall(:uv_async_send, Cvoid, (Ptr{Cvoid},), async)
467+
@test isempty(Base.Workqueue)
466468
Base.process_events() # schedule event
467469
Sys.iswindows() && Base.process_events() # schedule event (windows?)
470+
@test length(Base.Workqueue) == 1
468471
ccall(:uv_async_send, Cvoid, (Ptr{Cvoid},), async)
469472
@test tc[] == 0
470473
yield() # consume event
471474
@test tc[] == 1
472-
ccall(:uv_async_send, Cvoid, (Ptr{Cvoid},), async)
473-
Base.process_events()
474475
Sys.iswindows() && Base.process_events() # schedule event (windows?)
475476
yield() # consume event
476477
@test tc[] == 2

0 commit comments

Comments
 (0)