module Rex::Ref

This module provides a uniform reference counted interface for classes to use.

Public Instance Methods

cleanup() click to toggle source

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

# File lib/rex/sync/ref.rb, line 53
def cleanup
end
deref() click to toggle source

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

# File lib/rex/sync/ref.rb, line 38
def deref
  @_references_mutex.synchronize {
    if ((@_references -= 1) == 0)
      cleanup

      true
    else
      false
    end
  }
end
ref() click to toggle source

Increments the total number of references.

# File lib/rex/sync/ref.rb, line 26
def ref
  @_references_mutex.synchronize {
    @_references += 1
  }

  self
end
refinit() click to toggle source

Initializes the reference count to one.

# File lib/rex/sync/ref.rb, line 16
def refinit
  @_references       = 1
  @_references_mutex = Mutex.new

  self
end