Package icyllis.arc3d.core

# Class RefCnt

java.lang.Object
icyllis.arc3d.core.RefCnt

All Implemented Interfaces:
  `RefCounted`

Direct Known Subclasses:
  `ArcData`, `BlendShader`, `ComposeColorFilter`, `Context`, `CpuBuffer`, `Device`, `Image`, `ImageShader`, `ImageViewProxy`, `LocalMatrixShader`, `ManagedResource`, `Pixels`, `ReleaseCallback`, `RenderTask`, `Surface`, `SurfaceProxy`, `Task`, `UniformDataManager`

public abstract class RefCnt extends Object implements RefCounted
Base class for objects that may be shared by multiple objects. When an existing owner wants to share a reference, it calls `ref()`. When an owner wants to release its reference, it calls `unref()`. When the shared object's reference count goes to zero as the result of an `unref()` call, its `deallocate()` is called. It is an error for the destructor to be called explicitly (or calling `deallocate()`) if `getRefCnt()` > 1.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RefCnt()`
  Default constructor, initializing the reference count to 1.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <T extends RefCounted>
  T`
  `create(T that)`
  `static <T extends RefCounted>
  T`
  `create(T sp, T that)`
  `protected abstract void`
  `deallocate()`
  Override this method to invoke de-allocation of the underlying resource.
  `final int`
  `getRefCnt()`
  Debug only.
  `final int`
  `getRefCntAcquire()`
  Returns the reference count, which has memory ordering effects compatible with `memory_order_acquire`.
  `final int`
  `getRefCntVolatile()`
  Returns the reference count, which has memory ordering effects compatible with `memory_order_seq_cst`.
  `static <T extends RefCounted>
  T`
  `move(T sp)`
  `static <T extends RefCounted>
  T`
  `move(T sp, T that)`
  `final void`
  `ref()`
  Increases the reference count by 1 on the client.
  `final boolean`
  `unique()`
  May return true if the caller is the only owner.
  `final void`
  `unref()`
  Decreases the reference count by 1 on the client.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### RefCnt

    public RefCnt()
    Default constructor, initializing the reference count to 1.

- ## Method Details

  - ### move

    @SharedPtr public static <T extends RefCounted> T move(@SharedPtr T sp)

  - ### move

    @SharedPtr public static <T extends RefCounted> T move(@SharedPtr T sp, @SharedPtr T that)

  - ### create

    @SharedPtr public static <T extends RefCounted> T create(T that)

  - ### create

    @SharedPtr public static <T extends RefCounted> T create(@SharedPtr T sp, T that)

  - ### unique

    public final boolean unique()
    May return true if the caller is the only owner. Ensures that all previous owner's actions are complete.
    Returns:
      true if this object is uniquely referenced by the program

  - ### ref

    public final void ref()
    Increases the reference count by 1 on the client. Must be balanced by a call to `unref()`. It's an error to call this method if the reference count has already reached zero.
    Specified by:
      `ref` in interface `RefCounted`

  - ### unref

    public final void unref()
    Decreases the reference count by 1 on the client. If the reference count is 1 before the decrement, then `deallocate()` is called. It's an error to call this method if the reference count has already reached zero.
    Specified by:
      `unref` in interface `RefCounted`

  - ### getRefCnt

    public final int getRefCnt()
    Debug only. Returns the reference count, accessed in program order, but with no assurance of memory ordering effects with respect to other threads.
    Returns:
      the reference count

  - ### getRefCntAcquire

    public final int getRefCntAcquire()
    Returns the reference count, which has memory ordering effects compatible with `memory_order_acquire`.
    Returns:
      the reference count

  - ### getRefCntVolatile

    public final int getRefCntVolatile()
    Returns the reference count, which has memory ordering effects compatible with `memory_order_seq_cst`.
    Returns:
      the reference count

  - ### deallocate

    @OverrideOnly protected abstract void deallocate()
    Override this method to invoke de-allocation of the underlying resource.