Module: FFI
- Defined in:
- lib/ffi-value.rb
Defined Under Namespace
Classes: AbstractMemory
Constant Summary collapse
- ValueStore =
Hash.new { |h, k| h[k.object_id] = [k, 0] }
- ValueStoreMutex =
Mutex.new
Class Method Summary collapse
Class Method Details
.dec_ref(object) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ffi-value.rb', line 48 def self.dec_ref(object) refcount = nil ValueStoreMutex.synchronize { _, refcount = ValueStore[object.object_id] refcount -= 1 if (refcount <= 0) then ValueStore.delete(object.object_id) else ValueStore[object.object_id] = [object, refcount] end } if refcount < 0 raise ArgumentError.new("Object: #{object.object_id} was not previously referenced!") end refcount end |
.inc_ref(object) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/ffi-value.rb', line 38 def self.inc_ref(object) refcount = nil ValueStoreMutex.synchronize { _, refcount = ValueStore[object.object_id] refcount += 1 ValueStore[object.object_id] = [object, refcount] } refcount end |