Class: Hakuban::FFI::Callbacks

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCallbacks

Returns a new instance of Callbacks.



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/hakuban/ffi.rb', line 68

def initialize
	@queues = {}
	@queues_sequence = 0
	@queues_mutex = Mutex.new
	@waker = proc { |pointer|
		queue_id = pointer.address
		@queues_mutex.synchronize {
			@queues[queue_id]&.each { |queue|
				queue << :wake
			}
		}
	}
end

Instance Attribute Details

#wakerObject (readonly)

Returns the value of attribute waker.



66
67
68
# File 'lib/hakuban/ffi.rb', line 66

def waker
  @waker
end

Instance Method Details

#register_queue(queue) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/hakuban/ffi.rb', line 82

def register_queue(queue)
	@queues_mutex.synchronize {
		@queues_sequence = (@queues_sequence+1) % 2**32
		queue_id = @queues_sequence
		(@queues[queue_id] ||= Set.new) << queue
		queue_id
	}
end

#unregister_queue(queue_id) ⇒ Object



91
92
93
94
95
96
# File 'lib/hakuban/ffi.rb', line 91

def unregister_queue(queue_id)
	@queues_mutex.synchronize {
		@queues[queue_id].delete(queue_id)
		@queues.delete(queue_id)  if @queues[queue_id].empty?
	}
end