Browse Source

Keep the Request message in memory

We used to free the Request we made after transmitting it.  However, for
GiveBack to work properly, we need to be able to make that request
again.  To do it without having to request the Source_Capabilities
again, it makes sense to keep the Request message in memory.  We have
more messages in the pool than we need anyway.
Clara Hobbs 7 years ago
parent
commit
6f16b75f9b
1 changed files with 10 additions and 9 deletions
  1. 10
    9
      src/policy_engine.c

+ 10
- 9
src/policy_engine.c View File

@@ -50,6 +50,8 @@ enum policy_engine_state {
50 50
 
51 51
 /* The received message we're currently working with */
52 52
 static union pd_msg *policy_engine_message = NULL;
53
+/* The most recent Request from the DPM */
54
+static union pd_msg *last_dpm_request = NULL;
53 55
 /* Whether or not the source capabilities match our required power */
54 56
 static bool capability_match = false;
55 57
 /* Whether or not we have an explicit contract */
@@ -131,14 +133,15 @@ static enum policy_engine_state pe_sink_wait_cap(void)
131 133
 
132 134
 static enum policy_engine_state pe_sink_eval_cap(void)
133 135
 {
134
-    /* Get a message object */
135
-    union pd_msg *request = chPoolAlloc(&pdb_msg_pool);
136
+    /* Get a message object for the request if we don't have one already */
137
+    if (last_dpm_request == NULL) {
138
+        last_dpm_request = chPoolAlloc(&pdb_msg_pool);
139
+    }
136 140
     /* Ask the DPM what to request */
137
-    capability_match = pdb_dpm_evaluate_capability(policy_engine_message, request);
141
+    capability_match = pdb_dpm_evaluate_capability(policy_engine_message,
142
+            last_dpm_request);
138 143
     /* Free the Source_Capabilities message */
139 144
     chPoolFree(&pdb_msg_pool, policy_engine_message);
140
-    /* Put the request into policy_engine_message */
141
-    policy_engine_message = request;
142 145
 
143 146
     return PESinkSelectCap;
144 147
 }
@@ -146,13 +149,11 @@ static enum policy_engine_state pe_sink_eval_cap(void)
146 149
 static enum policy_engine_state pe_sink_select_cap(void)
147 150
 {
148 151
     /* Transmit the request */
149
-    chMBPost(&pdb_prltx_mailbox, (msg_t) policy_engine_message, TIME_IMMEDIATE);
152
+    chMBPost(&pdb_prltx_mailbox, (msg_t) last_dpm_request, TIME_IMMEDIATE);
150 153
     chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
151 154
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
152 155
             | PDB_EVT_PE_RESET);
153
-    /* Free the sent message */
154
-    chPoolFree(&pdb_msg_pool, policy_engine_message);
155
-    policy_engine_message = NULL;
156
+    /* Don't free the request; we might need it again */
156 157
     /* If we got reset signaling, transition to default */
157 158
     if (evt & PDB_EVT_PE_RESET) {
158 159
         return PESinkTransitionDefault;

Loading…
Cancel
Save