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
This commit is contained in:
Juho Hämäläinen
2015-03-04 12:09:30 +02:00
committed by Martin Jones
parent a756991a42
commit e9c2cce662

View File

@@ -234,23 +234,41 @@ void ResourcePolicyInt::release(const ResourcePolicyImpl *client)
{
QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.find(client);
if (i != m_clients.end()) {
if (i.value().status == GrantedResource) {
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) {
QMap<const ResourcePolicyImpl*, clientEntry>::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()";
#endif
m_resourceSet->release();
m_status = Initial;
}
}
}
}
bool ResourcePolicyInt::isGranted(const ResourcePolicyImpl *client) const
@@ -258,7 +276,8 @@ bool ResourcePolicyInt::isGranted(const ResourcePolicyImpl *client) const
QMap<const ResourcePolicyImpl*, clientEntry>::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;
}