make withWriteLock and withTryWriteLock const

This commit is contained in:
Seth Alves 2015-10-28 13:49:52 -07:00
parent a1096510e8
commit 22d6b6df34
2 changed files with 4 additions and 5 deletions

View file

@ -1792,8 +1792,7 @@ const QByteArray EntityItem::getActionData() const {
assertUnlocked(); assertUnlocked();
if (_actionDataDirty) { if (_actionDataDirty) {
EntityItem* unconstThis = const_cast<EntityItem*>(this); withWriteLock([&] {
unconstThis->withWriteLock([&] {
getActionDataInternal(); getActionDataInternal();
result = _allActionsDataCache; result = _allActionsDataCache;
}); });

View file

@ -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);
} }