mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +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 {
|
||||
QByteArray result;
|
||||
assertUnlocked();
|
||||
withReadLock([&] {
|
||||
result = getActionDataInternal();
|
||||
});
|
||||
|
||||
if (_actionDataDirty) {
|
||||
withWriteLock([&] {
|
||||
getActionDataInternal();
|
||||
result = _allActionsDataCache;
|
||||
});
|
||||
} else {
|
||||
withReadLock([&] {
|
||||
result = _allActionsDataCache;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
class ReadWriteLockable {
|
||||
public:
|
||||
template <typename F>
|
||||
bool withWriteLock(F f, bool require = true) {
|
||||
bool withWriteLock(F f, bool require = true) const {
|
||||
if (!require) {
|
||||
bool result = _lock.tryLockForWrite();
|
||||
if (result) {
|
||||
|
@ -22,7 +22,7 @@ public:
|
|||
_lock.unlock();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
QWriteLocker locker(&_lock);
|
||||
f();
|
||||
|
@ -30,7 +30,7 @@ public:
|
|||
}
|
||||
|
||||
template <typename F>
|
||||
bool withTryWriteLock(F f) {
|
||||
bool withTryWriteLock(F f) const {
|
||||
return withWriteLock(f, false);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue