Btk
atomic.hpp
1 #if !defined(_BTKIMPL_ATOMIC_HPP_)
2 #define _BTKIMPL_ATOMIC_HPP_
3 #include <SDL2/SDL_atomic.h>
4 namespace Btk{
5  //a wrapper for SDL_atomic_t
6  struct Atomic{
7  Atomic():value({}){}
8  //default value
9  Atomic(int val){
10  SDL_AtomicSet(&value,val);
11  }
12  mutable SDL_atomic_t value;
13  Atomic &operator =(int val){
14  SDL_AtomicSet(&value,val);
15  return *this;
16  }
17  Atomic &operator ++(){
18  SDL_AtomicIncRef(&value);
19  return *this;
20  }
21  Atomic &operator --(){
22  SDL_AtomicDecRef(&value);
23  return *this;
24  }
25  operator int() const noexcept{
26  return SDL_AtomicGet(&value);
27  }
28  //like normal int
29  Atomic operator +(int value) const noexcept{
30  return Atomic(static_cast<int>(*this) + value);
31  }
32  Atomic operator -(int value) const noexcept{
33  return Atomic(static_cast<int>(*this) - value);
34  }
35  Atomic operator *(int value) const noexcept{
36  return Atomic(static_cast<int>(*this) * value);
37  }
38  Atomic operator /(int value) const noexcept{
39  return Atomic(static_cast<int>(*this) / value);
40  }
41  Atomic &operator -=(int value) noexcept{
42  SDL_AtomicAdd(&(this->value),-value);
43  return *this;
44  };
45  Atomic &operator +=(int value) noexcept{
46  SDL_AtomicAdd(&(this->value),value);
47  return *this;
48  };
49  };
50 };
51 
52 #endif // _BTKIMPL_ATOMIC_HPP_
Definition: atomic.hpp:6
This header include many useful containers.
Definition: async.hpp:7