Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 75fe7069c7b1^
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9540f89923e8
Choose a head ref
  • 2 commits
  • 21 files changed
  • 1 contributor

Commits on Jun 13, 2016

  1. Copy the full SHA
    75fe706 View commit details
  2. Copy the full SHA
    9540f89 View commit details
11 changes: 0 additions & 11 deletions configure
Original file line number Diff line number Diff line change
@@ -72,7 +72,6 @@ class Configure
@libc = nil
@x86_32 = false
@x86_64 = false
@fibers = false
@dtrace = false
@dtrace_const = false
@have_lchmod = false
@@ -458,7 +457,6 @@ class Configure
feature "vendor-zlib", false
feature "vendor-libsodium", true
feature "alloc-tracking", false
feature "fibers", true
feature "dtrace", false
feature "rpath", true

@@ -1198,10 +1196,6 @@ int main() { return tgetnum(""); }
@defines << "RBX_ALLOC_TRACKING"
end

if @features["fibers"].value
@fibers = true if @x86_32 or @x86_64
end

if @features["dtrace"].value and has_dtrace
@defines << "HAVE_DTRACE"
end
@@ -1583,7 +1577,6 @@ int main() { return tgetnum(""); }
:x86_64 => @x86_64,
:dtrace => @dtrace,
:dtrace_const => @dtrace_const,
:fibers => @fibers,
:debug_build => @debug_build,
:sourcedir => @sourcedir,
:stagingdir => @stagingdir,
@@ -1690,10 +1683,6 @@ int main() { return tgetnum(""); }
end
end

if @fibers
f.puts "#define RBX_FIBER_ENABLED 1"
end

f.puts "#define RBX_DTRACE_CONST #{@dtrace_const ? "const" : ""}"

write_have_defines f
104 changes: 12 additions & 92 deletions core/enumerator.rb
Original file line number Diff line number Diff line change
@@ -447,123 +447,43 @@ def zip(*lists)
end
end

if Rubinius::Fiber::ENABLED
class FiberGenerator
STACK_SIZE = 1_048_576
class FiberGenerator
STACK_SIZE = 1_048_576

attr_reader :result

def initialize(obj)
@object = obj
rewind
end

def next?
!@done
end

def next
reset unless @fiber

val = @fiber.resume

raise StopIteration, "iteration has ended" if @done

return val
end

def rewind
@fiber = nil
@done = false
end

def reset
@done = false
@fiber = Rubinius::Fiber.new stack_size: STACK_SIZE do
obj = @object
@result = obj.each do |*val|
Rubinius::Fiber.yield *val
end
@done = true
end
end
end
else
FiberGenerator = nil
end

class ThreadGenerator
attr_reader :result

def initialize(enum, obj, meth, args)
def initialize(obj)
@object = obj
@method = meth
@args = args

ObjectSpace.define_finalizer(enum, method(:kill))

rewind
end

# Used to cleanup the background thread when the enumerator
# is GC'd.
def kill(obj_id)
if @thread
@thread.kill
end
end

def next?
if @done
@thread.join if @thread
@thread = nil
return false
end

true
!@done
end

def next
reset unless @thread
reset unless @fiber

@hold_channel << nil
vals = @channel.receive
val = @fiber.resume

raise StopIteration, "iteration has ended" if @done

# return *[1] == [1], unfortunately.
return vals.size == 1 ? vals.first : vals
return val
end

def rewind
if @thread
@thread.kill
end

@fiber = nil
@done = false
@thread = nil
end

def reset
@done = false
@channel = Rubinius::Channel.new
@hold_channel = Rubinius::Channel.new

@thread = Thread.new do
@result = @object.__send__(@method, *@args) do |*vals|
@hold_channel.receive
@channel << vals
@fiber = Rubinius::Fiber.new stack_size: STACK_SIZE do
obj = @object
@result = obj.each do |*val|
Rubinius::Fiber.yield *val
end

# Hold to indicate done to avoid race conditions setting
# the ivar.
@hold_channel.receive
@done = true

# Put an extra value in the channel, so that main
# thread doesn't accidentally block if it doesn't
# detect @done in time.
@channel << nil
end
end
end
74 changes: 36 additions & 38 deletions core/fiber.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,46 @@
module Rubinius
class Fiber
attr_reader :stack_size
attr_reader :thread_name
attr_reader :fiber_id
attr_reader :source

def self.new(**kw, &block)
if block.nil?
raise ArgumentError, "Fiber.new requires a block"
end
class Fiber
attr_reader :stack_size
attr_reader :thread_name
attr_reader :fiber_id
attr_reader :source

def self.new(**kw, &block)
if block.nil?
raise ArgumentError, "Fiber.new requires a block"
end

stack_size = Rubinius::Type.try_convert kw[:stack_size], Fixnum, :to_int
stack_size = Rubinius::Type.try_convert kw[:stack_size], Fixnum, :to_int

Rubinius.invoke_primitive :fiber_new, stack_size, block, self
end
Rubinius.invoke_primitive :fiber_new, stack_size, block, self
end

def self.current
Rubinius.primitive :fiber_s_current
raise PrimitiveFailure, "Rubinius::Fiber.current failed"
end
def self.current
Rubinius.primitive :fiber_s_current
raise PrimitiveFailure, "Rubinius::Fiber.current failed"
end

def self.yield(*args)
Rubinius.primitive :fiber_s_yield
raise PrimitiveFailure, "Rubinius::Fiber.yield failed"
end
def self.yield(*args)
Rubinius.primitive :fiber_s_yield
raise PrimitiveFailure, "Rubinius::Fiber.yield failed"
end

def resume(*args)
Rubinius.primitive :fiber_resume
raise PrimitiveFailure, "Rubinius::Fiber#resume failed"
end
def resume(*args)
Rubinius.primitive :fiber_resume
raise PrimitiveFailure, "Rubinius::Fiber#resume failed"
end

def transfer(*args)
Rubinius.primitive :fiber_transfer
raise PrimitiveFailure, "Rubinius::Fiber#transfer failed"
end
def transfer(*args)
Rubinius.primitive :fiber_transfer
raise PrimitiveFailure, "Rubinius::Fiber#transfer failed"
end

def alive?
!@dead
end
def alive?
!@dead
end

def inspect
str = "#<#{self.class}:0x#{object_id.to_s(16)} thread_name=#{@thread_name} fiber_id=#{@fiber_id} status=#{alive? ? "alive" : "dead"}"
str << " source=#{@source}" if @source
str << ">"
end
def inspect
str = "#<#{self.class}:0x#{object_id.to_s(16)} thread_name=#{@thread_name} fiber_id=#{@fiber_id} status=#{alive? ? "alive" : "dead"}"
str << " source=#{@source}" if @source
str << ">"
end
end
2 changes: 0 additions & 2 deletions core/zed.rb
Original file line number Diff line number Diff line change
@@ -1062,8 +1062,6 @@ module Errno
FFI = Rubinius::FFI
end

Fiber = Rubinius::Fiber

class File < IO
# these will be necessary when we run on Windows
DOSISH = false # !!(RUBY_PLATFORM =~ /mswin/)
Loading