Skip to content

Commit

Permalink
libcore: Use atomic integers for reference counting
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 9, 2017
1 parent e3c289e commit 12ec4cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 3 additions & 2 deletions doomsday/sdk/libcore/include/de/data/counted.h
Expand Up @@ -21,6 +21,7 @@
#define LIBDENG2_COUNTED_H

#include "../libcore.h"
#include <atomic>

namespace de {

Expand Down Expand Up @@ -86,15 +87,15 @@ class DENG2_PUBLIC Counted
public:
/// Number of other things that refer to this object, i.e. have
/// a pointer to it.
mutable dint _refCount;
mutable std::atomic_int _refCount;

private:
template <typename Type>
friend Type *refless(Type *counted);

#ifdef DENG2_DEBUG
public:
static int totalCount; // Number of Counted objects in existence.
static std::atomic_int totalCount; // Number of Counted objects in existence.
# ifdef DENG_USE_COUNTED_TRACING
static void printAllocs();
# endif
Expand Down
3 changes: 1 addition & 2 deletions doomsday/sdk/libcore/src/data/counted.cpp
Expand Up @@ -22,7 +22,7 @@
namespace de {

#ifdef DENG2_DEBUG
int Counted::totalCount = 0; ///< Should return back to zero when program ends.
std::atomic_int Counted::totalCount { 0 }; ///< Should return back to zero when program ends.
# ifdef DENG_USE_COUNTED_TRACING
static QHash<void *, QByteArray> countedAllocs;
void Counted::printAllocs()
Expand Down Expand Up @@ -76,7 +76,6 @@ void Counted::addRef(dint count) const
{
DENG2_ASSERT(_refCount >= 0);
_refCount += count;
DENG2_ASSERT(_refCount >= 0);
}

} // namespace de

0 comments on commit 12ec4cd

Please sign in to comment.