Method from EDU.oswego.cs.dl.util.concurrent.SynchronizedInt Detail: |
public int add(int amount) {
synchronized (lock_) {
return value_ += amount;
}
}
Add amount to value (i.e., set value += amount) |
public int and(int b) {
synchronized (lock_) {
value_ = value_ & b;
return value_;
}
}
|
public boolean commit(int assumedValue,
int 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(int other) {
int val = get();
return (val < other)? -1 : (val == other)? 0 : 1;
}
|
public int compareTo(SynchronizedInt other) {
return compareTo(other.get());
}
|
public int compareTo(Object other) {
return compareTo((SynchronizedInt)other);
}
|
public int complement() {
synchronized (lock_) {
value_ = ~value_;
return value_;
}
}
Set the value to its complement |
public int decrement() {
synchronized (lock_) {
return --value_;
}
}
|
public int divide(int factor) {
synchronized (lock_) {
return value_ /= factor;
}
}
Divide value by factor (i.e., set value /= factor) |
public boolean equals(Object other) {
if (other != null &&
other instanceof SynchronizedInt)
return get() == ((SynchronizedInt)other).get();
else
return false;
}
|
public final int get() {
synchronized(lock_) { return value_; }
}
|
public int hashCode() {
return get();
}
|
public int increment() {
synchronized (lock_) {
return ++value_;
}
}
|
public synchronized int multiply(int factor) {
synchronized (lock_) {
return value_ *= factor;
}
}
Multiply value by factor (i.e., set value *= factor) |
public int negate() {
synchronized (lock_) {
value_ = -value_;
return value_;
}
}
Set the value to the negative of its old value |
public int or(int b) {
synchronized (lock_) {
value_ = value_ | b;
return value_;
}
}
|
public int set(int newValue) {
synchronized (lock_) {
int old = value_;
value_ = newValue;
return old;
}
}
|
public int subtract(int amount) {
synchronized (lock_) {
return value_ -= amount;
}
}
Subtract amount from value (i.e., set value -= amount) |
public int swap(SynchronizedInt other) {
if (other == this) return get();
SynchronizedInt fst = this;
SynchronizedInt 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 SynchronizedInt.
Uses identityHashCode to avoid deadlock when
two SynchronizedInts 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 int xor(int b) {
synchronized (lock_) {
value_ = value_ ^ b;
return value_;
}
}
|