From 0cc443d3c27d30e591e00c48347eee75d1f1e7e9 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Sat, 19 Mar 2016 16:54:26 +0530 Subject: [PATCH] Fix message priority implementation Functional specification mandates returning a message with a higher timestamp in case two messages have the same priority. Somehow we missed this in the implementation. This also introduced a bug where all messages with same priority could cause problems. --- minix/kernel/mqueue.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/minix/kernel/mqueue.c b/minix/kernel/mqueue.c index 0093db282..dfd2e0616 100644 --- a/minix/kernel/mqueue.c +++ b/minix/kernel/mqueue.c @@ -176,7 +176,10 @@ int message_index_with_highprio(int mqdes, endpoint_t dst) prio = mq.msg[mqdes].msge[i].priority; for (int j = 0; j < MAX_RECEIVERS; j++) { if (mq.msg[mqdes].msge[i].dst[j] == dst) { - if (max_prio < find_max(max_prio, prio)) { + if (max_prio == prio) { + if (mq.msg[mqdes].msge[i].timestamp > mq.msg[mqdes].msge[index].timestamp) + index = i; + } else if (max_prio < find_max(max_prio, prio)) { index = i; max_prio = find_max(max_prio, prio); }