Method from EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean Detail: |
public boolean and(boolean b) {
synchronized (lock_) {
value_ = value_ & b;
return value_;
}
}
|
public boolean commit(boolean assumedValue,
boolean newValue) {
synchronized(lock_) {
boolean success = (assumedValue == value_);
if (success) value_ = newValue;
return success;
}
}
Set value to newValue only if it is currently assumedValue. |
public int compareTo(boolean other) {
boolean val = get();
return (val == other)? 0 : (val)? 1 : -1;
}
|
public int compareTo(SynchronizedBoolean other) {
return compareTo(other.get());
}
|
public int compareTo(Object other) {
return compareTo((SynchronizedBoolean)other);
}
|
public boolean complement() {
synchronized (lock_) {
value_ = !value_;
return value_;
}
}
Set the value to its complement |
public boolean equals(Object other) {
if (other != null &&
other instanceof SynchronizedBoolean)
return get() == ((SynchronizedBoolean)other).get();
else
return false;
}
|
public final boolean get() {
synchronized(lock_) { return value_; }
}
|
public int hashCode() {
boolean b = get();
return (b)? 3412688 : 8319343; // entirely arbitrary
}
|
public boolean or(boolean b) {
synchronized (lock_) {
value_ = value_ | b;
return value_;
}
}
|
public boolean set(boolean newValue) {
synchronized (lock_) {
boolean old = value_;
value_ = newValue;
return old;
}
}
|
public boolean swap(SynchronizedBoolean other) {
if (other == this) return get();
SynchronizedBoolean fst = this;
SynchronizedBoolean snd = other;
if (System.identityHashCode(fst) > System.identityHashCode(snd)) {
fst = other;
snd = this;
}
synchronized(fst.lock_) {
synchronized(snd.lock_) {
fst.set(snd.set(fst.get()));
return get();
}
}
}
Atomically swap values with another SynchronizedBoolean.
Uses identityHashCode to avoid deadlock when
two SynchronizedBooleans attempt to simultaneously swap with each other.
(Note: Ordering via identyHashCode is not strictly guaranteed
by the language specification to return unique, orderable
values, but in practice JVMs rely on them being unique.) |
public String toString() {
return String.valueOf(get());
}
|
public boolean xor(boolean b) {
synchronized (lock_) {
value_ = value_ ^ b;
return value_;
}
}
|