51 public class AtomicBoolean implements java.io.Serializable {
52 private static final long serialVersionUID = 4654671469794556979L;
53 private static final VarHandle VALUE;
54 static {
55 try {
56 MethodHandles.Lookup l = MethodHandles.lookup();
57 VALUE = l.findVarHandle(AtomicBoolean.class, "value", int.class);
58 } catch (ReflectiveOperationException e) {
59 throw new ExceptionInInitializerError(e);
60 }
61 }
62
63 private volatile int value;
64
65 /**
66 * Creates a new {@code AtomicBoolean} with the given initial value.
67 *
68 * @param initialValue the initial value
69 */
70 public AtomicBoolean(boolean initialValue) {
71 value = initialValue ? 1 : 0;
72 }
73
74 /**
75 * Creates a new {@code AtomicBoolean} with initial value {@code false}.
76 */
77 public AtomicBoolean() {
78 }
79
80 /**
81 * Returns the current value,
82 * with memory effects as specified by {@link VarHandle#getVolatile}.
83 *
84 * @return the current value
85 */
86 public final boolean get() {
87 return value != 0;
88 }
89
90 /**
91 * Atomically sets the value to {@code newValue}
|
51 public class AtomicBoolean implements java.io.Serializable {
52 private static final long serialVersionUID = 4654671469794556979L;
53 private static final VarHandle VALUE;
54 static {
55 try {
56 MethodHandles.Lookup l = MethodHandles.lookup();
57 VALUE = l.findVarHandle(AtomicBoolean.class, "value", int.class);
58 } catch (ReflectiveOperationException e) {
59 throw new ExceptionInInitializerError(e);
60 }
61 }
62
63 private volatile int value;
64
65 /**
66 * Creates a new {@code AtomicBoolean} with the given initial value.
67 *
68 * @param initialValue the initial value
69 */
70 public AtomicBoolean(boolean initialValue) {
71 if (initialValue)
72 value = 1;
73 }
74
75 /**
76 * Creates a new {@code AtomicBoolean} with initial value {@code false}.
77 */
78 public AtomicBoolean() {
79 }
80
81 /**
82 * Returns the current value,
83 * with memory effects as specified by {@link VarHandle#getVolatile}.
84 *
85 * @return the current value
86 */
87 public final boolean get() {
88 return value != 0;
89 }
90
91 /**
92 * Atomically sets the value to {@code newValue}
|