Skip to content

Commit

Permalink
tryWrite renamed to trySet, see #22
Browse files Browse the repository at this point in the history
  • Loading branch information
nbronson committed Apr 19, 2010
1 parent ce93028 commit d30fa6e
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/edu/stanford/ppl/ccstm/Ref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ object Ref {

/** Either atomically transforms this reference without blocking and
* returns true, or returns false. `transform` is to `tryTransform` as
* `set` is to `tryWrite`. A true return value does not necessarily mean
* `set` is to `trySet`. A true return value does not necessarily mean
* that `f` has already been called, just that the transformation will be
* performed in the bound context if it commits.
* @param f a function that is safe to call multiple times, and safe to
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/edu/stanford/ppl/ccstm/Sink.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object Sink {
* @throws IllegalStateException if this view is bound to a transaction
* that is not active.
*/
def tryWrite(v: T): Boolean
def trySet(v: T): Boolean
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ object LazyConflictIntRef {
record(new Set(v))
}

def tryWrite(v: Int): Boolean = {
def trySet(v: Int): Boolean = {
set(v)
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class StripedIntRef(initialValue: Int) extends IntRef {

def set(v: Int) { STM.atomic(unbind.set(v)(_)) }

def tryWrite(v: Int): Boolean = STM.atomic(unbind.bind(_).tryWrite(v))
def trySet(v: Int): Boolean = STM.atomic(unbind.bind(_).trySet(v))

def readForWrite: Int = get

Expand Down Expand Up @@ -173,7 +173,7 @@ class StripedIntRef(initialValue: Int) extends IntRef {
unbind.set(v)
}

def tryWrite(v: Int): Boolean = {
def trySet(v: Int): Boolean = {
tryTransform(i => v)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private[ccstm] class EscapedBound[T](val unbind: Ref[T],
def releasableRead: ReleasableRead[T] = NonTxn.releasableRead(handle)

def set(v: T) { NonTxn.set(handle, v) }
def tryWrite(v: T): Boolean = NonTxn.tryWrite(handle, v)
def trySet(v: T): Boolean = NonTxn.trySet(handle, v)

def readForWrite: T = NonTxn.get(handle)
def swap(v: T): T = NonTxn.swap(handle, v)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/edu/stanford/ppl/ccstm/impl/NonTxn.scala
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private[ccstm] object NonTxn {
z
}

def tryWrite[T](handle: Handle[T], v: T): Boolean = {
def trySet[T](handle: Handle[T], v: T): Boolean = {
val m0 = tryAcquireLock(handle, true)
if (m0 == 0L) {
false
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/edu/stanford/ppl/ccstm/impl/SingleBound.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ private[ccstm] class SingleBound[T](val unbind: Ref[T],
case null => NonTxn.set(nonTxnHandle, v)
case txn: Txn => txn.set(txnHandle, v)
}
def tryWrite(v: T): Boolean = Txn.dynCurrentOrNull match {
case null => NonTxn.tryWrite(nonTxnHandle, v)
case txn: Txn => txn.tryWrite(txnHandle, v)
def trySet(v: T): Boolean = Txn.dynCurrentOrNull match {
case null => NonTxn.trySet(nonTxnHandle, v)
case txn: Txn => txn.trySet(txnHandle, v)
}

def readForWrite: T = Txn.dynCurrentOrNull match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private[ccstm] class SingleProxyBound[T](unbind0: Ref[T]) extends Ref.Bound[T] {
def releasableRead: ReleasableRead[T] = dynBound.releasableRead

def set(v: T): Unit = dynBound.set(v)
def tryWrite(v: T): Boolean = dynBound.tryWrite(v)
def trySet(v: T): Boolean = dynBound.trySet(v)

def readForWrite: T = dynBound.readForWrite
def swap(v: T): T = dynBound.swap(v)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/edu/stanford/ppl/ccstm/impl/TxnBound.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private[ccstm] class TxnBound[T](val unbind: Ref[T],
def releasableRead: ReleasableRead[T] = txn.releasableRead(handle)

def set(v: T) { txn.set(handle, v) }
def tryWrite(v: T): Boolean = txn.tryWrite(handle, v)
def trySet(v: T): Boolean = txn.trySet(handle, v)

def readForWrite: T = txn.readForWrite(handle)
def swap(v: T): T = txn.swap(handle, v)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/edu/stanford/ppl/ccstm/impl/TxnImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ abstract class TxnImpl(failureHistory: List[Txn.RollbackCause], ctx: ThreadConte
handle.data
}

def tryWrite[T](handle: Handle[T], v: T): Boolean = {
def trySet[T](handle: Handle[T], v: T): Boolean = {
requireActive()

val m0 = handle.meta
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/edu/stanford/ppl/stm/IsolatedRefSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,10 @@ class IsolatedRefSuite extends STMFunSuite {
binder.reset()
}

test(fact + ": " + binder + ": tryWrite") {
test(fact + ": " + binder + ": trySet") {
val x = fact(1)
assert(binder(x).get === 1)
while (!binder(x).tryWrite(2)) {
while (!binder(x).trySet(2)) {
assert(binder(x).get === 1)
}
assert(binder(x).get === 2)
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/edu/stanford/ppl/stm/TxnSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class TxnSuite extends STMFunSuite {
assert(x() === 11)
assert(x.escaped() === 10)
assert(x.escaped.mode == Escaped)
val f = x.escaped.tryWrite(20)
val f = x.escaped.trySet(20)
assert(f === false)
}
}
Expand Down

0 comments on commit d30fa6e

Please sign in to comment.