<commit_before>/*
 * Copyright (c) 2015 <NAME>
 * Copyright (c) 2015 <NAME>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

//! @file roc_core/target_gnu/roc_core/atomic.h
//! @brief Atomic integer.

#ifndef ROC_CORE_ATOMIC_H_
#define ROC_CORE_ATOMIC_H_

namespace roc {
namespace core {

//! Atomic integer.
class Atomic : public NonCopyable<> {
public:
    //! Initialize with given value.
    explicit Atomic(long value = 0)
        : value_(value) {
    }

    //! Atomic load.
    operator long() const {
        return __atomic_load_n(&value_, __ATOMIC_SEQ_CST);
    }

    //! Atomic store.
    long operator=(long v) {
        __atomic_store_n(&value_, v, __ATOMIC_SEQ_CST);
        return v;
    }

    //! Atomic increment.
    long operator++() {
        return __atomic_add_fetch(&value_, 1, __ATOMIC_SEQ_CST);
    }

    //! Atomic decrement.
    long operator--() {
        return __atomic_sub_fetch(&value_, 1, __ATOMIC_SEQ_CST);
    }

    //! Atomic test-and-set.
    //! @remarks
    //!  Atomically sets value to non-zero and returns '0' if previous value
    //!  was '0' or '1' otherwise.
    long test_and_set() {
        long expected = 0;
        return __atomic_compare_exchange_n(&value_, &expected, 1, false, __ATOMIC_SEQ_CST,
                                           __ATOMIC_SEQ_CST)
            ? 0
            : 1;
    }

private:
    mutable long value_;
};

} // namespace core
} // namespace roc

#endif // ROC_CORE_ATOMIC_H_<commit_msg>Use legacy __sync builtins from older GCC<commit_after>/*
 * Copyright (c) 2015 <NAME>
 * Copyright (c) 2015 <NAME>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

//! @file roc_core/target_gnu/roc_core/atomic.h
//! @brief Atomic integer.

#ifndef ROC_CORE_ATOMIC_H_
#define ROC_CORE_ATOMIC_H_

namespace roc {
namespace core {

//! Atomic integer.
class Atomic : public NonCopyable<> {
public:
    //! Initialize with given value.
    explicit Atomic(long value = 0)
        : value_(value) {
    }

    //! Atomic load.
    operator long() const {
        return __sync_add_and_fetch(&value_, 0);
    }

    //! Atomic store.
    //! @remarks
    //!  Only boolean values may be implemented in a cross-platform way
    //!  using GCC legacy __sync builtins.
    long operator=(bool v) {
        if (v) {
            __sync_lock_test_and_set(&value_, 1);
        } else {
            __sync_and_and_fetch(&value_, 0);
        }
        return v;
    }

    //! Atomic increment.
    long operator++() {
        return __sync_add_and_fetch(&value_, 1);
    }

    //! Atomic decrement.
    long operator--() {
        return __sync_sub_and_fetch(&value_, 1);
    }

    //! Atomic test-and-set.
    //! @remarks
    //!  Atomically sets value to non-zero and returns '0' if previous value
    //!  was '0' or '1' otherwise.
    long test_and_set() {
        return __sync_bool_compare_and_swap(&value_, 0, 1) ? 0 : 1;
    }

private:
    mutable long value_;
};

} // namespace core
} // namespace roc

#endif // ROC_CORE_ATOMIC_H_
{'fraction_non_alphanumeric': 0.11778846153846154, 'fraction_numerical': 0.014122596153846154, 'mean_word_length': 2.3223552894211577, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2006671', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1075, 'n_words': 315}