Module: Rex::Ref
- Included in:
- Service
- Defined in:
- lib/rex/sync/ref.rb
Overview
This module provides a uniform reference counted interface for classes to use.
Instance Method Summary collapse
-
#cleanup ⇒ Object
Called to clean up resources once the ref count drops to zero.
-
#deref ⇒ Object
Decrements the total number of references.
-
#ref ⇒ Object
Increments the total number of references.
-
#refinit ⇒ Object
Initializes the reference count to one.
Instance Method Details
#cleanup ⇒ Object
Called to clean up resources once the ref count drops to zero.
53 54 |
# File 'lib/rex/sync/ref.rb', line 53 def cleanup end |
#deref ⇒ Object
Decrements the total number of references. If the reference count reaches zero, true is returned. Otherwise, false is returned.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rex/sync/ref.rb', line 38 def deref @_references_mutex.synchronize { if ((@_references -= 1) == 0) cleanup true else false end } end |
#ref ⇒ Object
Increments the total number of references.
26 27 28 29 30 31 32 |
# File 'lib/rex/sync/ref.rb', line 26 def ref @_references_mutex.synchronize { @_references += 1 } self end |
#refinit ⇒ Object
Initializes the reference count to one.
16 17 18 19 20 21 |
# File 'lib/rex/sync/ref.rb', line 16 def refinit @_references = 1 @_references_mutex = Mutex.new self end |