/
0008-Maintain-proper-internal-state-when-releasing-resour.patch
85 lines (79 loc) · 3.39 KB
/
0008-Maintain-proper-internal-state-when-releasing-resour.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
From 9dca3fe294e5755656d5e875fe9db1dbd593eb44 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juho=20H=C3=A4m=C3=A4l=C3=A4inen?=
<juho.hamalainen@tieto.com>
Date: Wed, 4 Mar 2015 12:09:30 +0200
Subject: [PATCH 08/15] 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
---
src/plugins/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 fc6a3d87..881888db 100644
--- a/src/plugins/resourcepolicy/resourcepolicyint.cpp
+++ b/src/plugins/resourcepolicy/resourcepolicyint.cpp
@@ -240,22 +240,40 @@ 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) {
- 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 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()";
+ qDebug() << "##### " << i.value().id << ": RELEASE call resourceSet->release()";
#endif
- m_resourceSet->release();
- m_status = Initial;
+ m_resourceSet->release();
+ m_status = Initial;
+ }
+ }
}
}
@@ -264,7 +282,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;
}
--
2.15.0