mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Remove our own atomic type in favor of std::atomic
This commit is contained in:
+2
-2
@@ -13,6 +13,6 @@
|
||||
|
||||
// what a waste of a source file...
|
||||
|
||||
AtomicInt Age::new_age(2);
|
||||
atomic<Age::age_t> Age::new_age(2);
|
||||
|
||||
IMPLEMENT_DYNAMIC_ARG(AtomicIntEquiv, last_update_age, 0);
|
||||
IMPLEMENT_DYNAMIC_ARG(Age::age_t, last_update_age, 0);
|
||||
|
||||
+11
-8
@@ -10,14 +10,17 @@
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <util/dynamic_arg.hpp>
|
||||
#include <util/atomic.hpp>
|
||||
#include <cstdint>
|
||||
#include <atomic>
|
||||
|
||||
// ----------------------------------------------------------------------------- : Age
|
||||
|
||||
/// Represents the age of a value, higher values are newer
|
||||
/** Age is counted using a global variable */
|
||||
class Age {
|
||||
public:
|
||||
public:
|
||||
typedef uint_fast64_t age_t;
|
||||
|
||||
/// Construct a new age value
|
||||
Age() {
|
||||
update();
|
||||
@@ -27,7 +30,7 @@ class Age {
|
||||
* 1: before 'beginning of time', the age conceptually just before program start
|
||||
* 2..: normal ages
|
||||
*/
|
||||
Age(AtomicIntEquiv age) : age(age) {}
|
||||
Age(age_t age) : age(age) {}
|
||||
|
||||
/// Update the age to become the newest one
|
||||
inline void update() {
|
||||
@@ -40,13 +43,13 @@ class Age {
|
||||
inline bool operator == (Age a) const { return age == a.age; }
|
||||
|
||||
/// A number corresponding to the age
|
||||
inline AtomicIntEquiv get() const { return age; }
|
||||
inline age_t get() const { return age; }
|
||||
|
||||
private:
|
||||
private:
|
||||
/// This age
|
||||
AtomicIntEquiv age;
|
||||
age_t age;
|
||||
/// Global age counter, value of the last age created
|
||||
static AtomicInt new_age;
|
||||
static atomic<age_t> new_age;
|
||||
};
|
||||
|
||||
|
||||
@@ -56,5 +59,5 @@ class Age {
|
||||
* if last_update_age > 0 they return whether the image is still up to date
|
||||
* if last_update_age == 0 they generate the image
|
||||
*/
|
||||
DECLARE_DYNAMIC_ARG (AtomicIntEquiv, last_update_age);
|
||||
DECLARE_DYNAMIC_ARG(Age::age_t, last_update_age);
|
||||
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) Twan van Laarhoven and the other MSE developers |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
#pragma once
|
||||
|
||||
/** @file util/atomic.hpp
|
||||
*
|
||||
* @brief Provides the type AtomicInt, which is an integer that can be incremented and decremented atomicly
|
||||
*/
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
// ----------------------------------------------------------------------------- : AtomicInt : windows
|
||||
|
||||
#if defined(__WXMSW__)
|
||||
#ifdef _MSC_VER
|
||||
extern "C" {
|
||||
LONG __cdecl _InterlockedIncrement(LONG volatile *Addend);
|
||||
LONG __cdecl _InterlockedDecrement(LONG volatile *Addend);
|
||||
}
|
||||
#pragma intrinsic (_InterlockedIncrement)
|
||||
#define InterlockedIncrement _InterlockedIncrement
|
||||
#pragma intrinsic (_InterlockedDecrement)
|
||||
#define InterlockedDecrement _InterlockedDecrement
|
||||
#endif
|
||||
|
||||
/// An integer which is equivalent to an AtomicInt, but which doesn't support attomic operations
|
||||
typedef LONG AtomicIntEquiv;
|
||||
|
||||
/// An integer that can be incremented and decremented atomicly
|
||||
class AtomicInt {
|
||||
public:
|
||||
AtomicInt(AtomicIntEquiv v) : v(v) {}
|
||||
inline operator AtomicIntEquiv() const {
|
||||
return v;
|
||||
}
|
||||
/// Attomicly increments this AtomicInt, returns the new value
|
||||
inline AtomicIntEquiv operator ++ () {
|
||||
return InterlockedIncrement(&v);
|
||||
}
|
||||
/// Attomicly decrements this AtomicInt, returns the new value
|
||||
inline AtomicIntEquiv operator -- () {
|
||||
return InterlockedDecrement(&v);
|
||||
}
|
||||
private:
|
||||
AtomicIntEquiv v; ///< The value
|
||||
};
|
||||
|
||||
/// We have a fast AtomicInt
|
||||
#define HAVE_FAST_ATOMIC
|
||||
|
||||
// ----------------------------------------------------------------------------- : AtomicInt : GCC
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
/// An integer which is equivalent to an AtomicInt, but which doesn't support attomic operations
|
||||
typedef unsigned int AtomicIntEquiv;
|
||||
|
||||
/// An integer that can be incremented and decremented atomicly
|
||||
class AtomicInt {
|
||||
public:
|
||||
AtomicInt(AtomicIntEquiv v) : v(v) {}
|
||||
inline operator AtomicIntEquiv() const {
|
||||
return v;
|
||||
}
|
||||
inline AtomicInt operator ++ () {
|
||||
return __sync_add_and_fetch(&v,1);
|
||||
}
|
||||
inline AtomicInt operator -- () {
|
||||
return __sync_sub_and_fetch(&v,1);
|
||||
}
|
||||
private:
|
||||
AtomicIntEquiv v;
|
||||
};
|
||||
|
||||
/// We have a fast AtomicInt
|
||||
#define HAVE_FAST_ATOMIC
|
||||
|
||||
// ----------------------------------------------------------------------------- : AtomicInt : portable
|
||||
#else
|
||||
|
||||
/// An integer which is equivalent to an AtomicInt, but which doesn't support attomic operations
|
||||
typedef long AtomicIntEquiv;
|
||||
|
||||
/// An integer that can be incremented and decremented atomicly
|
||||
class AtomicInt {
|
||||
public:
|
||||
AtomicInt(AtomicIntEquiv v) : v(v) {}
|
||||
AtomicInt(const AtomicInt& i) {
|
||||
wxCriticalSectionLocker lock(i.cs);
|
||||
v = i.v;
|
||||
}
|
||||
inline operator AtomicIntEquiv() const {
|
||||
return v;
|
||||
}
|
||||
/// Attomicly increments this AtomicInt, returns the new value
|
||||
inline AtomicIntEquiv operator ++ () {
|
||||
wxCriticalSectionLocker lock(cs);
|
||||
return ++v;
|
||||
}
|
||||
/// Attomicly decrements this AtomicInt, returns the new value
|
||||
inline AtomicIntEquiv operator -- () {
|
||||
wxCriticalSectionLocker lock(cs);
|
||||
return --v;
|
||||
}
|
||||
private:
|
||||
AtomicIntEquiv v; ///< The value
|
||||
mutable wxCriticalSection cs; ///< Critical section protecting v
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user