Class: Hakuban::FFI::FFIFutureReturningNothing

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/hakuban/ffi.rb

Constant Summary collapse

@@callbacks =
Callbacks.new

Class Method Summary collapse

Class Method Details

.create_and_await(owner) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/hakuban/ffi.rb', line 105

def self.create_and_await(owner)
	Thread.handle_interrupt(Object => :never) {
		begin
			queue = queue_id = drop_locked = pointer = nil
			Thread.handle_interrupt(Object => :immediate) {
				queue = Queue.new
				queue_id = @@callbacks.register_queue(queue)
				drop_locked = owner.drop_lock(queue)
				return nil  if !pointer = owner.with_pointer { |pointer| yield pointer }
				loop {
					result = owner.with_pointer { Hakuban::FFI::hakuban_future_returning_nothing_poll(pointer[:pointer],@@callbacks.waker,::FFI::Pointer.new(queue_id)) }
					return result  if not result.is_Pending?
					# Currently the only future returning nothing is guaranteed to complete at first poll
					# :unreachable:
					raise Hakuban::FFIObject::PointerAlreadyDropped  if queue.pop == :dropping
					# :unreachable:
				}
			}
		ensure
			Hakuban::FFI::hakuban_future_returning_nothing_drop(pointer[:pointer])  if pointer
			owner.drop_release(queue)  if drop_locked
			@@callbacks.unregister_queue(queue_id)
		end
	}
end