Class: Grammar::Ruby0::PipeBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/grammar/ruby0.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buf, mutex, cvar, max_size) ⇒ PipeBuffer

Returns a new instance of PipeBuffer.



415
416
417
418
419
420
421
# File 'lib/grammar/ruby0.rb', line 415

def initialize(buf, mutex, cvar, max_size)
    @buf = buf
    @tmp_buf = nil
    @mutex = mutex
    @cvar = cvar
    @max_size = max_size || -1
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



449
450
451
# File 'lib/grammar/ruby0.rb', line 449

def method_missing(meth, *args, &block)
    @tmp_buf.send(meth, *args, &block)
end

Instance Attribute Details

#max_sizeObject

Returns the value of attribute max_size.



414
415
416
# File 'lib/grammar/ruby0.rb', line 414

def max_size
  @max_size
end

Instance Method Details

#_produce(arg) ⇒ Object Also known as: <<



422
423
424
425
426
427
428
429
430
431
432
# File 'lib/grammar/ruby0.rb', line 422

def _produce(arg)
    @mutex.lock
    begin
        @buf << arg
        @cvar.signal
    ensure
        @cvar.wait(@mutex) if @buf.size==@max_size
        @mutex.unlock
    end
    self
end

#taintObject



434
435
436
437
438
439
440
# File 'lib/grammar/ruby0.rb', line 434

def taint
    @tmp_buf ||= @buf.class.new
    class << self
        remove_method(:<<)
    end
    super
end

#untaintObject



441
442
443
444
445
446
447
448
# File 'lib/grammar/ruby0.rb', line 441

def untaint
    class << self
        alias_method(:<<, :_produce)
    end
    @tmp_buf.size.times { |i| self << @tmp_buf[i] }
    @tmp_buf.slice!(0, @tmp_buf.size)
    super
end