On 28-Feb-18 4:00 AM, Wiles, Keith wrote:
+ struct message_queue_entry *cur_msg, *next_msg, *new_msg = NULL;
while (1) {
- if (read_msg(&msg, &sa) == 0)
- process_msg(&msg, &sa);
+ /* we want to process all messages in order of their arrival,
+ * but status of init_complete may change while we're iterating
+ * the tailq. so, store it here and check once every iteration.
+ */
+ int init_complete;
Do we allow variables to be defined in the middle of a block, I thought we only
allowed them after a ‘{‘ or open block.
Apologies, will fix.
+
+ if (new_msg == NULL)
+ new_msg = malloc(sizeof(*new_msg));
I am very concerned about allocating memory with no limit. If the process never
completes then we could receive messages and consume a lot of memory. I would
want to see a limit to the number of messages we can consume in the queue just
to be sure.
Sure, will do.
+ if (read_msg(&new_msg->msg, &new_msg->sa) == 0) {
+ /* we successfully read the message, so enqueue it */
+ TAILQ_INSERT_TAIL(&message_queue, new_msg, next);
+ new_msg = NULL;
+ } /* reuse new_msg for next message if we couldn't read_msg */
+
+ init_complete = internal_config.init_complete;
Does the internal_config.init_complete need to be a volatile to make sure it is
reread each time thru the loop?
Will fix.
+
+ /* tailq only accessed here, so no locking needed */
+ TAILQ_FOREACH_SAFE(cur_msg, &message_queue, next, next_msg) {
+ /* secondary process should not process any incoming
+ * requests until its initialization is complete, but
+ * it is allowed to process replies to its own queries.
+ */
+ if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
+ !init_complete &&
+ cur_msg->msg.type != MP_REP)
+ continue;
+
+ TAILQ_REMOVE(&message_queue, cur_msg, next);
+
+ process_msg(&cur_msg->msg, &cur_msg->sa);
+
+ free(cur_msg);
+ }
}
return NULL;
--
2.7.4
Regards,
Keith
--
Thanks,
Anatoly