19 #include <QtCore/QMutex>
20 #include <QtCore/QHash>
21 #include <QtCore/QAtomicInt>
23 #include "objectstore_p.h"
30 QHash<const void *, QAtomicInt> refCount;
34 Q_GLOBAL_STATIC(GlobalStore, globalStore)
39 bool ObjectStore::put(
const void * ptr)
41 bool mustAddStrongRef =
false;
42 GlobalStore *
const gs = globalStore();
43 if (!gs)
return mustAddStrongRef;
45 QMutexLocker lock(&gs->mutex);
46 if (!gs->refCount.contains(ptr)) {
47 gs->refCount.insert(ptr, QAtomicInt(0));
48 mustAddStrongRef =
true;
50 (gs->refCount[ptr]).ref();
52 return mustAddStrongRef;
55 bool ObjectStore::take(
const void * ptr)
57 bool mustSubtractStrongRef =
false;
58 GlobalStore *
const gs = globalStore();
59 if (!gs)
return mustSubtractStrongRef;
61 QMutexLocker lock(&gs->mutex);
64 Q_ASSERT(gs->refCount.contains(ptr));
66 if (!gs->refCount.contains(ptr)) {
71 (gs->refCount[ptr]).deref();
73 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
74 if (!gs->refCount[ptr].load()) {
76 if (!gs->refCount[ptr]) {
79 gs->refCount.remove(ptr);
80 mustSubtractStrongRef =
true;
82 return mustSubtractStrongRef;
85 bool ObjectStore::isEmpty()
87 GlobalStore *
const gs = globalStore();
90 QMutexLocker lock(&gs->mutex);
92 if (gs->refCount.count()>0) {
Wrappers for GStreamer classes.