xiaoxiang781216 commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1001387608


##########
sched/mqueue/msgrcv.c:
##########
@@ -0,0 +1,261 @@
+/****************************************************************************
+ * sched/mqueue/msgrcv.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+
+#include <nuttx/cancelpt.h>
+
+#include "sched/sched.h"
+#include "mqueue/msg.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgrcv_wait
+ ****************************************************************************/
+
+static int msgrcv_wait(FAR struct msgq_s *msgq, FAR struct msgbuf_s **rcvmsg,
+                       long msgtyp, int msgflg)
+{
+  FAR struct list_node *newmsg = NULL;
+  FAR struct list_node *node;
+  FAR struct tcb_s *rtcb;
+
+#ifdef CONFIG_CANCELLATION_POINTS
+  /* msgrcv_wait() is not a cancellation point, but it may be called
+   * from msgrcv() which are cancellation point.
+   */
+
+  if (check_cancellation_point())
+    {
+      /* If there is a pending cancellation, then do not perform
+       * the wait.  Exit now with ECANCELED.
+       */
+
+      return -ECANCELED;
+    }
+#endif
+
+  /* Get the message from the head of the queue */
+
+  while (1)
+    {
+      list_for_every(&msgq->msglist, node)
+        {
+          /* Unless MSG_COPY is specified in msgflg (see below), the msgtyp
+           * argument specifies the type of message requested, as follows:
+           *
+           * 1. If msgtyp is 0, then the first message in the queue is read.
+           *
+           * 2. If msgtyp is greater than 0, then the first message in the
+           *    queue of type msgtyp is read, unless MSG_EXCEPT was
+           *    specified in msgflg, in which case the first message in the
+           *    queue of type not equal to msgtyp will be read.
+           *
+           * 3. If msgtyp is less than 0, then the first message in the
+           *    queue with the lowest type less than or equal to the
+           *    absolute value of msgtyp will be read.
+           */
+
+          if (msgtyp < 0)
+            {
+              if (newmsg == NULL || ((FAR struct msgbuf_s *)newmsg)->mtype >
+                                    ((FAR struct msgbuf_s *)node)->mtype)
+                {
+                  newmsg = node;
+                }
+            }
+          else if (msgtyp == 0 ||
+                   (msgflg & MSG_EXCEPT) != 0 ||

Review Comment:
   the logic is wrong?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to