TxnLocal.isInitialized -- why doesn't an InTxnEnd suffice?

11 views
Skip to first unread message

Hanns Holger Rutz

unread,
Dec 22, 2012, 7:31:42 PM12/22/12
to scala-stm-e...@googlegroups.com
I'm just refactoring some stuff involving `TxnLocal` and `setExternalDecider`. I'm using the `TxnLocal` to store/initialize a peer database transaction. The external decider is now exterior and cascades, i.e. calls into the database decider; that cannot determine whether the `TxnLocal` was initialized, as I only have an `InTxnEnd`; while I can call `apply`, I need to call `isInitialized` first in order to only retrieve the peer txn _if it had been used in that transaction_.

So I wonder why `isInitialized` needs a full `InTxn` and not just `InTxnEnd`, and whether I can work around this somehow?

Thanks, .h.h.

Hanns Holger Rutz

unread,
Dec 22, 2012, 7:36:55 PM12/22/12
to scala-stm-e...@googlegroups.com
the work around

private val dbTxnInit = TxnLocal( false )
private val dbTxnRef = TxnLocal( initialValue = { implicit tx =>
// Txn.setExternalDecider( this )
val res = database.beginTransaction()
...
dbTxnInit() = true
res
}

def shouldCommit( implicit txn: InTxnEnd ) : Boolean = {
// if( !dbTxnRef.isInitialized ) return true // can't call
if( !dbTxnInit.get ) return true // work around

val dbTxn = dbTxnRef() // safe to read now
...
> --
>
>
>

Nathan Bronson

unread,
Dec 22, 2012, 10:32:06 PM12/22/12
to scala-stm-e...@googlegroups.com
You're right, the parameter is more specific than necessary. I've published 0.8-SNAPSHOT with the fix, and I will update the docs once github becomes writable again. Your workaround is correct.

 - Nathan


--






--
Nathan Grasso Bronson
ngbr...@gmail.com
Reply all
Reply to author
Forward
0 new messages