Skip to content

Commit

Permalink
Removed weakCompareAndSet and weakCompareAndSetIdentity. See #22
Browse files Browse the repository at this point in the history
  • Loading branch information
nbronson committed Apr 19, 2010
1 parent 20ef254 commit 4560d71
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 100 deletions.
16 changes: 0 additions & 16 deletions src/main/scala/edu/stanford/ppl/ccstm/Ref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,6 @@ object Ref {
*/
def compareAndSetIdentity[A <: T with AnyRef](before: A, after: T): Boolean

/** Works like <code>compareAndSet</code>, but allows spurious failures. A
* false return from this method does not necessarily mean that the
* previous value of the <code>Ref</code> is not equal to
* <code>before</code>.
* @see edu.stanford.ppl.ccstm.Ref.Bound#compareAndSet
*/
def weakCompareAndSet(before: T, after: T): Boolean

/** Works like <code>compareAndSetIdentity</code>, but allows spurious
* failures. A false return from this method does not necessarily mean
* that the previous value of the <code>Ref</code> has a different
* reference identity than <code>before</code>.
* @see edu.stanford.ppl.ccstm.Ref.Bound#compareAndSetIdentity
*/
def weakCompareAndSetIdentity[A <: T with AnyRef](before: A, after: T): Boolean

/** Atomically replaces the value ''v'' stored in the `Ref` with
* `f`(''v''). Some implementations may defer execution of `f` or call
* `f` multiple times.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,9 @@ object LazyConflictIntRef {
}
}

def weakCompareAndSet(before: Int, after: Int): Boolean = compareAndSet(before, after)

def compareAndSetIdentity[A <: Int with AnyRef](before: A, after: Int): Boolean = {
throw new UnsupportedOperationException("identity comparisons are not valid on Int")
}
def weakCompareAndSetIdentity[A <: Int with AnyRef](before: A, after: Int): Boolean = {
throw new UnsupportedOperationException("identity comparisons are not valid on Int")
}

def transform(f: (Int) => Int) {
_value = f(_value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,6 @@ class StripedIntRef(initialValue: Int) extends IntRef {
throw new UnsupportedOperationException
}

def weakCompareAndSet(before: Int, after: Int): Boolean = {
compareAndSet(before, after)
}

def weakCompareAndSetIdentity[A <: Int with AnyRef](before: A, after: Int): Boolean = {
throw new UnsupportedOperationException
}

def transform(f: Int => Int) { STM.atomic(unbind.transform(f)(_)) }

def getAndTransform(f: Int => Int): Int = STM.atomic(unbind.bind(_).getAndTransform(f))
Expand Down Expand Up @@ -218,14 +210,6 @@ class StripedIntRef(initialValue: Int) extends IntRef {
throw new UnsupportedOperationException
}

def weakCompareAndSet(before: Int, after: Int): Boolean = {
compareAndSet(before, after)
}

def weakCompareAndSetIdentity[A <: Int with AnyRef](before: A, after: Int): Boolean = {
throw new UnsupportedOperationException
}

def transform(f: Int => Int) {
unbind.transform(f)
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/scala/edu/stanford/ppl/ccstm/impl/EscapedBound.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ private[ccstm] class EscapedBound[T](val unbind: Ref[T],
def getAndSet(v: T): T = NonTxn.getAndSet(handle, v)
def compareAndSet(before: T, after: T): Boolean = NonTxn.compareAndSet(handle, before, after)
def compareAndSetIdentity[R <: AnyRef with T](before: R, after: T): Boolean = NonTxn.compareAndSetIdentity(handle, before, after)
def weakCompareAndSet(before: T, after: T): Boolean = NonTxn.compareAndSet(handle, before, after)
def weakCompareAndSetIdentity[R <: AnyRef with T](before: R, after: T): Boolean = NonTxn.compareAndSetIdentity(handle, before, after)
def transform(f: T => T) { NonTxn.getAndTransform(handle, f) }
def getAndTransform(f: T => T): T = NonTxn.getAndTransform(handle, f)
def tryTransform(f: T => T): Boolean = NonTxn.tryTransform(handle, f)
Expand Down
8 changes: 0 additions & 8 deletions src/main/scala/edu/stanford/ppl/ccstm/impl/SingleBound.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ private[ccstm] class SingleBound[T](val unbind: Ref[T],
case null => NonTxn.compareAndSetIdentity(nonTxnHandle, before, after)
case txn: Txn => txn.compareAndSetIdentity(txnHandle, before, after)
}
def weakCompareAndSet(before: T, after: T): Boolean = Txn.dynCurrentOrNull match {
case null => NonTxn.compareAndSet(nonTxnHandle, before, after)
case txn: Txn => txn.weakCompareAndSet(txnHandle, before, after)
}
def weakCompareAndSetIdentity[R <: AnyRef with T](before: R, after: T): Boolean = Txn.dynCurrentOrNull match {
case null => NonTxn.compareAndSetIdentity(nonTxnHandle, before, after)
case txn: Txn => txn.weakCompareAndSetIdentity(txnHandle, before, after)
}
def transform(f: T => T): Unit = Txn.dynCurrentOrNull match {
case null => NonTxn.getAndTransform(nonTxnHandle, f)
case txn: Txn => txn.getAndTransform(txnHandle, f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ private[ccstm] class SingleProxyBound[T](unbind0: Ref[T]) extends Ref.Bound[T] {
def compareAndSet(before: T, after: T): Boolean = dynBound.compareAndSet(before, after)
def compareAndSetIdentity[R <: AnyRef with T](before: R, after: T): Boolean =
dynBound.compareAndSetIdentity(before, after)
def weakCompareAndSet(before: T, after: T): Boolean =
dynBound.weakCompareAndSet(before, after)
def weakCompareAndSetIdentity[R <: AnyRef with T](before: R, after: T): Boolean =
dynBound.weakCompareAndSetIdentity(before, after)
def transform(f: T => T): Unit = dynBound.transform(f)
def getAndTransform(f: T => T): T = dynBound.getAndTransform(f)
def tryTransform(f: T => T): Boolean = dynBound.tryTransform(f)
Expand Down
2 changes: 0 additions & 2 deletions src/main/scala/edu/stanford/ppl/ccstm/impl/TxnBound.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ private[ccstm] class TxnBound[T](val unbind: Ref[T],
def getAndSet(v: T): T = txn.getAndSet(handle, v)
def compareAndSet(before: T, after: T): Boolean = txn.compareAndSet(handle, before, after)
def compareAndSetIdentity[A <: T with AnyRef](before: A, after: T): Boolean = txn.compareAndSetIdentity(handle, before, after)
def weakCompareAndSet(before: T, after: T): Boolean = txn.weakCompareAndSet(handle, before, after)
def weakCompareAndSetIdentity[A <: T with AnyRef](before: A, after: T): Boolean = txn.weakCompareAndSetIdentity(handle, before, after)
def transform(f: T => T) {
// this isn't as silly as it seems, because some Bound implementations
// override getAndTransform()
Expand Down
8 changes: 0 additions & 8 deletions src/main/scala/edu/stanford/ppl/ccstm/impl/TxnImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -644,14 +644,6 @@ abstract class TxnImpl(failureHistory: List[Txn.RollbackCause], ctx: ThreadConte
})
}

def weakCompareAndSet[T](handle: Handle[T], before: T, after: T): Boolean = {
compareAndSet(handle, before, after)
}

def weakCompareAndSetIdentity[T, R <: T with AnyRef](handle: Handle[T], before: R, after: T): Boolean = {
compareAndSetIdentity(handle, before, after)
}

def getAndTransform[T](handle: Handle[T], f: T => T): T = {
requireActive()

Expand Down
39 changes: 0 additions & 39 deletions src/test/scala/edu/stanford/ppl/stm/IsolatedRefSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -303,45 +303,6 @@ class IsolatedRefSuite extends STMFunSuite {
binder.reset()
}

test(fact + ": " + binder + ": successful weakCompareAndSet") {
val x = fact(1)
while (!binder(x).weakCompareAndSet(1, 2)) {
assert(binder(x).get === 1)
}
assert(binder(x).get === 2)
binder.reset()
}

test(fact + ": " + binder + ": failing weakCompareAndSet") {
val x = fact(1)
val f = binder(x).weakCompareAndSet(2, 3)
assert(!f)
assert(binder(x).get === 1)
binder.reset()
}

test(fact + ": " + binder + ": successful weakCompareAndSetIdentity") {
val ref1 = new java.lang.Integer(3)
val ref2 = new java.lang.Integer(4)
val x = Ref(ref1)
while (!binder(x).weakCompareAndSetIdentity(ref1, ref2)) {
assert(binder(x).get eq ref1)
}
assert(binder(x).get eq ref2)
binder.reset()
}

test(fact + ": " + binder + ": failing weakCompareAndSetIdentity") {
val ref1 = new java.lang.Integer(3)
val ref2 = new java.lang.Integer(3)
val ref3 = new java.lang.Integer(4)
val x = Ref(ref1)
val f = binder(x).weakCompareAndSetIdentity(ref2, ref3)
assert(!f)
assert(binder(x).get eq ref1)
binder.reset()
}

test(fact + ": " + binder + ": unrecordedRead immediate use") {
val x = fact(1)
val u = binder(x).unrecordedRead
Expand Down

0 comments on commit 4560d71

Please sign in to comment.