00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef _M_TXMUTEX_H_GHA983
00044 #define _M_TXMUTEX_H_GHA983
00045
00046 #undef pthread_mutex_t
00047 #undef pthread_mutex_init
00048 #undef pthread_mutex_destroy
00049 #undef pthread_mutex_lock
00050 #undef pthread_mutex_unlock
00051
00052 #undef pthread_rwlock_t
00053 #undef pthread_rwlock_init
00054 #undef pthread_rwlock_destroy
00055 #undef pthread_rwlock_rdlock
00056 #undef pthread_rwlock_wrlock
00057 #undef pthread_rwlock_unlock
00058
00059
00060 #include <itm.h>
00061 #include <pthread.h>
00062
00063 #define DEBUG_PRINTF(format, ...)
00064
00065
00066
00067
00068 typedef pthread_mutex_t txmutex_t;
00069
00070
00071 static
00072 void _ITM_CALL_CONVENTION txmutex_unlock_commit_action(void *arg)
00073 {
00074 txmutex_t *txmutex = (txmutex_t *) arg;
00075 pthread_mutex_t *mutex = (pthread_mutex_t *) txmutex;
00076
00077
00078 pthread_mutex_unlock(mutex);
00079
00080 return;
00081 }
00082
00083 __attribute__((tm_pure))
00084 static inline
00085 int txmutex_init(txmutex_t *txmutex)
00086 {
00087 pthread_mutex_t *mutex = (pthread_mutex_t *) txmutex;
00088 pthread_mutexattr_t attr;
00089 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
00090
00091 return pthread_mutex_init(mutex, &attr);
00092 }
00093
00094
00095 __attribute__((tm_pure))
00096 static inline
00097 int txmutex_destroy(txmutex_t *txmutex)
00098 {
00099 pthread_mutex_t *mutex = (pthread_mutex_t *) txmutex;
00100
00101 return pthread_mutex_destroy(mutex);
00102 }
00103
00104
00105 __attribute__((tm_pure))
00106 static inline
00107 int txmutex_lock(txmutex_t *txmutex)
00108 {
00109 pthread_mutex_t *mutex = (pthread_mutex_t *) txmutex;
00110 int ret;
00111
00112 DEBUG_PRINTF("[%d] NOW : MUTEX LOCK %p\n", pthread_self(), mutex);
00113 ret = pthread_mutex_lock(mutex);
00114 DEBUG_PRINTF("[%d] NOW : MUTEX LOCK %p DONE\n", pthread_self(), mutex);
00115
00116 return ret;
00117 }
00118
00119
00120 __attribute__((tm_pure))
00121 static inline
00122 int txmutex_unlock(txmutex_t *txmutex)
00123 {
00124 int ret;
00125 pthread_mutex_t *mutex = (pthread_mutex_t *) txmutex;
00126
00127 _ITM_transaction * td;
00128 td = _ITM_getTransaction();
00129
00130 if (_ITM_inTransaction(td) > 0) {
00131 DEBUG_PRINTF("[%d] DEFER: MUTEX UNLOCK %p\n", pthread_self(), mutex);
00132 _ITM_addUserCommitAction (td, txmutex_unlock_commit_action, 2, txmutex);
00133 ret = 0;
00134 } else {
00135 DEBUG_PRINTF("[%d] NOW : MUTEX UNLOCK %p\n", pthread_self(), mutex);
00136 ret = pthread_mutex_unlock (mutex);
00137 }
00138
00139 return ret;
00140 }
00141
00142
00143 #endif