本文整理了Java中sun.misc.Unsafe.compareAndSwapInt()
方法的一些代码示例,展示了Unsafe.compareAndSwapInt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Unsafe.compareAndSwapInt()
方法的具体详情如下:
包路径:sun.misc.Unsafe
类名称:Unsafe
方法名:compareAndSwapInt
[英]Performs a compare-and-set operation on an int
field within the given object.
[中]对给定对象内的int
字段执行比较和设置操作。
代码示例来源:origin: google/guava
/** CASes the busy field from 0 to 1 to acquire lock. */
final boolean casBusy() {
return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1);
}
代码示例来源:origin: google/guava
/** CASes the busy field from 0 to 1 to acquire lock. */
final boolean casBusy() {
return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1);
}
代码示例来源:origin: prestodb/presto
/** CASes the busy field from 0 to 1 to acquire lock. */
final boolean casBusy() {
return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1);
}
代码示例来源:origin: prestodb/presto
/** CASes the busy field from 0 to 1 to acquire lock. */
final boolean casBusy() {
return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1);
}
代码示例来源:origin: redisson/redisson
@Override
public boolean compareAndSwapInt(long offset, int expect, int newVal) {
return unsafe.compareAndSwapInt(base,off+offset,expect,newVal);
}
代码示例来源:origin: redisson/redisson
@Override
public boolean compareAndSwapInt(long offset, int expect, int newVal) {
return unsafe.compareAndSwapInt(null, baseAdress + offset, expect, newVal);
}
代码示例来源:origin: springside/springside4
/**
* CASes the busy field from 0 to 1 to acquire lock.
*/
final boolean casBusy() {
return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1);
}
代码示例来源:origin: vipshop/vjtools
/**
* CASes the busy field from 0 to 1 to acquire lock.
*/
final boolean casBusy() {
return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1);
}
代码示例来源:origin: alibaba/Sentinel
/**
* CASes the busy field from 0 to 1 to acquire lock.
*/
final boolean casBusy() {
return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1);
}
代码示例来源:origin: ben-manes/caffeine
/** CASes the tableBusy field from 0 to 1 to acquire lock. */
final boolean casTableBusy() {
return UnsafeAccess.UNSAFE.compareAndSwapInt(this, TABLE_BUSY, 0, 1);
}
代码示例来源:origin: google/j2objc
/** CASes the busy field from 0 to 1 to acquire lock. */
final boolean casBusy() {
return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1);
}
代码示例来源:origin: google/j2objc
/** CASes the busy field from 0 to 1 to acquire lock. */
final boolean casBusy() {
return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1);
}
代码示例来源:origin: ben-manes/caffeine
boolean casDrainStatus(int expect, int update) {
return UnsafeAccess.UNSAFE.compareAndSwapInt(this, DRAIN_STATUS_OFFSET, expect, update);
}
}
代码示例来源:origin: alibaba/jstorm
/**
* CASes the busy field from 0 to 1 to acquire lock.
*/
final boolean casBusy() {
return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1);
}
代码示例来源:origin: PipelineAI/pipeline
/**
* CASes the busy field from 0 to 1 to acquire lock.
*/
final boolean casBusy() {
return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1);
}
代码示例来源:origin: h2oai/h2o-2
/**
* Adds (atomically) the given value to the pending count.
*
* @param delta the value to add
*/
public final void addToPendingCount(int delta) {
int c; // note: can replace with intrinsic in jdk8
do {} while (!U.compareAndSwapInt(this, PENDING, c = pending, c+delta));
}
代码示例来源:origin: h2oai/h2o-2
public void setMin( float min ) {
int imin = Float.floatToRawIntBits(min);
float old = _min2;
while( min < old && !_unsafe.compareAndSwapInt(this, _min2Offset, Float.floatToRawIntBits(old), imin ) )
old = _min2;
}
// Find Inclusive _max2
代码示例来源:origin: jersey/jersey
/**
* Acquires write lock for tree restructuring.
*/
private final void lockRoot() {
if (!U.compareAndSwapInt(this, LOCKSTATE, 0, WRITER))
contendedLock(); // offload to separate method
}
代码示例来源:origin: jersey/jersey
/**
* Acquires write lock for tree restructuring.
*/
private final void lockRoot() {
if (!U.compareAndSwapInt(this, LOCKSTATE, 0, WRITER))
contendedLock(); // offload to separate method
}
代码示例来源:origin: h2oai/h2o-2
static public void setMax( float fs[], int i, float max ) {
float old = fs[i];
while( max > old && !_unsafe.compareAndSwapInt(fs,rawIndex(fs,i), Float.floatToRawIntBits(old), Float.floatToRawIntBits(max) ) )
old = fs[i];
}
static public String toString( float fs[] ) {
内容来源于网络,如有侵权,请联系作者删除!