Class: ConcurrentSHM::Channel::Buffered::Empty

Inherits:
ConcurrentSHM::Channel::Buffered show all
Defined in:
lib/concurrent-shm/channel.rb

Overview

A buffered channel with zero-width packets.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ConcurrentSHM::Channel

#close

Class Method Details

.new(shm, depth:, offset: 0, autosize: true) ⇒ Object

Allocates a buffered, zero-width channel.

Raises:

  • (RangeError)

    if depth is less than 1 or greater than 2<sup>32</sup>-1

See Also:



270
271
272
273
274
275
276
277
278
279
280
# File 'lib/concurrent-shm/channel.rb', line 270

def self.new(shm, depth:, offset: 0, autosize: true)
  raise RangeError, "Depth must be > 0" unless depth > 0
  dbytes = bytes_for(depth) { raise RangeError, "Depth must be less than 2^32" }

  alloc(shm, dbytes*2 + 1, offset: offset, autosize: autosize) do |body|
    @depth = depth
    @read = body[0, dbytes].as_uintptr
    @written = body[dbytes, dbytes].as_uintptr
    @closed = body[dbytes*2].as_intptr
  end
end

Instance Method Details

#recvnil

Receive a zero-width packet over the channel. Blocks if the buffer is empty.

Returns:

  • (nil)


291
292
293
# File 'lib/concurrent-shm/channel.rb', line 291

def recv
  do_recv
end

#sendnil

Send a zero-width packet over the channel. Blocks if the buffer is full.

Returns:

  • (nil)

Raises:



285
286
287
# File 'lib/concurrent-shm/channel.rb', line 285

def send
  do_send
end