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?
raise Hakuban::FFIObject::PointerAlreadyDropped if queue.pop == :dropping
}
}
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
|