public static int getLocalTID ( TransactionImpl tran ) { if ( tc . isEntryEnabled ( ) ) Tr . entry ( tc , "getLocalTID" , tran ) ; int id ; while ( true ) { // Capture the current seed value. Do another increment // and shift by the difference of current seed. Due to // randomness of thread access and Java memory model, this // will improve the key space to reduce collisions. Using // this approach to avoid using Thread.currentThread() or // a ThreadLocal variable. final int currSeed = _baseSeed ++ ; id = ( ++ _baseSeed << ( _baseSeed - currSeed ) ) & 0x7FFFFFFF ; // Conditionally add the new local tid to the map // associating it with the given transaction. // This has been modified to use non-optimistic putIfAbsent() // to address a race condition if put() is used on its own. if ( id > 0 && localTIDMap . putIfAbsent ( id , tran ) == null ) { // We're done break ; } // If there is a clash, generate a new local TID until // we find one that is free. } if ( tc . isEntryEnabled ( ) ) Tr . exit ( tc , "getLocalTID" , id ) ; return id ; }
Return the next available local tid and associate it with the given transaction . This method should be used during the creation of a new transaction .