Skip to content

Commit a23e3d9

Browse files
author
KDr2
committed
remove some obsolete code
1 parent 062fe98 commit a23e3d9

File tree

1 file changed

+6
-27
lines changed

1 file changed

+6
-27
lines changed

src/ctask.jl

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ function n_copies(t::Task)
4242
end
4343

4444
function enable_stack_copying(t::Task)
45-
state = t.state
46-
if state !== :runnable && state !== :done
45+
if istaskfailed(t)
4746
error("only runnable or finished tasks' stack can be copied.")
4847
end
4948
return ccall((:jl_enable_stack_copying, libtask_julia), Any, (Any,), t)::Task
@@ -94,8 +93,7 @@ end
9493

9594
function Base.copy(ctask::CTask)
9695
task = ctask.task
97-
state = task.state
98-
if state !== :runnable && state !== :done
96+
if istaskfailed(task)
9997
error("only runnable or finished tasks can be copied.")
10098
end
10199

@@ -108,13 +106,6 @@ function Base.copy(ctask::CTask)
108106
newtask.code = task.code
109107
setstate!(newtask, getstate(task))
110108
newtask.result = task.result
111-
@static if VERSION < v"1.1"
112-
newtask.parent = task.parent
113-
end
114-
115-
if isdefined(task, :last)
116-
newtask.last = nothing
117-
end
118109

119110
return CTask(newtask)
120111
end
@@ -145,13 +136,9 @@ function produce(v)
145136
end
146137

147138
# Internal check to make sure that it is possible to switch to the consumer.
148-
@assert task.state in (:runnable, :queued)
139+
@assert !istaskdone(task) && !istaskfailed(task)
149140

150-
@static if VERSION < v"1.1.9999"
151-
task.state === :queued && yield()
152-
else
153-
task.queue !== nothing && yield()
154-
end
141+
task.queue !== nothing && yield()
155142

156143
if empty
157144
# Switch to the consumer.
@@ -209,7 +196,7 @@ function consume(ctask::CTask, values...)
209196
push!(producer.storage[:consumers].waitq, ct)
210197
end
211198

212-
if producer.state === :runnable
199+
if !istaskdone(producer) && !istaskfailed(producer)
213200
# Switch to the producer.
214201
schedule(producer)
215202
yield()
@@ -220,7 +207,7 @@ function consume(ctask::CTask, values...)
220207
end
221208

222209
# If the task failed, throw an exception.
223-
_istaskfailed(producer) && throw(CTaskException(producer))
210+
istaskfailed(producer) && throw(CTaskException(producer))
224211

225212
# If the task is done return the result.
226213
istaskdone(producer) && return producer.result
@@ -229,14 +216,6 @@ function consume(ctask::CTask, values...)
229216
wait()
230217
end
231218

232-
function _istaskfailed(task::Task)
233-
@static if VERSION < v"1.3"
234-
return task.state === :failed
235-
else
236-
return Base.istaskfailed(task)
237-
end
238-
end
239-
240219
function getstate(task::Task)
241220
@static if VERSION < v"1.6.0-DEV.618"
242221
return task.state

0 commit comments

Comments
 (0)