Module: Rex::Ref

Included in:
Msf::Plugin, 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

Instance Method Details

#cleanupObject

Called to clean up resources once the ref count drops to zero.


54
55
# File 'lib/rex/sync/ref.rb', line 54

def cleanup
end

#derefObject

Decrements the total number of references. If the reference count reaches zero, true is returned. Otherwise, false is returned.


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rex/sync/ref.rb', line 39

def deref
  @_references_mutex.synchronize {
    if ((@_references -= 1) == 0)
      cleanup

      true
    else
      false
    end
  }
end

#refObject

Increments the total number of references.


27
28
29
30
31
32
33
# File 'lib/rex/sync/ref.rb', line 27

def ref
  @_references_mutex.synchronize {
    @_references += 1
  }

  self
end

#refinitObject

Initializes the reference count to one.


17
18
19
20
21
22
# File 'lib/rex/sync/ref.rb', line 17

def refinit
  @_references       = 1
  @_references_mutex = Mutex.new

  self
end