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
 
50
 
51
 /* The received message we're currently working with */
51
 /* The received message we're currently working with */
52
 static union pd_msg *policy_engine_message = NULL;
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
 /* Whether or not the source capabilities match our required power */
55
 /* Whether or not the source capabilities match our required power */
54
 static bool capability_match = false;
56
 static bool capability_match = false;
55
 /* Whether or not we have an explicit contract */
57
 /* Whether or not we have an explicit contract */
131
 
133
 
132
 static enum policy_engine_state pe_sink_eval_cap(void)
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
     /* Ask the DPM what to request */
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
     /* Free the Source_Capabilities message */
143
     /* Free the Source_Capabilities message */
139
     chPoolFree(&pdb_msg_pool, policy_engine_message);
144
     chPoolFree(&pdb_msg_pool, policy_engine_message);
140
-    /* Put the request into policy_engine_message */
141
-    policy_engine_message = request;
142
 
145
 
143
     return PESinkSelectCap;
146
     return PESinkSelectCap;
144
 }
147
 }
146
 static enum policy_engine_state pe_sink_select_cap(void)
149
 static enum policy_engine_state pe_sink_select_cap(void)
147
 {
150
 {
148
     /* Transmit the request */
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
     chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
153
     chEvtSignal(pdb_prltx_thread, PDB_EVT_PRLTX_MSG_TX);
151
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
154
     eventmask_t evt = chEvtWaitAny(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR
152
             | PDB_EVT_PE_RESET);
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
     /* If we got reset signaling, transition to default */
157
     /* If we got reset signaling, transition to default */
157
     if (evt & PDB_EVT_PE_RESET) {
158
     if (evt & PDB_EVT_PE_RESET) {
158
         return PESinkTransitionDefault;
159
         return PESinkTransitionDefault;

Loading…
Cancel
Save