Module: WGPU::CallbackKeepalive
- Defined in:
- lib/wgpu/native_resource.rb
Constant Summary collapse
- INITIALIZATION_MUTEX =
Mutex.new
- RETAINED_MUTEX =
Mutex.new
- RETAINED_CALLBACKS =
{}
Class Method Summary collapse
-
.count(owner) ⇒ Integer
Returns the number of callbacks retained for an owner.
-
.release(owner, token) ⇒ void
Releases a retained callback token.
-
.retain(owner, callback) ⇒ Object
Retains an FFI callback for as long as an operation needs it.
-
.transfer(from, to, token) ⇒ Boolean
Moves a retained callback token to another owner without unrooting it.
Class Method Details
.count(owner) ⇒ Integer
Returns the number of callbacks retained for an owner.
161 162 163 164 |
# File 'lib/wgpu/native_resource.rb', line 161 def count(owner) mutex, callbacks = storage_for(owner) mutex.synchronize { callbacks.length } end |
.release(owner, token) ⇒ void
This method returns an undefined value.
Releases a retained callback token.
130 131 132 133 134 135 136 |
# File 'lib/wgpu/native_resource.rb', line 130 def release(owner, token) return unless token mutex, callbacks = storage_for(owner) mutex.synchronize { callbacks.delete(token) } RETAINED_MUTEX.synchronize { RETAINED_CALLBACKS.delete(token) } end |
.retain(owner, callback) ⇒ Object
Retains an FFI callback for as long as an operation needs it.
117 118 119 120 121 122 123 |
# File 'lib/wgpu/native_resource.rb', line 117 def retain(owner, callback) mutex, callbacks = storage_for(owner) token = Object.new mutex.synchronize { callbacks[token] = callback } RETAINED_MUTEX.synchronize { RETAINED_CALLBACKS[token] = callback } token end |
.transfer(from, to, token) ⇒ Boolean
Moves a retained callback token to another owner without unrooting it.
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/wgpu/native_resource.rb', line 144 def transfer(from, to, token) return false unless token callback = RETAINED_MUTEX.synchronize { RETAINED_CALLBACKS[token] } return false unless callback from_mutex, from_callbacks = storage_for(from) to_mutex, to_callbacks = storage_for(to) from_mutex.synchronize { from_callbacks.delete(token) } to_mutex.synchronize { to_callbacks[token] = callback } true end |