sun.misc.Unsafe.getAndAddLong()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(225)

本文整理了Java中sun.misc.Unsafe.getAndAddLong()方法的一些代码示例,展示了Unsafe.getAndAddLong()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Unsafe.getAndAddLong()方法的具体详情如下:
包路径:sun.misc.Unsafe
类名称:Unsafe
方法名:getAndAddLong

Unsafe.getAndAddLong介绍

[英]Atomically adds the given value to the current value of a field or array element within the given object o at the given offset.
[中]以原子方式将给定值添加到给定对象o中给定offset处的字段或数组元素的当前值。

代码示例

代码示例来源:origin: neo4j/neo4j

/**
 * Atomically add the given delta to the long field, and return its previous value.
 * <p>
 * This has the memory visibility semantics of a volatile read followed by a volatile write.
 */
public static long getAndAddLong( Object obj, long offset, long delta )
{
  return unsafe.getAndAddLong( obj, offset, delta );
}

代码示例来源:origin: real-logic/aeron

private long getAndAddRawTail(final int alignedLength)
  {
    return UnsafeAccess.UNSAFE.getAndAddLong(null, tailAddressOffset, alignedLength);
  }
}

代码示例来源:origin: JCTools/JCTools

@Override
protected void inc(long[] cells, long offset, long delta) {
  UNSAFE.getAndAddLong(cells, offset, delta);
}

代码示例来源:origin: real-logic/agrona

/**
 * Perform an atomic increment that will not lose updates across threads.
 *
 * @return the previous value of the counter
 */
public long increment()
{
  return UnsafeAccess.UNSAFE.getAndAddLong(byteArray, addressOffset, 1);
}

代码示例来源:origin: real-logic/agrona

/**
 * Add an increment to the counter that will not lose updates across threads.
 *
 * @param increment to be added.
 * @return the previous value of the counter
 */
public long getAndAdd(final long increment)
{
  return UnsafeAccess.UNSAFE.getAndAddLong(byteArray, addressOffset, increment);
}

代码示例来源:origin: real-logic/agrona

public long getAndAddLong(final long index, final long delta)
{
  if (SHOULD_BOUNDS_CHECK)
  {
    boundsCheck0(index, SIZE_OF_LONG);
  }
  return UNSAFE.getAndAddLong(null, addressOffset + index, delta);
}

代码示例来源:origin: real-logic/agrona

public long getAndAddLong(final int index, final long delta)
{
  if (SHOULD_BOUNDS_CHECK)
  {
    boundsCheck0(index, SIZE_OF_LONG);
  }
  return UNSAFE.getAndAddLong(byteArray, addressOffset + index, delta);
}

代码示例来源:origin: JCTools/JCTools

protected final long getAndIncrementProducerCycleClaim(int cycleIndex)
{
  return UNSAFE.getAndAddLong(this, calcProducerCycleClaimOffset(cycleIndex), 1);
}

代码示例来源:origin: org.kaazing/nuklei-core

/**
 * Generate and return an ID that is unique between participants.
 *
 * @return id
 */
public long nextId()
{
  return UNSAFE.getAndAddLong(this, ID_COUNTER_OFFSET, 1);
}

代码示例来源:origin: org.agrona/Agrona

/**
 * Perform an atomic increment that will not lose updates across threads.
 *
 * @return the previous value of the counter
 */
public long increment()
{
  return UnsafeAccess.UNSAFE.getAndAddLong(buffer, addressOffset, 1);
}

代码示例来源:origin: io.aeron/aeron-client

private long getAndAddRawTail(final int alignedLength)
  {
    return UnsafeAccess.UNSAFE.getAndAddLong(null, tailAddressOffset, alignedLength);
  }
}

代码示例来源:origin: io.snappydata/gemfire-core

/**
 * {@inheritDoc}
 */
@Override
public final long getAndAdd(T obj, final long delta) {
 return unsafe.getAndAddLong(obj, offset, delta);
}

代码示例来源:origin: io.aeron/aeron-all

private long getAndAddRawTail(final int alignedLength)
  {
    return UnsafeAccess.UNSAFE.getAndAddLong(null, tailAddressOffset, alignedLength);
  }
}

代码示例来源:origin: dragome/dragome-sdk

/**
 * Atomically adds the given value to the current value.
 *
 * @param delta the value to add
 * @return the updated value
 */
public final long addAndGet(long delta) {
  return unsafe.getAndAddLong(this, valueOffset, delta) + delta;
}

代码示例来源:origin: dragome/dragome-sdk

/**
 * Atomically decrements by one the current value.
 *
 * @return the updated value
 */
public final long decrementAndGet() {
  return unsafe.getAndAddLong(this, valueOffset, -1L) - 1L;
}

代码示例来源:origin: dragome/dragome-sdk

/**
 * Atomically decrements by one the current value.
 *
 * @return the previous value
 */
public final long getAndDecrement() {
  return unsafe.getAndAddLong(this, valueOffset, -1L);
}

代码示例来源:origin: zeebe-io/zeebe

@Override
public void signal() {
 UNSAFE.getAndAddLong(this, TRIGGER_COUNT_OFFSET, 1);
 task.tryWakeup();
}

代码示例来源:origin: org.agrona/agrona

public long getAndAddLong(final int index, final long delta)
{
  if (SHOULD_BOUNDS_CHECK)
  {
    boundsCheck0(index, SIZE_OF_LONG);
  }
  return UNSAFE.getAndAddLong(byteArray, addressOffset + index, delta);
}

代码示例来源:origin: OpenHFT/Chronicle-Core

@Override
  @ForceInline
  public long addLong(@NotNull Object object, long offset, long increment) {
//        assert (offset & 0x7) == 0;
    if (object == null)
      throw new NullPointerException();
    return UNSAFE.getAndAddLong(object, offset, increment) + increment;
  }

代码示例来源:origin: DataSketches/memory

@Override
public long getAndAddLong(final long offsetBytes, final long delta) { //JDK 8+
 assertValidAndBoundsForWrite(offsetBytes, ARRAY_LONG_INDEX_SCALE);
 final long addr = getCumulativeOffset(offsetBytes);
 if (UnsafeUtil.JDK8_OR_ABOVE) {
  return unsafe.getAndAddLong(getUnsafeObject(), addr, delta);
 } else {
  return JDK7Compatible.getAndAddLong(getUnsafeObject(), addr, delta);
 }
}

相关文章

Unsafe类方法