Commit 76675634 authored by Yoni Fogel's avatar Yoni Fogel

[t:2216] Windows port of 2216 Showed that windows fetch_and_increment was...

[t:2216] Windows port of 2216 Showed that windows fetch_and_increment was returning incremented (not original) result.
Atomic functions now return the original

git-svn-id: file:///svn/toku/tokudb@18187 c7de825b-a66e-492c-adef-691d508d4ae1
parent 1a23a7fe
......@@ -10,12 +10,18 @@ toku_sync_fetch_and_add_uint32(volatile uint32_t *a, uint32_t b) {
static inline uint32_t
toku_sync_fetch_and_increment_uint32(volatile uint32_t *a) {
return _InterlockedIncrement((LONG*)a);
uint32_t r = _InterlockedIncrement((LONG*)a);
//InterlockedIncrement returns the result, not original.
//Return the original.
return r - 1;
}
static inline uint32_t
toku_sync_fetch_and_decrement_uint32(volatile uint32_t *a) {
return _InterlockedDecrement((LONG*)a);
uint32_t r = _InterlockedDecrement((LONG*)a);
//InterlockedDecrement returns the result, not original.
//Return the original.
return r + 1;
}
static inline int32_t
......@@ -53,19 +59,22 @@ toku_sync_fetch_and_add_uint64(volatile uint64_t *a, uint64_t b) {
//Temporarily just use 32 bit atomic instructions (treat the values as 32
//bit only). For now this is ok, the values are only used in show engine
//status.
return _InterlockedExchangeAdd((LONG*)a, b);
return toku_sync_fetch_and_add_uint32((uint32_t*)a, b);
#endif
}
static inline uint64_t
toku_sync_fetch_and_increment_uint64(volatile uint64_t *a) {
#if TOKU_WINDOWS_HAS_ATOMIC_64
return _InterlockedIncrement64((int64_t*)a);
uint64_t r = _InterlockedIncrement64((int64_t*)a);
//InterlockedIncrement64 returns the result, not original.
//Return the original.
return r - 1;
#else
//Temporarily just use 32 bit atomic instructions (treat the values as 32
//bit only). For now this is ok, the values are only used in show engine
//status.
return _InterlockedIncrement((LONG*)a);
return toku_sync_fetch_and_increment_uint32((uint32_t*)a);
#endif
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment