Class RefCnt
java.lang.Object
io.netty.util.internal.RefCnt
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 when
ReferenceCountUpdater is used.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisLiveNonVolatile(RefCnt ref) Returnstrueif and only if the given reference counter is alive.static intReturns the current reference count of the givenRefCntinstance with a load acquire semantic.static booleanDecreases the reference count of the givenRefCntinstance by 1.static booleanDecreases the reference count of the givenRefCntinstance by the specified decrement.static voidresetRefCnt(RefCnt ref) Resets the reference count of the givenRefCntinstance to 1.static voidIncreases the reference count of the givenRefCntinstance by 1.static voidIncreases the reference count of the givenRefCntinstance by the specified increment.static voidWARNING: An unsafe operation that sets the reference count of the givenRefCntinstance directly.
-
Constructor Details
-
RefCnt
public RefCnt()
-
-
Method Details
-
refCnt
Returns the current reference count of the givenRefCntinstance with a load acquire semantic.- Parameters:
ref- the target RefCnt instance- Returns:
- the reference count
-
retain
Increases the reference count of the givenRefCntinstance by 1.- Parameters:
ref- the target RefCnt instance
-
retain
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
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
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
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
WARNING: An unsafe operation that sets the reference count of the givenRefCntinstance directly.- Parameters:
ref- the target RefCnt instancerefCnt- new reference count
-
resetRefCnt
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
-