本文整理汇总了Java中org.apache.ignite.internal.util.GridUnsafe.compareAndSwapLong方法的典型用法代码示例。如果您正苦于以下问题:Java GridUnsafe.compareAndSwapLong方法的具体用法?Java GridUnsafe.compareAndSwapLong怎么用?Java GridUnsafe.compareAndSwapLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ignite.internal.util.GridUnsafe
的用法示例。
在下文中一共展示了GridUnsafe.compareAndSwapLong方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: borrowFreePage
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/**
* @return Relative pointer to a free page that was borrowed from the allocated pool.
*/
private long borrowFreePage() {
while (true) {
long freePageRelPtrMasked = GridUnsafe.getLong(freePageListPtr);
long freePageRelPtr = freePageRelPtrMasked & ADDRESS_MASK;
if (freePageRelPtr != INVALID_REL_PTR) {
long freePageAbsPtr = absolute(freePageRelPtr);
long nextFreePageRelPtr = GridUnsafe.getLong(freePageAbsPtr) & ADDRESS_MASK;
long cnt = ((freePageRelPtrMasked & COUNTER_MASK) + COUNTER_INC) & COUNTER_MASK;
if (GridUnsafe.compareAndSwapLong(null, freePageListPtr, freePageRelPtrMasked, nextFreePageRelPtr | cnt)) {
GridUnsafe.putLong(freePageAbsPtr, PAGE_MARKER);
return freePageRelPtr;
}
}
else
return INVALID_REL_PTR;
}
}
示例2: updateAtomicLong
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/**
* @param ptr Pointer to update.
* @param delta Delta.
*/
private static long updateAtomicLong(long ptr, long delta) {
while (true) {
long old = GridUnsafe.getLong(ptr);
long updated = old + delta;
if (GridUnsafe.compareAndSwapLong(null, ptr, old, updated))
return updated;
}
}
示例3: casLong
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/**
* @param ptr Pointer.
* @param exp Expected.
* @param v New value.
* @return {@code true} If operation succeeded.
*/
public boolean casLong(long ptr, long exp, long v) {
return GridUnsafe.compareAndSwapLong(null, ptr, exp, v);
}