move gcc atomic stuff into centralized location, add methods for atomically manipulating 64 bit integers (since 32 bit machines need gcc to emit special instructions)

This commit is contained in:
Sears Russell 2011-07-15 17:34:44 +00:00
parent 9244d4607f
commit 852c46b97b
2 changed files with 21 additions and 10 deletions

View file

@ -10,15 +10,6 @@
#include <stasis/page.h>
#include <stasis/experimental/latchFree/lfSlotted.h>
#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);
}

View file

@ -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 */