Refine search
public long getLevelMinPriority(int level, long taskThreadUsageNanos) { levelMinPriority[level].compareAndSet(-1, taskThreadUsageNanos); return levelMinPriority[level].get(); }
@Override public void onNext(T t) { long idx = index.get(); if (idx == Long.MAX_VALUE || !index.compareAndSet(idx, idx + 1)) { return; } Disposable d = task.get(); if (d != null) { d.dispose(); } downstream.onNext(t); ObservableSource<?> itemTimeoutObservableSource; try { itemTimeoutObservableSource = ObjectHelper.requireNonNull( itemTimeoutIndicator.apply(t), "The itemTimeoutIndicator returned a null ObservableSource."); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); upstream.get().dispose(); index.getAndSet(Long.MAX_VALUE); downstream.onError(ex); return; } TimeoutConsumer consumer = new TimeoutConsumer(idx + 1, this); if (task.replace(consumer)) { itemTimeoutObservableSource.subscribe(consumer); } }
private void setMax(long value) { long current; while (value > (current = max.get()) && !max.compareAndSet(current, value)) ; }
@Override public void onNext(T t) { long idx = index.get(); if (idx == Long.MAX_VALUE || !index.compareAndSet(idx, idx + 1)) { return; } Disposable d = task.get(); if (d != null) { d.dispose(); } consumed++; downstream.onNext(t); Publisher<?> itemTimeoutPublisher; try { itemTimeoutPublisher = ObjectHelper.requireNonNull( itemTimeoutIndicator.apply(t), "The itemTimeoutIndicator returned a null Publisher."); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); upstream.get().cancel(); index.getAndSet(Long.MAX_VALUE); downstream.onError(ex); return; } TimeoutConsumer consumer = new TimeoutConsumer(idx + 1, this); if (task.replace(consumer)) { itemTimeoutPublisher.subscribe(consumer); } }
private void setMin(long value) { long current; while (value < (current = min.get()) && !min.compareAndSet(current, value)) ; }
public void offer( long candidate ) { long currentHighest; do { currentHighest = highestId.get(); if ( candidate <= currentHighest ) { return; } } while ( !highestId.compareAndSet( currentHighest, candidate ) ); }
public static boolean compareAndIncreaseOnly(final AtomicLong target, final long value) { long prev = target.get(); while (value > prev) { boolean updated = target.compareAndSet(prev, value); if (updated) return true; prev = target.get(); } return false; }
private static void update( AtomicLong highestAppliedVersion, long version ) { for ( long high; ; ) { high = highestAppliedVersion.get(); if ( version <= high ) { return; } if ( highestAppliedVersion.compareAndSet( high, version ) ) { return; } } }
/** * Acquire the light lock protecting this consumer from multi-threaded access. Instead of blocking * when the lock is not available, however, we just throw an exception (since multi-threaded usage is not * supported). * @throws ConcurrentModificationException if another thread already has the lock */ private void acquire() { long threadId = Thread.currentThread().getId(); if (threadId != currentThread.get() && !currentThread.compareAndSet(NO_CURRENT_THREAD, threadId)) throw new ConcurrentModificationException("KafkaConsumer is not safe for multi-threaded access"); refcount.incrementAndGet(); }
public boolean tryAcquire() { long currentTime = System.currentTimeMillis(); long lastTime = lastTimeAtom.get(); return currentTime - lastTime >= windowSizeMillis && lastTimeAtom.compareAndSet(lastTime, currentTime); } }
/** * Copy from {@link Random#seedUniquifier()} */ private static long seedUniquifier() { for (; ; ) { long current = seedUniquifier.get(); long next = current * 181783497276652981L; if (seedUniquifier.compareAndSet(current, next)) { return next; } } }
public boolean accept(long now) { long currTokens; if (now > nextUpdate) { currTokens = tokens.get(); if (tokens.compareAndSet(currTokens, maxTokens)) { nextUpdate = System.currentTimeMillis() / 1000 * 1000 + intervalMillis; } } do { currTokens = tokens.get(); } while (currTokens > 0 && !tokens.compareAndSet(currTokens, currTokens - 1)); return currTokens > 0; } }
public void afterConnected(long delta) { connectingCount.decrementAndGet(); connectNanoTotal.addAndGet(delta); for (;;) { // connectNanoMax long max = connectNanoMax.get(); if (delta > max) { if (connectNanoMax.compareAndSet(max, delta)) { break; } else { continue; } } else { break; } } activeCount.incrementAndGet(); }
public void afterClose(long aliveNano) { openingCount.decrementAndGet(); aliveNanoTotal.addAndGet(aliveNano); for (;;) { long max = aliveNanoMax.get(); if (aliveNano > max) { if (aliveNanoMax.compareAndSet(max, aliveNano)) { break; } } else { break; } } for (;;) { long min = aliveNanoMin.get(); if (aliveNano < min) { if (aliveNanoMin.compareAndSet(min, aliveNano)) { break; } } else { break; } } }
/** * Atomically adds the positive value n to the requested value in the AtomicLong and * caps the result at Long.MAX_VALUE and returns the previous value. * @param requested the AtomicLong holding the current requested value * @param n the value to add, must be positive (not verified) * @return the original value before the add */ public static long add(AtomicLong requested, long n) { for (;;) { long r = requested.get(); if (r == Long.MAX_VALUE) { return Long.MAX_VALUE; } long u = addCap(r, n); if (requested.compareAndSet(r, u)) { return r; } } }
/** * Atomically subtract the given number (positive, not validated) from the target field unless it contains Long.MAX_VALUE. * @param requested the target field holding the current requested amount * @param n the produced element count, positive (not validated) * @return the new amount */ public static long produced(AtomicLong requested, long n) { for (;;) { long current = requested.get(); if (current == Long.MAX_VALUE) { return Long.MAX_VALUE; } long update = current - n; if (update < 0L) { RxJavaPlugins.onError(new IllegalStateException("More produced than requested: " + update)); update = 0L; } if (requested.compareAndSet(current, update)) { return update; } } }
private boolean acquireLogPermission(String msg) { AtomicLong cooldown = mCooldowns.computeIfAbsent(msg, m -> new AtomicLong(0)); long allowed = cooldown.get(); long now = System.currentTimeMillis(); return now >= allowed && cooldown.compareAndSet(allowed, now + mCooldownMs); }
/** * Atomically adds the positive value n to the requested value in the AtomicLong and * caps the result at Long.MAX_VALUE and returns the previous value and * considers Long.MIN_VALUE as a cancel indication (no addition then). * @param requested the AtomicLong holding the current requested value * @param n the value to add, must be positive (not verified) * @return the original value before the add */ public static long addCancel(AtomicLong requested, long n) { for (;;) { long r = requested.get(); if (r == Long.MIN_VALUE) { return Long.MIN_VALUE; } if (r == Long.MAX_VALUE) { return Long.MAX_VALUE; } long u = addCap(r, n); if (requested.compareAndSet(r, u)) { return r; } } }
public static long next() { while ( true ) { long base = System.currentTimeMillis() << BIN_DIGITS; long maxValue = base + ONE_MS - 1; for ( long current = VALUE.get(), update = Math.max( base, current + 1 ); update < maxValue; current = VALUE.get(), update = Math.max( base, current + 1 ) ) { if ( VALUE.compareAndSet( current, update ) ) { return update; } } } }
private void updateMax(int time) { long max; do { max = this.max.get(); if (max >= 0 && ((int) max) >= time) { return; } } while (!this.max.compareAndSet(max, UnsignedInts.toLong(time))); }