diff --git a/src/stasis/experimental/latchFree/lfSlotted.c b/src/stasis/experimental/latchFree/lfSlotted.c index 7501200..1d644d8 100644 --- a/src/stasis/experimental/latchFree/lfSlotted.c +++ b/src/stasis/experimental/latchFree/lfSlotted.c @@ -10,15 +10,6 @@ #include #include -#ifdef HAVE_GCC_ATOMICS -#define CAS(_a,_o,_n) __sync_bool_compare_and_swap(_a,_o,_n) -#define BARRIER() __sync_synchronize() -#define FETCH_AND_ADD(_a, _i) __sync_fetch_and_add(_a, _i) -#else -#define CAS(_a,_o,_n) 1 -#define BARRIER() abort() -#define FETCH_AND_ADD(_a, _i) 1 -#endif static int notSupported(int xid, Page * p) { return 0; } static const byte* lfSlottedRead (int xid, Page *p, recordid rid) { @@ -31,7 +22,7 @@ static byte* lfSlottedWrite(int xid, Page *p, recordid rid) { } static void lfSlottedWriteDone(int xid, Page *p, recordid rid, byte *buf) { BARRIER(); - int succ = CAS(stasis_page_slotted_numslots_ptr(p), rid.slot, rid.slot+1); + int succ = CAS(XXX,stasis_page_slotted_numslots_ptr(p), rid.slot, rid.slot+1); DEBUG("write done %d\n", rid.slot+1); assert(succ); } diff --git a/stasis/util/latches.h b/stasis/util/latches.h index 13c9d0c..990f7ab 100644 --- a/stasis/util/latches.h +++ b/stasis/util/latches.h @@ -109,4 +109,24 @@ void __profile_deletelock (rwl *lock); #endif +#ifdef HAVE_GCC_ATOMICS +#define CAS(mutex,_a,_o,_n) __sync_bool_compare_and_swap(_a,_o,_n) +#define BARRIER() __sync_synchronize() +#define FETCH_AND_ADD(_o,_i) __sync_fetch_and_add(_o,_i) +#if ULONG_MAX <= 4294967295 // are we on a 32 bit machine? +#define ATOMIC_READ_64(mutex,_o) FETCH_AND_ADD(_o,0) +#define ATOMIC_WRITE_64(mutex,_o,_n) _sync_lock_test_and_set(_o,_n) +#else // this is a 33 or greater bit machine. Assume it's 64 bit, and that 64 bit writes are atomic. +#define ATOMIC_READ_64(mutex,_a) *_a +#define ATOMIC_WRITE_64(mutex,_a,_n) do {*_a=_n; } while (0) +#endif +#else +#define CAS(mutex,_a,_o,_n) GCC_ATOMICS_REQUIRED +#define BARRIER() GCC_ATOMICS_REQUIRED +#define FETCH_AND_ADD(_a,_i) GCC_ATOMICS_REQUIRED +#define ATOMIC_READ_64(mutex, _a) GCC_ATOMICS_REQUIRED +#define ATOMIC_WRITE_64(mutex,_a,_n) GCC_ATOMICS_REQUIRED +#endif + + #endif /* __LATCHES_H */