mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 09:44:21 +02:00
The weak shared object hash can be accessed by multiple threads, so it must
be locked.
This commit is contained in:
parent
469e31cc05
commit
ce0210bf04
2 changed files with 10 additions and 0 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <QItemEditorFactory>
|
||||
#include <QMetaProperty>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWriteLocker>
|
||||
|
||||
#include "Bitstream.h"
|
||||
#include "MetavoxelUtil.h"
|
||||
|
@ -27,10 +28,12 @@ SharedObject::SharedObject() :
|
|||
_remoteID(0),
|
||||
_remoteOriginID(0) {
|
||||
|
||||
QWriteLocker locker(&_weakHashLock);
|
||||
_weakHash.insert(_id, this);
|
||||
}
|
||||
|
||||
void SharedObject::setID(int id) {
|
||||
QWriteLocker locker(&_weakHashLock);
|
||||
_weakHash.remove(_id);
|
||||
_weakHash.insert(_id = id, this);
|
||||
}
|
||||
|
@ -41,6 +44,7 @@ void SharedObject::incrementReferenceCount() {
|
|||
|
||||
void SharedObject::decrementReferenceCount() {
|
||||
if (!_referenceCount.deref()) {
|
||||
QWriteLocker locker(&_weakHashLock);
|
||||
_weakHash.remove(_id);
|
||||
delete this;
|
||||
}
|
||||
|
@ -127,6 +131,7 @@ void SharedObject::dump(QDebug debug) const {
|
|||
|
||||
int SharedObject::_lastID = 0;
|
||||
WeakSharedObjectHash SharedObject::_weakHash;
|
||||
QReadWriteLock SharedObject::_weakHashLock;
|
||||
|
||||
void pruneWeakSharedObjectHash(WeakSharedObjectHash& hash) {
|
||||
for (WeakSharedObjectHash::iterator it = hash.begin(); it != hash.end(); ) {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <QMetaType>
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QReadWriteLock>
|
||||
#include <QSet>
|
||||
#include <QWidget>
|
||||
#include <QtDebug>
|
||||
|
@ -36,6 +37,9 @@ public:
|
|||
/// Returns the weak hash under which all local shared objects are registered.
|
||||
static const WeakSharedObjectHash& getWeakHash() { return _weakHash; }
|
||||
|
||||
/// Returns a reference to the weak hash lock.
|
||||
static QReadWriteLock& getWeakHashLock() { return _weakHashLock; }
|
||||
|
||||
Q_INVOKABLE SharedObject();
|
||||
|
||||
/// Returns the unique local ID for this object.
|
||||
|
@ -85,6 +89,7 @@ private:
|
|||
|
||||
static int _lastID;
|
||||
static WeakSharedObjectHash _weakHash;
|
||||
static QReadWriteLock _weakHashLock;
|
||||
};
|
||||
|
||||
/// Removes the null references from the supplied hash.
|
||||
|
|
Loading…
Reference in a new issue