Java Code Examples for java.util.concurrent.atomic.AtomicReference.getAcquire()

The following are Jave code examples for showing how to use getAcquire() of the java.util.concurrent.atomic.AtomicReference class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Reactive4JavaFlow   File: ExceptionHelper.java   Source Code and License Vote up 5 votes
public static boolean addThrowable(AtomicReference<Throwable> errors, Throwable t) {
    for (;;) {
        Throwable a = (Throwable) errors.getAcquire();
        if (a == TERMINATED) {
            return false;
        }
        Throwable b = CompositeThrowable.combine(a, t);
        if (errors.compareAndSet(a, b)) {
            return true;
        }
    }
}
 
Example 2
Project: Reactive4JavaFlow   File: ExceptionHelper.java   Source Code and License Vote up 5 votes
public static Throwable terminate(AtomicReference<Throwable> errors) {
    Throwable a = (Throwable)errors.getAcquire();
    if (a != TERMINATED) {
        a = (Throwable)errors.getAndSet(TERMINATED);
    }
    return a;
}
 
Example 3
Project: Reactive4JavaFlow   File: VarHandleCostPerf.java   Source Code and License Vote up 5 votes
public static boolean cancel(AtomicReference<Flow.Subscription> field) {
    Flow.Subscription a = field.getAcquire();
    if (a != CANCELLED) {
        a = field.getAndSet(CANCELLED);
        if (a != CANCELLED) {
            if (a != null) {
                a.cancel();
            }
            return true;
        }
    }
    return false;
}