Refine search
/** * Atomically disposes the Disposable in the field if not already disposed. * @param field the target field * @return true if the current thread managed to dispose the Disposable */ public static boolean dispose(AtomicReference<Disposable> field) { Disposable current = field.get(); Disposable d = DISPOSED; if (current != d) { current = field.getAndSet(d); if (current != d) { if (current != null) { current.dispose(); } return true; } } return false; }
@SuppressWarnings("unchecked") BehaviorSubscription<T>[] terminate(Object terminalValue) { BehaviorSubscription<T>[] a = subscribers.get(); if (a != TERMINATED) { a = subscribers.getAndSet(TERMINATED); if (a != TERMINATED) { // either this or atomics with lots of allocation setCurrent(terminalValue); } } return a; }
/** * Atomically swaps in the common cancelled subscription instance * and cancels the previous subscription if any. * @param field the target field to dispose the contents of * @return true if the swap from the non-cancelled instance to the * common cancelled instance happened in the caller's thread (allows * further one-time actions). */ public static boolean cancel(AtomicReference<Subscription> field) { Subscription current = field.get(); if (current != CANCELLED) { current = field.getAndSet(CANCELLED); if (current != CANCELLED) { if (current != null) { current.cancel(); } return true; } } return false; }
@SuppressWarnings("unchecked") BehaviorSubscription<T>[] terminate(Object terminalValue) { BehaviorSubscription<T>[] a = subscribers.get(); if (a != TERMINATED) { a = subscribers.getAndSet(TERMINATED); if (a != TERMINATED) { // either this or atomics with lots of allocation setCurrent(terminalValue); } } return a; }