}
return result;
}
public static boolean transfer(String accountNum1, String accountNum2, int amount, Timespec deadline, Timespec period_ts, int thread_id) throws Throwable{
Throwable throwable = null;
Context context = ContextDelegator.getInstance();
boolean commit = true;
boolean aborted = false;
boolean earlierTxPresent = false;
Timespec current = new Timespec();
Integer threadID = thread_id;
for (int i = 0; i < 0x7fffffff; i++) {
DTL2Directory.threadPhaseMap.put(thread_id, DTL2Directory.NOT_IN_COMMIT_PHASE);
if(DTL2Directory.priorityRaised_ThreadMap.get(thread_id) == DTL2Directory.PRIORITY_RAISED) {
DTL2Directory.priorityRaised_ThreadMap.put(thread_id, DTL2Directory.PRIORITY_NOT_RAISED);
ChronosScheduler.reset_self_deadline_priority(deadline);
}
context.init(4);
try {
transfer(accountNum1, accountNum2, amount, context, deadline, period_ts, thread_id);
} catch (TransactionException ex) {
commit = false;
earlierTxPresent = false;
aborted = true;
//ex.printStackTrace();
} catch (InterruptedException ex) {
commit = false;
earlierTxPresent = true;
Logger.fetal("Int-Ex recvd in Bank.Tfr " + thread_id);
} catch (Throwable ex) {
throwable = ex;
}
if (commit) {
if (context.commit(deadline, period_ts, thread_id)) {
if (throwable != null) {
throw throwable;
} else {
// Clear interrupt flag raised in commit stage
Thread.interrupted();
aborted = false;
return true;
}
} else {
// wait for signal to retry
Logger.fetal("Failed to commit " + thread_id);
aborted = true;
}
} else {
if(context instanceof ControlContext)
ControlContext.abort(((ControlContext)context).getContextId());
else {
//System.out.print("R-" + tid + " ");
aborted = true;
context.rollback();
if(earlierTxPresent) {
//while(true) {
DummyObject object = new DummyObject(threadID);
synchronized(object) {