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
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends RefCounted>
Tcreate
(T that) static <T extends RefCounted>
Tcreate
(T sp, T that) protected abstract void
Override this method to invoke de-allocation of the underlying resource.final int
Debug only.final int
Returns the reference count, which has memory ordering effects compatible withmemory_order_acquire
.final int
Returns the reference count, which has memory ordering effects compatible withmemory_order_seq_cst
.static <T extends RefCounted>
Tmove
(T sp) static <T extends RefCounted>
Tmove
(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.
-
Constructor Details
-
RefCnt
public RefCnt()Default constructor, initializing the reference count to 1.
-
-
Method Details
-
move
-
move
-
create
-
create
-
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 tounref()
. It's an error to call this method if the reference count has already reached zero.- Specified by:
ref
in interfaceRefCounted
-
unref
public final void unref()Decreases the reference count by 1 on the client. If the reference count is 1 before the decrement, thendeallocate()
is called. It's an error to call this method if the reference count has already reached zero.- Specified by:
unref
in interfaceRefCounted
-
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 withmemory_order_acquire
.- Returns:
- the reference count
-
getRefCntVolatile
public final int getRefCntVolatile()Returns the reference count, which has memory ordering effects compatible withmemory_order_seq_cst
.- Returns:
- the reference count
-
deallocate
@OverrideOnly protected abstract void deallocate()Override this method to invoke de-allocation of the underlying resource.
-