<commit_before>#if !defined(TOKU_ATOMIC_H)
#define TOKU_ATOMIC_H

#if TOKU_WINDOWS

static inline uint32_t
toku_sync_fetch_and_add_uint32(volatile uint32_t *a, uint32_t b) {
    return _InterlockedExchangeAdd((LONG*)a, b);
}

static inline uint32_t
toku_sync_fetch_and_increment_uint32(volatile uint32_t *a) {
    return _InterlockedIncrement((LONG*)a);
}

static inline uint32_t
toku_sync_fetch_and_decrement_uint32(volatile uint32_t *a) {
    return _InterlockedDecrement((LONG*)a);
}

static inline int32_t
toku_sync_fetch_and_add_int32(volatile int32_t *a, int32_t b) {
    return _InterlockedExchangeAdd((LONG*)a, b);
}

static inline int32_t
toku_sync_fetch_and_increment_int32(volatile int32_t *a) {
    return _InterlockedIncrement((LONG*)a);
}

static inline int32_t
toku_sync_fetch_and_decrement_int32(volatile int32_t *a) {
    return _InterlockedDecrement((LONG*)a);
}

#define TOKU_WINDOWS_MIN_SUPPORTED_IS_VISTA 0

//Vista has 64 bit atomic instruction functions.
//64 bit windows should also have it, but we're using neither right now.
#if TOKU_WINDOWS_MIN_SUPPORTED_IS_VISTA || defined(_WIN64)
#define TOKU_WINDOWS_HAS_ATOMIC_64 1
#else
#define TOKU_WINDOWS_HAS_ATOMIC_64 0
#endif



static inline uint64_t
toku_sync_fetch_and_add_uint64(volatile uint64_t *a, uint64_t b) {
#if TOKU_WINDOWS_HAS_ATOMIC_64
    return _InterlockedExchangeAdd64((int64_t*)a, b);
#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 _InterlockedExchangeAdd((LONG*)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);
#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);<commit_msg>[t:2216] Windows port of 2216 Showed that windows fetch_and_increment was returning incremented (not original) result. Atomic functions now return the original<commit_after>#if !defined(TOKU_ATOMIC_H)
#define TOKU_ATOMIC_H

#if TOKU_WINDOWS

static inline uint32_t
toku_sync_fetch_and_add_uint32(volatile uint32_t *a, uint32_t b) {
    return _InterlockedExchangeAdd((LONG*)a, b);
}

static inline uint32_t
toku_sync_fetch_and_increment_uint32(volatile uint32_t *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) {
    uint32_t r = _InterlockedDecrement((LONG*)a);
    //InterlockedDecrement returns the result, not original.
    //Return the original.
    return r + 1;
}

static inline int32_t
toku_sync_fetch_and_add_int32(volatile int32_t *a, int32_t b) {
    return _InterlockedExchangeAdd((LONG*)a, b);
}

static inline int32_t
toku_sync_fetch_and_increment_int32(volatile int32_t *a) {
    return _InterlockedIncrement((LONG*)a);
}

static inline int32_t
toku_sync_fetch_and_decrement_int32(volatile int32_t *a) {
    return _InterlockedDecrement((LONG*)a);
}

#define TOKU_WINDOWS_MIN_SUPPORTED_IS_VISTA 0

//Vista has 64 bit atomic instruction functions.
//64 bit windows should also have it, but we're using neither right now.
#if TOKU_WINDOWS_MIN_SUPPORTED_IS_VISTA || defined(_WIN64)
#define TOKU_WINDOWS_HAS_ATOMIC_64 1
#else
#define TOKU_WINDOWS_HAS_ATOMIC_64 0
#endif



static inline uint64_t
toku_sync_fetch_and_add_uint64(volatile uint64_t *a, uint64_t b) {
#if TOKU_WINDOWS_HAS_ATOMIC_64
    return _InterlockedExchangeAdd64((int64_t*)a, b);
#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 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
    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 toku_sync_fetch_and_increment_uint32((uint32_t*)a);
{'fraction_non_alphanumeric': 0.07869142351900972, 'fraction_numerical': 0.04442970822281167, 'mean_word_length': 5.311018131101813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5899732', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1633, 'n_words': 420}