[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdevplatform] /: Use QMutexLocker where appropriate, use (un)lock_Inline_ elswhere.
From: Milian Wolff <mail () milianw ! de>
Date: 2013-08-01 0:09:23
Message-ID: E1V4gSJ-0007KR-3A () scm ! kde ! org
[Download RAW message or body]
Git commit 3ed783ab3e4e2ea188997cd086208b73608dde03 by Milian Wolff.
Committed on 01/08/2013 at 00:05.
Pushed by mwolff into branch 'master'.
Use QMutexLocker where appropriate, use (un)lock_Inline_ elswhere.
The latter is what QMutexLocker also does, thus we should do the same.
The latter will only be a difference on release builds with the
QT_NO_DEBUG define set though.
M +6 -6 interfaces/foregroundlock.cpp
M +4 -4 language/duchain/appendedlist.h
M +14 -13 language/duchain/duchain.cpp
M +2 -5 language/duchain/duchainbase.cpp
M +2 -2 language/duchain/repositories/itemrepository.h
M +5 -7 language/util/setrepository.cpp
M +2 -4 util/spinlock.h
http://commits.kde.org/kdevplatform/3ed783ab3e4e2ea188997cd086208b73608dde03
diff --git a/interfaces/foregroundlock.cpp b/interfaces/foregroundlock.cpp
index 01c6213..47645a7 100644
--- a/interfaces/foregroundlock.cpp
+++ b/interfaces/foregroundlock.cpp
@@ -44,12 +44,12 @@ public:
~SimplePThreadMutex() {
pthread_mutex_destroy(&m_mutex);
}
- void lock() {
+ void lockInline() {
int result = pthread_mutex_lock(&m_mutex);
Q_ASSERT(result == 0);
Q_UNUSED(result);
}
- void unlock() {
+ void unlockInline() {
int result = pthread_mutex_unlock(&m_mutex);
Q_ASSERT(result == 0);
Q_UNUSED(result);
@@ -101,7 +101,7 @@ void lockForegroundMutexInternal() {
// We already have the mutex
++recursion;
}else{
- internalMutex.lock();
+ internalMutex.lockInline();
Q_ASSERT(recursion == 0 && holderThread == 0);
holderThread = QThread::currentThread();
recursion = 1;
@@ -134,7 +134,7 @@ void unlockForegroundMutexInternal() {
if(recursion == 0)
{
holderThread = 0;
- internalMutex.unlock();
+ internalMutex.unlockInline();
}
}
}
@@ -166,13 +166,13 @@ void KDevelop::ForegroundLock::relock()
public:
virtual void doInternal() {
// By locking the mutex, we make sure that the requester is \
actually waiting for the condition
- waitMutex.lock();
+ waitMutex.lockInline();
// Now we release the foreground lock
TemporarilyReleaseForegroundLock release;
// And signalize to the requester that we've released it
condition.wakeAll();
// Allow the requester to actually wake up, by unlocking \
m_waitMutex
- waitMutex.unlock();
+ waitMutex.unlockInline();
// Now wait until the requester is ready
QMutexLocker lock(&finishMutex);
}
diff --git a/language/duchain/appendedlist.h b/language/duchain/appendedlist.h
index d482f0d..aa1b486 100644
--- a/language/duchain/appendedlist.h
+++ b/language/duchain/appendedlist.h
@@ -94,7 +94,7 @@ class TemporaryDataManager {
uint alloc() {
if(threadSafe)
- m_mutex.lock();
+ m_mutex.lockInline();
uint ret;
if(!m_freeIndicesWithData.isEmpty()) {
@@ -141,7 +141,7 @@ class TemporaryDataManager {
}
if(threadSafe)
- m_mutex.unlock();
+ m_mutex.unlockInline();
Q_ASSERT(!(ret & DynamicAppendedListMask));
@@ -153,7 +153,7 @@ class TemporaryDataManager {
index &= KDevelop::DynamicAppendedListRevertMask;
if(threadSafe)
- m_mutex.lock();
+ m_mutex.lockInline();
freeItem(m_items[index]);
@@ -170,7 +170,7 @@ class TemporaryDataManager {
}
if(threadSafe)
- m_mutex.unlock();
+ m_mutex.unlockInline();
}
uint usedItemCount() const {
diff --git a/language/duchain/duchain.cpp b/language/duchain/duchain.cpp
index a3e4b97..f9f0238 100644
--- a/language/duchain/duchain.cpp
+++ b/language/duchain/duchain.cpp
@@ -266,10 +266,11 @@ class DUChainPrivate
}
void stopThread() {
- m_waitMutex.lock();
- m_stopRunning = true;
- m_wait.wakeAll(); //Wakes the thread up, so it notices it should exit
- m_waitMutex.unlock();
+ {
+ QMutexLocker lock(&m_waitMutex);
+ m_stopRunning = true;
+ m_wait.wakeAll(); //Wakes the thread up, so it notices it should exit
+ }
wait();
}
@@ -279,9 +280,8 @@ class DUChainPrivate
for(uint s = 0; s < cleanupEverySeconds; ++s) {
if(m_stopRunning)
break;
- m_waitMutex.lock();
+ QMutexLocker lock(&m_waitMutex);
m_wait.wait(&m_waitMutex, 1000);
- m_waitMutex.unlock();
}
if(m_stopRunning)
break;
@@ -465,12 +465,13 @@ public:
info->makeDynamic(); //By doing this, we make sure the data is actually being \
destroyed in the destructor
- m_chainsMutex.lock();
- bool removed = m_fileEnvironmentInformations.remove(info->url(), info);
-
- bool removed2 = \
m_indexEnvironmentInformations.remove(info->indexedTopContext().index());
-
- m_chainsMutex.unlock();
+ bool removed = false;
+ bool removed2 = false;
+ {
+ QMutexLocker lock(&m_chainsMutex);
+ removed = m_fileEnvironmentInformations.remove(info->url(), info);
+ removed2 = m_indexEnvironmentInformations.remove(info->indexedTopContext().index());
+ }
{
//Remove it from the environment information lists if it was there
@@ -1672,7 +1673,7 @@ KDevelop::ReferencedTopDUContext DUChain::waitForUpdate(const \
KDevelop::IndexedS
WaitForUpdate waiter;
- waiter.m_dataMutex.lock();
+ waiter.m_dataMutex.lockInline();
{
DUChainReadLocker readLock(DUChain::lock());
diff --git a/language/duchain/duchainbase.cpp b/language/duchain/duchainbase.cpp
index 62a25ec..062c69a 100644
--- a/language/duchain/duchainbase.cpp
+++ b/language/duchain/duchainbase.cpp
@@ -235,21 +235,18 @@ QMutex shouldCreateConstantDataStorageMutex;
QSet<QThread*> shouldCreateConstantDataStorage;
bool DUChainBaseData::shouldCreateConstantData() {
- shouldCreateConstantDataStorageMutex.lock();
+ QMutexLocker lock(&shouldCreateConstantDataStorageMutex);
bool ret = shouldCreateConstantDataStorage.contains( QThread::currentThread() );
- shouldCreateConstantDataStorageMutex.unlock();
return ret;
}
void DUChainBaseData::setShouldCreateConstantData(bool should) {
- shouldCreateConstantDataStorageMutex.lock();
+ QMutexLocker lock(&shouldCreateConstantDataStorageMutex);
if(should)
shouldCreateConstantDataStorage.insert(QThread::currentThread());
else
shouldCreateConstantDataStorage.remove(QThread::currentThread());
-
- shouldCreateConstantDataStorageMutex.unlock();
}
}
diff --git a/language/duchain/repositories/itemrepository.h \
b/language/duchain/repositories/itemrepository.h index bea4a69..db72f61 100644
--- a/language/duchain/repositories/itemrepository.h
+++ b/language/duchain/repositories/itemrepository.h
@@ -1031,10 +1031,10 @@ struct Locker { //This is a dummy that does nothing
template<>
struct Locker<true> {
Locker(QMutex* mutex) : m_mutex(mutex) {
- m_mutex->lock();
+ m_mutex->lockInline();
}
~Locker() {
- m_mutex->unlock();
+ m_mutex->unlockInline();
}
QMutex* m_mutex;
};
diff --git a/language/util/setrepository.cpp b/language/util/setrepository.cpp
index 748a3e5..d24e7a9 100644
--- a/language/util/setrepository.cpp
+++ b/language/util/setrepository.cpp
@@ -430,7 +430,7 @@ Set::Iterator& Set::Iterator::operator++() {
Q_ASSERT(d->nodeStackSize);
if(d->repository->m_mutex)
- d->repository->m_mutex->lock();
+ d->repository->m_mutex->lockInline();
++d->currentIndex;
@@ -457,7 +457,7 @@ Set::Iterator& Set::Iterator::operator++() {
Q_ASSERT(d->nodeStackSize == 0 || d->currentIndex < d->nodeStack[0]->end());
if(d->repository->m_mutex)
- d->repository->m_mutex->unlock();
+ d->repository->m_mutex->unlockInline();
return *this;
}
@@ -1060,10 +1060,10 @@ BasicSetRepository* Set::repository() const {
void Set::staticRef() {
if(!m_tree)
return;
- m_repository->m_mutex->lock();
+
+ QMutexLocker lock(m_repository->m_mutex);
SetNodeData* data = \
m_repository->dataRepository.dynamicItemFromIndexSimple(m_tree); ++data->m_refCount;
- m_repository->m_mutex->unlock();
}
///Mutex must be locked
@@ -1096,11 +1096,9 @@ void Set::staticUnref() {
if(!m_tree)
return;
- m_repository->m_mutex->lock();
+ QMutexLocker lock(m_repository->m_mutex);
unrefNode(m_tree);
-
- m_repository->m_mutex->unlock();
}
StringSetRepository::StringSetRepository(QString name) : \
Utils::BasicSetRepository(name) {
diff --git a/util/spinlock.h b/util/spinlock.h
index 81c753d..cbdb904 100644
--- a/util/spinlock.h
+++ b/util/spinlock.h
@@ -81,20 +81,18 @@ class SpinLock
}
//We need to wait now
- m_data.waitingMutex.lock();
+ QMutexLocker lock(&m_data.waitingMutex);
m_data.needWake = true;
m_data.waitingCondition.wait(&m_data.waitingMutex, mSleep);
- m_data.waitingMutex.unlock();
}
}else{
//No timeout
while(!m_data.lock.testAndSetOrdered(0, 1))
{
//We need to wait now
- m_data.waitingMutex.lock();
+ QMutexLocker lock(&m_data.waitingMutex);
m_data.needWake = true;
m_data.waitingCondition.wait(&m_data.waitingMutex, mSleep);
- m_data.waitingMutex.unlock();
}
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic