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:
committed by
Martin Jones
parent
a756991a42
commit
e9c2cce662
@@ -234,22 +234,40 @@ void ResourcePolicyInt::release(const ResourcePolicyImpl *client)
|
|||||||
{
|
{
|
||||||
QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.find(client);
|
QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.find(client);
|
||||||
if (i != m_clients.end()) {
|
if (i != m_clients.end()) {
|
||||||
if (i.value().status == GrantedResource) {
|
ResourceStatus oldStatus = i.value().status;
|
||||||
i.value().status = Initial;
|
i.value().status = Initial;
|
||||||
|
|
||||||
|
#ifdef RESOURCE_DEBUG
|
||||||
|
qDebug() << "##### " << i.value().id << ": RELEASE";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (oldStatus == GrantedResource) {
|
||||||
--m_acquired;
|
--m_acquired;
|
||||||
#ifdef RESOURCE_DEBUG
|
#ifdef RESOURCE_DEBUG
|
||||||
qDebug() << "##### " << i.value().id << ": RELEASE, acquired (" << m_acquired << ")";
|
qDebug() << "##### " << i.value().id << ": RELEASE, acquired (" << m_acquired
|
||||||
|
<< "), emit resourcesReleased()";
|
||||||
#endif
|
#endif
|
||||||
emit i.value().client->resourcesReleased();
|
emit i.value().client->resourcesReleased();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (m_acquired == 0 && m_status != Initial) {
|
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
|
#ifdef RESOURCE_DEBUG
|
||||||
qDebug() << "##### " << i.value().id << ": RELEASE call resourceSet->release()";
|
qDebug() << "##### " << i.value().id << ": RELEASE call resourceSet->release()";
|
||||||
#endif
|
#endif
|
||||||
m_resourceSet->release();
|
m_resourceSet->release();
|
||||||
m_status = Initial;
|
m_status = Initial;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +276,8 @@ bool ResourcePolicyInt::isGranted(const ResourcePolicyImpl *client) const
|
|||||||
QMap<const ResourcePolicyImpl*, clientEntry>::const_iterator i = m_clients.find(client);
|
QMap<const ResourcePolicyImpl*, clientEntry>::const_iterator i = m_clients.find(client);
|
||||||
if (i != m_clients.constEnd()) {
|
if (i != m_clients.constEnd()) {
|
||||||
#ifdef RESOURCE_DEBUG
|
#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
|
#endif
|
||||||
return i.value().status == GrantedResource;
|
return i.value().status == GrantedResource;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user