mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 03:08:00 +02:00
Merge pull request #6203 from sethalves/fix-action-crash
adjust locking in EntityItem::getActionDataInternal
This commit is contained in:
commit
61e35d7ada
2 changed files with 14 additions and 6 deletions
|
@ -1790,9 +1790,17 @@ const QByteArray EntityItem::getActionDataInternal() const {
|
||||||
const QByteArray EntityItem::getActionData() const {
|
const QByteArray EntityItem::getActionData() const {
|
||||||
QByteArray result;
|
QByteArray result;
|
||||||
assertUnlocked();
|
assertUnlocked();
|
||||||
withReadLock([&] {
|
|
||||||
result = getActionDataInternal();
|
if (_actionDataDirty) {
|
||||||
});
|
withWriteLock([&] {
|
||||||
|
getActionDataInternal();
|
||||||
|
result = _allActionsDataCache;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
withReadLock([&] {
|
||||||
|
result = _allActionsDataCache;
|
||||||
|
});
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
class ReadWriteLockable {
|
class ReadWriteLockable {
|
||||||
public:
|
public:
|
||||||
template <typename F>
|
template <typename F>
|
||||||
bool withWriteLock(F f, bool require = true) {
|
bool withWriteLock(F f, bool require = true) const {
|
||||||
if (!require) {
|
if (!require) {
|
||||||
bool result = _lock.tryLockForWrite();
|
bool result = _lock.tryLockForWrite();
|
||||||
if (result) {
|
if (result) {
|
||||||
|
@ -22,7 +22,7 @@ public:
|
||||||
_lock.unlock();
|
_lock.unlock();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWriteLocker locker(&_lock);
|
QWriteLocker locker(&_lock);
|
||||||
f();
|
f();
|
||||||
|
@ -30,7 +30,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
bool withTryWriteLock(F f) {
|
bool withTryWriteLock(F f) const {
|
||||||
return withWriteLock(f, false);
|
return withWriteLock(f, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue