From e9c2cce662afb92578c3d2a67e734409bb79bf56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juho=20H=C3=A4m=C3=A4l=C3=A4inen?= Date: Wed, 4 Mar 2015 12:09:30 +0200 Subject: [PATCH] Maintain proper internal state when releasing resources. Previously when releasing resources when resources were in "acquiring" state left the internal status in broken state. Because of this calling acquire() would not really call acquire from Resource Policy. Change the implementation so that client state is always set to Initial when calling release(), but call Resource Policy release() only when no clients are in acquiring or granted state. Change-Id: I7fb84aefb64da84808375515950a28331531a71e --- .../resourcepolicy/resourcepolicyint.cpp | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/plugins/resourcepolicy/resourcepolicyint.cpp b/src/plugins/resourcepolicy/resourcepolicyint.cpp index 8fed062c..56d07fec 100644 --- a/src/plugins/resourcepolicy/resourcepolicyint.cpp +++ b/src/plugins/resourcepolicy/resourcepolicyint.cpp @@ -234,22 +234,40 @@ void ResourcePolicyInt::release(const ResourcePolicyImpl *client) { QMap::iterator i = m_clients.find(client); if (i != m_clients.end()) { - if (i.value().status == GrantedResource) { - i.value().status = Initial; + ResourceStatus oldStatus = i.value().status; + i.value().status = Initial; + +#ifdef RESOURCE_DEBUG + qDebug() << "##### " << i.value().id << ": RELEASE"; +#endif + + if (oldStatus == GrantedResource) { --m_acquired; #ifdef RESOURCE_DEBUG - qDebug() << "##### " << i.value().id << ": RELEASE, acquired (" << m_acquired << ")"; + qDebug() << "##### " << i.value().id << ": RELEASE, acquired (" << m_acquired + << "), emit resourcesReleased()"; #endif emit i.value().client->resourcesReleased(); } - } - if (m_acquired == 0 && m_status != Initial) { + if (m_acquired == 0 && m_status != Initial) { + QMap::const_iterator c = m_clients.constBegin(); + int active = 0; + + while (c != m_clients.constEnd()) { + if (c.value().status != Initial) + ++active; + ++c; + } + + if (active == 0) { #ifdef RESOURCE_DEBUG - qDebug() << "##### " << i.value().id << ": RELEASE call resourceSet->release()"; + qDebug() << "##### " << i.value().id << ": RELEASE call resourceSet->release()"; #endif - m_resourceSet->release(); - m_status = Initial; + m_resourceSet->release(); + m_status = Initial; + } + } } } @@ -258,7 +276,8 @@ bool ResourcePolicyInt::isGranted(const ResourcePolicyImpl *client) const QMap::const_iterator i = m_clients.find(client); if (i != m_clients.constEnd()) { #ifdef RESOURCE_DEBUG - qDebug() << "##### " << i.value().id << ": IS GRANTED, status: " << i.value().status; + qDebug() << "##### " << i.value().id << ": IS GRANTED, status:" << i.value().status + << "granted:" << (i.value().status == GrantedResource); #endif return i.value().status == GrantedResource; }