00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef STM_H
00020 #define STM_H
00021
00022 #ifdef __cplusplus
00023 extern "C" {
00024 #endif
00025
00026 #include <stdlib.h>
00027 #include <setjmp.h>
00028
00029
00030 #define GLOBAL_VERSION
00031 #define INC_VALIDATION
00032 #define SIGNAL
00033 #define DESC_TLS
00034
00035 #if defined(NOGLOBAL_VERSION)
00036 #undef GLOBAL_VERSION
00037 #endif
00038 #if defined(NOINC_VALIDATION)
00039 #undef INC_VALIDATION
00040 #endif
00041 #if defined(NODESC_TLS)
00042 #undef DESC_TLS
00043 #endif
00044 #if defined(NOSIGNAL)
00045 #undef SIGNAL
00046 #endif
00047
00048 #if defined(STATS) && !defined(DEBUG)
00049 #define DEBUG
00050 #endif
00051
00052 #if defined(DEBUG) && !defined(INC_VALIDATION)
00053 #define INC_VALIDATION
00054 #endif
00055 #if defined(DEBUG) && defined(SIGNAL)
00056 #undef SIGNAL
00057 #endif
00058
00059 #if !defined(INC_VALIDATION) && !defined(SIGNAL)
00060 #define SIGNAL
00061 #endif
00062
00063 #ifdef INLINED
00064 #define INLINE static inline
00065 #define NOINLINE __attribute__((noinline)) static
00066 #else
00067 #define INLINE
00068 #define NOINLINE static
00069 #endif
00070
00071 #ifndef SAVESIGMASK
00072 #define SAVEMASK 0
00073 #else
00074 #define SAVEMASK 1
00075 #endif
00076
00077 #ifndef NOSETJMP
00078 #ifdef SIGNAL
00079 #define SETJMP(buf) sigsetjmp(buf,SAVEMASK)
00080 #define LONGJMP siglongjmp
00081 #else
00082 #define SETJMP(buf) setjmp(buf)
00083 #define LONGJMP longjmp
00084 #endif
00085 #else
00086 #define SETJMP(buf)
00087 #define LONGJMP longjmp
00088 #endif
00089
00090 #define RESET_VALIDATION
00091 #define VALIDATE_OREC(orec) false
00092 #define FAST_VALIDATION false
00093 #define EVENT_START(e)
00094 #define EVENT_END(e)
00095 #define STM_PRINT_EVENT_COUNTS()
00096 #define ASSERT_META_SIZE
00097
00098 #define STM_CONFLICT(desc) stm_retry(desc)
00099
00100 #define STM_VALIDATE() stm_validate(__stm_desc)
00101
00102 #define STM_ASSERT(x) \
00103 { if (!(x)) { STM_SET_DESC(); STM_VALIDATE(); assert(x); }}
00104
00105 void * stm_thr_init();
00106 void stm_thr_retire();
00107
00108 INLINE int stm_in_transaction();
00109 INLINE void * stm_desc();
00110 INLINE void stm_validate(void * mydesc);
00111
00112 #define STM_SET_DESC() void * __stm_desc = stm_desc()
00113
00114 #define STM_BEGIN_CALL() \
00115 stm_begin(_jmpbuf,__stm_desc,__FILE__,__LINE__)
00116
00117 #define STM_BEGIN \
00118 { \
00119 jmp_buf _jmpbuf; \
00120 SETJMP(_jmpbuf); \
00121 STM_BEGIN_CALL();
00122
00123 #define STM_END \
00124 stm_end(__stm_desc); \
00125 }
00126
00127 INLINE void stm_begin(jmp_buf buf,void * mydesc,char * fname,int line);
00128 INLINE void stm_end(void * mydesc);
00129
00130 #define STM_MALLOC(sz) stm_malloc(sz,__stm_desc)
00131 #define STM_FREE(ptr) stm_free(ptr,__stm_desc)
00132 #define STM_CALLOC(ne,sz) stm_calloc(ne,sz,__stm_desc)
00133 #define STM_CHECKPOINT(lval) stm_checkpoint((char *)(&(lval)),sizeof(lval),__stm_desc)
00134
00135 INLINE void * stm_malloc(size_t sz,void * mydesc);
00136 INLINE void stm_free(void * ptr,void * mydesc);
00137 INLINE void * stm_calloc(size_t ne,size_t sz,void * mydesc);
00138 INLINE void stm_checkpoint(char * addr, int size,void * mydesc);
00139 INLINE void stm_stack_range(void * addr, int size, void *mydesc);
00140
00141 #define STM_READ_P(lval) stm_read_ptr((void **)(void *)&(lval),__stm_desc)
00142 #define STM_READ_F(lval) stm_read_float((float *)&(lval),__stm_desc)
00143 #define STM_READ_D(lval) stm_read_double((double *)&(lval),__stm_desc)
00144 #define STM_READ_C(lval) stm_read_char((char *)&(lval),__stm_desc)
00145 #define STM_READ_S(lval) stm_read_short((short *)&(lval),__stm_desc)
00146 #define STM_READ_I(lval) stm_read_int((int *)&(lval),__stm_desc)
00147 #define STM_READ_L(lval) stm_read_long((long *)&(lval),__stm_desc)
00148 #define STM_READ_LL(lval) stm_read_ll((long long *)&(lval),__stm_desc)
00149 #define STM_READ_UC(lval) stm_read_uchar((unsigned char *)&(lval),__stm_desc)
00150 #define STM_READ_US(lval) stm_read_ushort((unsigned short *)&(lval),__stm_desc)
00151 #define STM_READ_UI(lval) stm_read_uint((unsigned int *)&(lval),__stm_desc)
00152 #define STM_READ_UL(lval) stm_read_ulong((unsigned long *)&(lval),__stm_desc)
00153 #define STM_READ_ULL(lval) stm_read_ull((unsigned long long *)&(lval),__stm_desc)
00154
00155 #define STM_WRITE_P(lval,rval) stm_write_ptr((void **)(void *)&(lval),(void *)(rval),__stm_desc)
00156 #define STM_WRITE_F(lval,rval) stm_write_float((float *)&(lval),rval,__stm_desc)
00157 #define STM_WRITE_D(lval,rval) stm_write_double((double *)&(lval),rval,__stm_desc)
00158 #define STM_WRITE_C(lval,rval) stm_write_char((char *)&(lval),rval,__stm_desc)
00159 #define STM_WRITE_S(lval,rval) stm_write_short((short *)&(lval),rval,__stm_desc)
00160 #define STM_WRITE_I(lval,rval) stm_write_int((int *)&(lval),rval,__stm_desc)
00161 #define STM_WRITE_L(lval,rval) stm_write_long((long *)&(lval),rval,__stm_desc)
00162 #define STM_WRITE_LL(lval,rval) stm_write_ll((long long *)&(lval),rval,__stm_desc)
00163 #define STM_WRITE_UC(lval,rval) stm_write_uchar((unsigned char *)&(lval),rval,__stm_desc)
00164 #define STM_WRITE_US(lval,rval) stm_write_ushort((unsigned short *)&(lval),rval,__stm_desc)
00165 #define STM_WRITE_UI(lval,rval) stm_write_uint((unsigned int *)&(lval),rval,__stm_desc)
00166 #define STM_WRITE_UL(lval,rval) stm_write_ulong((unsigned long *)&(lval),rval,__stm_desc)
00167 #define STM_WRITE_ULL(lval,rval) stm_write_ull((unsigned long long *)&(lval),rval,__stm_desc)
00168
00169 INLINE void * stm_read_ptr(void * volatile * addr,void * mydesc);
00170 INLINE float stm_read_float(float volatile * addr,void * mydesc);
00171 INLINE double stm_read_double(double volatile * addr,void * mydescy);
00172 INLINE char stm_read_char(char volatile * addr,void * mydesc);
00173 INLINE short stm_read_short(short volatile * addr,void * mydesc);
00174 INLINE int stm_read_int(int volatile * addr,void * mydesc);
00175 INLINE long stm_read_long(long volatile * addr,void * mydesc);
00176 INLINE long long stm_read_ll(long long volatile * addr,void * mydesc);
00177 INLINE unsigned char stm_read_uchar(unsigned char volatile * addr,void * mydesc);
00178 INLINE unsigned short stm_read_ushort(unsigned short volatile * addr,void * mydesc);
00179 INLINE unsigned int stm_read_uint(unsigned int volatile * addr,void * mydesc);
00180 INLINE unsigned long stm_read_ulong(unsigned long volatile * addr,void * mydesc);
00181 INLINE unsigned long long stm_read_ull(unsigned long long volatile * addr,void * mydesc);
00182
00183 INLINE void stm_write_ptr(void * volatile * addr, void * val,void * mydesc);
00184 INLINE void stm_write_float(float volatile * addr, float val,void * mydesc);
00185 INLINE void stm_write_double(double volatile * addr, double val,void * mydesc);
00186 INLINE void stm_write_char(char volatile * addr, char val,void * mydesc);
00187 INLINE void stm_write_short(short volatile * addr, short val,void * mydesc);
00188 INLINE void stm_write_int(int volatile * addr, int val,void * mydesc);
00189 INLINE void stm_write_long(long volatile * addr, long val,void * mydesc);
00190 INLINE void stm_write_ll(long long volatile * addr, long long val,void * mydesc);
00191 INLINE void stm_write_uchar(unsigned char volatile * addr, unsigned char val,void * mydesc);
00192 INLINE void stm_write_ushort(unsigned short volatile * addr, unsigned short val,void * mydesc);
00193 INLINE void stm_write_uint(unsigned int volatile * addr, unsigned int val,void * mydesc);
00194 INLINE void stm_write_ulong(unsigned long volatile * addr, unsigned long val,void * mydesc);
00195 INLINE void stm_write_ull(unsigned long long volatile * addr, unsigned long long val,void * mydesc);
00196
00197 INLINE void * stm_read_key_ptr(void * volatile * addr,void * key,void * mydesc);
00198 INLINE float stm_read_key_float(float volatile * addr,void * key,void * mydesc);
00199 INLINE double stm_read_key_double(double volatile * addr,void * key,void * mydescy);
00200 INLINE char stm_read_key_char(char volatile * addr,void * key,void * mydesc);
00201 INLINE short stm_read_key_short(short volatile * addr,void * key,void * mydesc);
00202 INLINE int stm_read_key_int(int volatile * addr,void * key,void * mydesc);
00203 INLINE long stm_read_key_long(long volatile * addr,void * key,void * mydesc);
00204 INLINE long long stm_read_key_ll(long long volatile * addr,void * key,void * mydesc);
00205 INLINE unsigned char stm_read_key_uchar(unsigned char volatile * addr,void * key,void * mydesc);
00206 INLINE unsigned short stm_read_key_ushort(unsigned short volatile * addr,void * key,void * mydesc);
00207 INLINE unsigned int stm_read_key_uint(unsigned int volatile * addr,void * key,void * mydesc);
00208 INLINE unsigned long stm_read_key_ulong(unsigned long volatile * addr,void * key,void * mydesc);
00209 INLINE unsigned long long stm_read_key_ull(unsigned long long volatile * addr,void * key,void * mydesc);
00210
00211 INLINE void stm_write_key_ptr(void * volatile * addr,void * key, void * val,void * mydesc);
00212 INLINE void stm_write_key_float(float volatile * addr,void * key, float val,void * mydesc);
00213 INLINE void stm_write_key_double(double volatile * addr,void * key, double val,void * mydesc);
00214 INLINE void stm_write_key_char(char volatile * addr,void * key, char val,void * mydesc);
00215 INLINE void stm_write_key_short(short volatile * addr,void * key, short val,void * mydesc);
00216 INLINE void stm_write_key_int(int volatile * addr,void * key, int val,void * mydesc);
00217 INLINE void stm_write_key_long(long volatile * addr,void * key, long val,void * mydesc);
00218 INLINE void stm_write_key_ll(long long volatile * addr,void * key, long long val,void * mydesc);
00219 INLINE void stm_write_key_uchar(unsigned char volatile * addr,void * key, unsigned char val,void * mydesc);
00220 INLINE void stm_write_key_ushort(unsigned short volatile * addr,void * key, unsigned short val,void * mydesc);
00221 INLINE void stm_write_key_uint(unsigned int volatile * addr,void * key, unsigned int val,void * mydesc);
00222 INLINE void stm_write_key_ulong(unsigned long volatile * addr,void * key, unsigned long val,void * mydesc);
00223 INLINE void stm_write_key_ull(unsigned long long volatile * addr,void * key, unsigned long long val,void * mydesc);
00224
00225 void stm_copy_block(char volatile * to, char volatile * from, int count, void * mydesc);
00226 void stm_read_block(char * to, char volatile * from, int count, void * mydesc);
00227 void stm_write_block(char volatile * to, char * from, int count, void * mydesc);
00228 void stm_set_block(char volatile * addr, int c, int count, void * mydesc);
00229
00230 void stm_retry(void * mydesc);
00231
00232 void stm_retire();
00233 void stm_print_time_prof();
00234 void stm_stats_out();
00235 void stm_print_stats();
00236
00237 #ifdef INLINED
00238 #include "stm.c"
00239 #endif
00240
00241 #ifdef __cplusplus
00242 }
00243 #endif
00244
00245 #endif
00246