Package io.netty.util.internal
Class RefCnt
- java.lang.Object
-
- io.netty.util.internal.RefCnt
-
public final class RefCnt extends Object
Monomorphic reference counter implementation that always use the most efficient available atomic updater. This implementation is easier for the JIT compiler to optimize, compared to whenReferenceCountUpdateris used.
-
-
Constructor Summary
Constructors Constructor Description RefCnt()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisLiveNonVolatile(RefCnt ref)Returnstrueif and only if the given reference counter is alive.static intrefCnt(RefCnt ref)Returns the current reference count of the givenRefCntinstance with a load acquire semantic.static booleanrelease(RefCnt ref)Decreases the reference count of the givenRefCntinstance by 1.static booleanrelease(RefCnt ref, int decrement)Decreases the reference count of the givenRefCntinstance by the specified decrement.static voidresetRefCnt(RefCnt ref)Resets the reference count of the givenRefCntinstance to 1.static voidretain(RefCnt ref)Increases the reference count of the givenRefCntinstance by 1.static voidretain(RefCnt ref, int increment)Increases the reference count of the givenRefCntinstance by the specified increment.static voidsetRefCnt(RefCnt ref, int refCnt)WARNING: An unsafe operation that sets the reference count of the givenRefCntinstance directly.
-
-
-
Method Detail
-
refCnt
public static int refCnt(RefCnt ref)
Returns the current reference count of the givenRefCntinstance with a load acquire semantic.- Parameters:
ref- the target RefCnt instance- Returns:
- the reference count
-
retain
public static void retain(RefCnt ref)
Increases the reference count of the givenRefCntinstance by 1.- Parameters:
ref- the target RefCnt instance
-
retain
public static void retain(RefCnt ref, int increment)
Increases the reference count of the givenRefCntinstance by the specified increment.- Parameters:
ref- the target RefCnt instanceincrement- the amount to increase the reference count by- Throws:
IllegalArgumentException- if increment is not positive
-
release
public static boolean release(RefCnt ref)
Decreases the reference count of the givenRefCntinstance by 1.- Parameters:
ref- the target RefCnt instance- Returns:
- true if the reference count became 0 and the object should be deallocated
-
release
public static boolean release(RefCnt ref, int decrement)
Decreases the reference count of the givenRefCntinstance by the specified decrement.- Parameters:
ref- the target RefCnt instancedecrement- the amount to decrease the reference count by- Returns:
- true if the reference count became 0 and the object should be deallocated
- Throws:
IllegalArgumentException- if decrement is not positive
-
isLiveNonVolatile
public static boolean isLiveNonVolatile(RefCnt ref)
Returnstrueif and only if the given reference counter is alive. This method is useful to check if the object is alive without incurring the cost of a volatile read.- Parameters:
ref- the target RefCnt instance- Returns:
trueif alive
-
setRefCnt
public static void setRefCnt(RefCnt ref, int refCnt)
WARNING: An unsafe operation that sets the reference count of the givenRefCntinstance directly.- Parameters:
ref- the target RefCnt instancerefCnt- new reference count
-
resetRefCnt
public static void resetRefCnt(RefCnt ref)
Resets the reference count of the givenRefCntinstance to 1.Warning: This method uses release memory semantics, meaning the change may not be immediately visible to other threads. It should only be used in quiescent states where no other threads are accessing the reference count.
- Parameters:
ref- the target RefCnt instance
-
-