Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/fiber/execution_context.cr
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ module Fiber::ExecutionContext
Thread.current.execution_context
end

def self.current? : ExecutionContext?
Thread.current.execution_context?
end

# :nodoc:
#
# Tells the current scheduler to suspend the current fiber and resume the
Expand Down Expand Up @@ -181,6 +185,7 @@ module Fiber::ExecutionContext
#
# Enqueues a fiber to be resumed inside the execution context.
#
# May be called from any ExecutionContext (i.e. must be thread-safe).
# May be called from any ExecutionContext (i.e. must be thread-safe). May also
# be called from bare threads (outside of an ExecutionContext).
abstract def enqueue(fiber : Fiber) : Nil
end
2 changes: 1 addition & 1 deletion src/fiber/execution_context/multi_threaded.cr
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ module Fiber::ExecutionContext

# :nodoc:
def enqueue(fiber : Fiber) : Nil
if ExecutionContext.current == self
if ExecutionContext.current? == self
# local enqueue: push to local queue of current scheduler
ExecutionContext::Scheduler.current.enqueue(fiber)
else
Expand Down
2 changes: 1 addition & 1 deletion src/fiber/execution_context/single_threaded.cr
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module Fiber::ExecutionContext

# :nodoc:
def enqueue(fiber : Fiber) : Nil
if ExecutionContext.current == self
if ExecutionContext.current? == self
# local enqueue
Crystal.trace :sched, "enqueue", fiber: fiber
@runnables.push(fiber)
Expand Down