ccstm
ccstm copied to clipboard
TxnLocal enhancements
TxnLocal
should get some of the methods from Ref
:
- the access shortcuts
apply()
andupdate(v)
- read+write forms
swap
,transform
,transformIfDefined
,+=
,-=
, and*=
I think compareAndSet
(and other Ref
methods whose success or failure is determined by concurrent accesses) would be misleading, because TxnLocal
instances are isolated.
Also, overriding initialValue
should perhaps be replaced with a by-name parameter to a factory method. This is more Scala-ish, but makes it more difficult to get access to the current Txn
context.
The factory method with by-name initial value doesn't mean you cannot keep the possibility to override initialValue and thereby gain access to the Txn...
// { object TxnLocal { def apply[ T ](init: => T) = new TxnLocal { override protected def initialValue( txn: Txn ) = init } }
val test = TxnLocal( false ) // }