Added an atomic<int> to the reference counter for thread saftey
This commit is contained in:
parent
fe7fd6b0b3
commit
5eec570768
|
@ -12,6 +12,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
namespace Utility
|
namespace Utility
|
||||||
{
|
{
|
||||||
|
@ -110,12 +111,12 @@ namespace Utility
|
||||||
struct ReferenceCount
|
struct ReferenceCount
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int count;
|
std::atomic<int> count;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ReferenceCount() :count(0) { }
|
ReferenceCount() :count(0) { }
|
||||||
ReferenceCount(const ReferenceCount& o) { count = o.count; }
|
ReferenceCount(const ReferenceCount& o) { count.store(o.count); }
|
||||||
inline const ReferenceCount& operator=(const ReferenceCount& o) { count = o.count; return *this;}
|
inline const ReferenceCount& operator=(const ReferenceCount& o) { count.store(o.count); return *this;}
|
||||||
inline void Incref() { this->count++; }
|
inline void Incref() { this->count++; }
|
||||||
inline void Incref(int c) { this->count += c; }
|
inline void Incref(int c) { this->count += c; }
|
||||||
inline int Decref() { return --this->count;}
|
inline int Decref() { return --this->count;}
|
||||||
|
|
Loading…
Reference in New Issue