00001
00008 #if (_TM_SYSTEM_ITM)
00009
00010 #ifndef _TXC_ITM_H
00011 #define _TXC_ITM_H
00012
00013 #include <itm.h>
00014
00015 static inline
00016 void
00017 tmsystem_tx_init(txc_tx_t *txd)
00018 {
00019 txd->itm_td = _ITM_getTransaction();
00020 txd->tid = (unsigned int) _ITM_getThreadnum();
00021 }
00022
00023
00024 _ITM_CALL_CONVENTION void
00025 tmsystem_generic_undo_action(void *arg)
00026 {
00027 tx_generic_undo_action((txc_tx_t *) arg);
00028 }
00029
00030
00031 _ITM_CALL_CONVENTION void
00032 tmsystem_generic_commit_action(void *arg)
00033 {
00034 tx_generic_commit_action((txc_tx_t *) arg);
00035 }
00036
00037
00038 static inline
00039 void
00040 tmsystem_register_generic_undo_action(txc_tx_t *txd)
00041 {
00042 if (txd->generic_undo_action_registered == 0) {
00043 _ITM_addUserUndoAction(txd->itm_td,
00044 tmsystem_generic_undo_action, (void *) txd);
00045 txd->generic_undo_action_registered = 1;
00046 }
00047 }
00048
00049
00050 static inline
00051 void
00052 tmsystem_register_generic_commit_action(txc_tx_t *txd)
00053 {
00054 if (txd->generic_commit_action_registered == 0) {
00055
00056
00057
00058
00059 _ITM_addUserCommitAction(txd->itm_td,
00060 tmsystem_generic_commit_action, 2, (void *) txd);
00061 txd->generic_commit_action_registered = 1;
00062 }
00063 }
00064
00065
00066 static inline
00067 void
00068 tmsystem_abort_transaction(txc_tx_t *txd, txc_tx_abortreason_t abort_reason)
00069 {
00070 tmsystem_register_generic_undo_action(txd);
00071 txd->abort_reason = abort_reason;
00072 txd->forced_retries++;
00073 switch (abort_reason) {
00074 case TXC_ABORTREASON_USERABORT:
00075 _ITM_abortTransaction(txd->itm_td, userAbort, NULL);
00076 break;
00077 case TXC_ABORTREASON_TMCONFLICT:
00078 _ITM_abortTransaction(txd->itm_td, TMConflict, NULL);
00079 break;
00080 case TXC_ABORTREASON_USERRETRY:
00081 case TXC_ABORTREASON_BUSYSENTINEL:
00082 case TXC_ABORTREASON_INCONSISTENCY:
00083 case TXC_ABORTREASON_BUSYTXLOCK:
00084 _ITM_abortTransaction(txd->itm_td, userRetry, NULL);
00085 break;
00086 default:
00087 TXC_INTERNALERROR("Unknown abort reason\n");
00088
00089 }
00090 }
00091
00092
00093 static inline
00094 txc_tx_xactstate_t
00095 tmsystem_get_xactstate(txc_tx_t *txd)
00096 {
00097 _ITM_transaction *td;
00098 _ITM_howExecuting mode;
00099
00100 td = txd->itm_td;
00101 mode = _ITM_inTransaction(td);
00102 switch (mode) {
00103 case outsideTransaction:
00104 return TXC_XACTSTATE_NONTRANSACTIONAL;
00105 case inRetryableTransaction:
00106 return TXC_XACTSTATE_TRANSACTIONAL_RETRYABLE;
00107 case inIrrevocableTransaction:
00108 return TXC_XACTSTATE_TRANSACTIONAL_IRREVOCABLE;
00109 default:
00110 TXC_INTERNALERROR("Unknown transaction state");
00111 }
00112 }
00113
00114
00115 #endif
00116
00117 #endif