You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/09/14 03:53:33 UTC

[GitHub] [incubator-nuttx] anchao opened a new pull request, #7088: sched/msgq: add support of System V message queue

anchao opened a new pull request, #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088

   ## Summary
   
   sched/msgq: add support of System V message queue
   sched/mqueue: decoupling condition member to common prologue
   
   https://man.openbsd.org/msgget.2
   
   ## Impact
   
   N/A
   
   ## Testing
   
   System V message queue test


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r970932694


##########
include/nuttx/mqueue.h:
##########
@@ -83,16 +83,23 @@
  * Public Type Declarations
  ****************************************************************************/
 
+/* Common prologue of all message queue structures. */
+
+struct mqueue_comm_s
+{
+  int16_t nwaitnotfull;       /* Number tasks waiting for not full */
+  int16_t nwaitnotempty;      /* Number tasks waiting for not empty */
+};
+
 /* This structure defines a message queue */
 
 struct mqueue_inode_s
 {
+  struct mqueue_comm_s comm;  /* Common prologue */

Review Comment:
   ditto



##########
fs/procfs/fs_procfsproc.c:
##########
@@ -411,7 +411,7 @@ static FAR const char * const g_statenames[] =
   "Inactive",
   "Waiting,Semaphore",
   "Waiting,Signal"
-#ifndef CONFIG_DISABLE_MQUEUE
+#if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_MQUEUE_SYSV)

Review Comment:
   could we use a common symbol?



##########
sched/mqueue/msginternal.c:
##########
@@ -0,0 +1,137 @@
+/****************************************************************************
+ * sched/mqueue/msginternal.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 <nuttx/kmalloc.h>
+#include "mqueue/msg.h"
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+struct list_node g_msgfreelist = LIST_INITIAL_VALUE(g_msgfreelist);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct list_node g_msgqactivelist =
+                        LIST_INITIAL_VALUE(g_msgqactivelist);
+static struct list_node g_msgqfreelist   =
+                        LIST_INITIAL_VALUE(g_msgqfreelist);
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxmsg_initialize
+ ****************************************************************************/
+
+void nxmsg_initialize(void)
+{
+  FAR struct msgbuf_s *msg;
+
+  msg = (FAR struct msgbuf_s *)kmm_malloc(sizeof(*msg) *
+                                          CONFIG_PREALLOC_MQ_MSGS);
+  if (msg)
+    {
+      int i;
+      for (i = 0; i < CONFIG_PREALLOC_MQ_MSGS; i++)
+        {
+          list_add_tail(&g_msgfreelist, &msg->node);
+          msg++;
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: nxmsg_alloc
+ ****************************************************************************/
+
+int nxmsg_alloc(FAR struct msgq_s **pmsgq)
+{
+  FAR struct msgq_s *msgq;
+
+  /* Allocate memory for the new message queue. */
+
+  msgq = list_remove_head_type(&g_msgqfreelist, struct msgq_s, node);
+  if (msgq == NULL)
+    {
+      msgq = (FAR struct msgq_s *)kmm_zalloc(sizeof(struct msgq_s));
+    }
+
+  if (msgq == NULL)
+    {
+      return -ENOSPC;
+    }
+
+  /* Initialize the new named message queue */
+
+  list_add_tail(&g_msgqactivelist, &msgq->node);
+  list_initialize(&msgq->msglist);
+
+  msgq->maxmsgs    = MSG_MAX_MSGS;
+  msgq->maxmsgsize = MSG_MAX_BYTES;
+
+  *pmsgq = msgq;
+  return OK;
+}
+
+/****************************************************************************
+ * Name: nxmsg_free
+ ****************************************************************************/
+
+void nxmsg_free(FAR struct msgq_s *msgq)
+{
+  FAR struct msgq_s *entry;
+  FAR struct msgq_s *tmp;
+
+  list_for_every_entry_safe(&msgq->msglist, entry, tmp, struct msgq_s, node)
+    {
+      list_delete(&entry->node);
+      list_add_tail(&g_msgfreelist, &entry->node);
+    }
+
+  list_delete(&msgq->node);
+  list_add_tail(&g_msgqfreelist, &msgq->node);
+}
+
+/****************************************************************************
+ * Name: nxmsg_lookup
+ ****************************************************************************/
+
+FAR struct msgq_s *nxmsg_lookup(key_t key)
+{
+  FAR struct msgq_s *msgq;
+
+  list_for_every_entry(&g_msgqactivelist, msgq, struct msgq_s, node)

Review Comment:
   can we change g_msgqactivelist to an array and identify the msq by index to improve the speed?



##########
include/nuttx/mqueue.h:
##########
@@ -83,16 +83,23 @@
  * Public Type Declarations
  ****************************************************************************/
 
+/* Common prologue of all message queue structures. */
+
+struct mqueue_comm_s

Review Comment:
   comm->cmn like:
   ```
   struct task_tcb_s
   {
     /* Common TCB fields ******************************************************/
   
     struct tcb_s cmn;                      /* Common TCB fields                   */
   
     /* Task Management Fields *************************************************/
   
   #ifdef CONFIG_SCHED_STARTHOOK
     starthook_t starthook;                 /* Task startup function               */
     FAR void *starthookarg;                /* The argument passed to the function */
   #endif
   };
   ```



##########
sched/mqueue/msgget.c:
##########
@@ -0,0 +1,95 @@
+/****************************************************************************
+ * sched/mqueue/msgget.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 "mqueue/msg.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgget
+ *
+ * Description:
+ *   Get a System V message queue identifier
+ *   The msgget() system call returns the System V message queue
+ *   identifier associated with the value of the key argument.  It may
+ *   be used either to obtain the identifier of a previously created
+ *   message queue (when msgflg is zero and key does not have the
+ *   value IPC_PRIVATE), or to create a new set.
+ *
+ * Input Parameters:
+ *   key    - Key associated with the message queue
+ *   msgflg - Operations and permissions flag
+ *
+ * Returned Value:
+ *   On success, msgget() returns the message queue identifier (a
+ *   nonnegative integer).  On failure, -1 is returned, and errno is
+ *   set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgget(key_t key, int msgflg)
+{
+  FAR struct msgq_s *msgq;
+  irqstate_t flags;
+  int ret = OK;
+
+  flags = enter_critical_section();
+
+  msgq = nxmsg_lookup(key);
+
+  if (msgq)
+    {
+      if ((msgflg & IPC_CREAT) && (msgflg & IPC_EXCL))
+        {
+          ret = -EEXIST;
+        }
+    }
+  else
+    {
+      if (key != IPC_PRIVATE && !(msgflg & IPC_CREAT))

Review Comment:
   how to identify the different private queue



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1000095145


##########
include/sys/msg.h:
##########
@@ -0,0 +1,212 @@
+/****************************************************************************
+ * include/sys/msg.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_SYS_MSG_H
+#define __INCLUDE_SYS_MSG_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/ipc.h>
+#include <time.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct
+ * are as defined by the SV API Intel 386 Processor Supplement.
+ */
+
+#define MSG_NOERROR 010000  /* No error if message is too big */
+#define MSG_EXCEPT  020000  /* Recv any msg except of specified type.*/
+#define MSG_COPY    040000  /* Copy (not remove) all queue messages */
+
+/****************************************************************************
+ * Public Type Declarations
+ ****************************************************************************/
+
+typedef unsigned long msgqnum_t;
+typedef unsigned long msglen_t;
+
+struct msqid_ds
+{
+  struct ipc_perm msg_perm;   /* Ownership and permissions */
+  time_t          msg_stime;  /* Time of last msgsnd(2) */
+  time_t          msg_rtime;  /* Time of last msgrcv(2) */
+  time_t          msg_ctime;  /* Time of last change */
+  unsigned long   msg_cbytes; /* Current number of bytes in
+                               * queue (nonstandard) */
+  msgqnum_t       msg_qnum;   /* Current number of messages
+                               * in queue */
+  msglen_t        msg_qbytes; /* Maximum number of bytes
+                               * allowed in queue */
+  pid_t           msg_lspid;  /* PID of last msgsnd(2) */
+  pid_t           msg_lrpid;  /* PID of last msgrcv(2) */
+};
+
+/* Structure describing a message.  The SVID doesn't suggest any
+ * particular name for this structure.  There is a reference in the
+ * msgop man page that reads "The structure mymsg is an example of what
+ * this user defined buffer might look like, and includes the following
+ * members:".  This sentence is followed by two lines equivalent
+ * to the mtype and mtext field declarations below.  It isn't clear
+ * if "mymsg" refers to the name of the structure type or the name of an
+ * instance of the structure...
+ */
+
+struct mymsg
+{
+  long  mtype;    /* message type (+ve integer) */
+  char  mtext[1]; /* message body */
+};
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgctl
+ *
+ * Description:
+ *   System V message control operations.
+ *   msgctl() performs the control operation specified by cmd on the
+ *   System V message queue with identifier msqid.
+ *
+ * Input Parameters:
+ *   msqid    - System V message queue identifier
+ *   cmd      - Command operations
+ *   msqid_ds - Defines a message queue
+ *
+ * Returned Value:
+ *   On success, IPC_STAT, IPC_SET, and IPC_RMID return 0.  A
+ *   successful IPC_INFO or MSG_INFO operation returns the index of
+ *   the highest used entry in the kernel's internal array recording
+ *   information about all message queues.  (This information can be
+ *   used with repeated MSG_STAT or MSG_STAT_ANY operations to obtain
+ *   information about all queues on the system.)  A successful
+ *   MSG_STAT or MSG_STAT_ANY operation returns the identifier of the
+ *   queue whose index was given in msqid.
+ *
+ *   On failure, -1 is returned and errno is set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgctl(int msqid, int cmd, FAR struct msqid_ds *buf);
+
+/****************************************************************************
+ * Name: msgget
+ *
+ * Description:
+ *   Get a System V message queue identifier
+ *   The msgget() system call returns the System V message queue
+ *   identifier associated with the value of the key argument.  It may
+ *   be used either to obtain the identifier of a previously created
+ *   message queue (when msgflg is zero and key does not have the
+ *   value IPC_PRIVATE), or to create a new set.
+ *
+ * Input Parameters:
+ *   key    - Key associated with the message queue
+ *   msgflg - Operations and permissions flag
+ *
+ * Returned Value:
+ *   On success, msgget() returns the message queue identifier (a
+ *   nonnegative integer).  On failure, -1 is returned, and errno is
+ *   set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgget(key_t key, int msgflg);
+
+/****************************************************************************
+ * Name: msgsnd
+ *
+ * Description:
+ *   The msgsnd() function is used to send a message to the queue
+ *   associated with the message queue identifier specified by msqid.
+ *   The msgp argument points to a user-defined buffer that must contain
+ *   first a field of type long int that will specify the type of the
+ *   message, and then a data portion that will hold the data bytes of
+ *   the message.
+ *
+ * Input Parameters:
+ *   msqid  - Message queue identifier
+ *   msgp   - Pointer to a buffer with the message to be sent
+ *   msgsz  - Length of the data part of the message to be sent
+ *   msgflg - Operations flags
+ *
+ * Returned Value:
+ *   On success, mq_send() returns 0 (OK); on error, -1 (ERROR)
+ *   is returned, with errno set to indicate the error:
+ *
+ *   EAGAIN   The queue was full and the O_NONBLOCK flag was set for the
+ *            message queue description referred to by mqdes.
+ *   EINVAL   Either msg or mqdes is NULL or the value of prio is invalid.
+ *   EPERM    Message queue opened not opened for writing.
+ *   EMSGSIZE 'msglen' was greater than the maxmsgsize attribute of the
+ *            message queue.
+ *   EINTR    The call was interrupted by a signal handler.
+ *
+ ****************************************************************************/
+
+int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
+
+/****************************************************************************
+ * Name: msgrcv
+ *
+ * Description:
+ *   The msgrcv() function reads a message from the message queue specified
+ *   by the msqid parameter and places it in the user-defined buffer
+ *   pointed to by the *msgp parameter.
+ *
+ * Input Parameters:
+ *   msqid  - Message queue identifier
+ *   msgp   - Pointer to a buffer in which the received message will be
+ *            stored
+ *   msgsz  - Length of the data part of the buffer
+ *   msgtyp - Type of message to be received.
+ *   msgflg - Operations flags.
+ *
+ * Returned Value:
+ *   On success, msgrcv() returns the number of bytes actually copied
+ *   into the mtext array.
+ *   On failure, both functions return -1, and set errno to indicate
+ *   the error.
+ *
+ ****************************************************************************/
+
+ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg);

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1000110222


##########
include/nuttx/mqueue.h:
##########
@@ -85,25 +85,32 @@
 # define nxmq_pollnotify(msgq, eventset)
 #endif
 
-# define MQ_WNELIST(mq)               (&((mq)->waitfornotempty))
-# define MQ_WNFLIST(mq)               (&((mq)->waitfornotfull))
+# define MQ_WNELIST(cmn)              (&((cmn).waitfornotempty))
+# define MQ_WNFLIST(cmn)              (&((cmn).waitfornotfull))
 
 /****************************************************************************
  * Public Type Declarations
  ****************************************************************************/
 
+/* Common prologue of all message queue structures. */
+
+struct mqueue_cmn_s
+{
+  dq_queue_t waitfornotempty; /* Task list waiting for not empty */
+  dq_queue_t waitfornotfull;  /* Task list waiting for not full */
+  int16_t nwaitnotfull;       /* Number tasks waiting for not full */
+  int16_t nwaitnotempty;      /* Number tasks waiting for not empty */
+};
+
 /* This structure defines a message queue */
 
 struct mqueue_inode_s
 {
+  struct mqueue_cmn_s cmn;    /* Common prologue */

Review Comment:
   Done



##########
sched/mqueue/msg.h:
##########
@@ -0,0 +1,98 @@
+/********************************************************************************
+ * sched/mqueue/msg.h
+ *
+ * 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.
+ *
+ ********************************************************************************/
+
+#ifndef __SCHED_MQUEUE_MSG_H
+#define __SCHED_MQUEUE_MSG_H
+
+/********************************************************************************
+ * Included Files
+ ********************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/list.h>
+#include <nuttx/mqueue.h>
+#include <sys/msg.h>
+
+#include <errno.h>
+
+#if defined(CONFIG_MQ_MAXMSGSIZE) && CONFIG_MQ_MAXMSGSIZE > 0
+
+/********************************************************************************
+ * Pre-processor Definitions
+ ********************************************************************************/
+
+#define MSG_MAX_BYTES   CONFIG_MQ_MAXMSGSIZE
+#define MSG_MAX_MSGS    16
+
+/********************************************************************************
+ * Public Type Definitions
+ ********************************************************************************/
+
+struct msgq_s
+{
+  struct mqueue_cmn_s  cmn;
+  struct list_node     msglist;       /* Prioritized message list */
+  key_t                key;
+  int16_t              maxmsgs;       /* Maximum number of messages in the queue */
+  int16_t              nmsgs;         /* Number of message in the queue */
+  uint16_t             maxmsgsize;    /* Max size of message in message queue */
+};
+
+struct msgbuf_s
+{
+  struct list_node node;
+  uint16_t         msize;                /* Message data length */
+  long             mtype;                /* Message type, must be > 0 */
+  char             mtext[MSG_MAX_BYTES]; /* Message data */
+};
+
+/********************************************************************************
+ * Public Data
+ ********************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+EXTERN struct list_node g_msgfreelist;
+
+/********************************************************************************
+ * Public Function Prototypes
+ ********************************************************************************/
+
+void               nxmsg_initialize(void);
+int                nxmsg_alloc(FAR struct msgq_s **pmsgq);
+void               nxmsg_free(FAR struct msgq_s *msgq);
+FAR struct msgq_s *nxmsg_lookup(key_t key);

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1001387894


##########
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)

Review Comment:
   list_for_every_entry to avoid the cast at line 85-86



##########
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 ||
+                   ((FAR struct msgbuf_s *)node)->mtype == msgtyp)
+            {
+              newmsg = node;
+              break;
+            }
+        }
+
+      if (newmsg)
+        {
+          list_delete(newmsg);
+          goto found;
+        }
+
+      if ((msgflg & IPC_NOWAIT) != 0)
+        {
+          return -EAGAIN;
+        }
+
+      /* The queue is empty!  Should we block until there the above condition
+       * has been satisfied?
+       */
+
+      rtcb          = this_task();
+      rtcb->waitobj = msgq;
+      msgq->cmn.nwaitnotempty++;
+
+      /* Initialize the 'errcode" used to communication wake-up error
+       * conditions.
+       */
+
+      rtcb->errcode  = OK;

Review Comment:
   remove the extra space before =



##########
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;

Review Comment:
   change the type of newmsg and node to msgbuf_s 



##########
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 ||
+                   ((FAR struct msgbuf_s *)node)->mtype == msgtyp)
+            {
+              newmsg = node;
+              break;
+            }
+        }
+
+      if (newmsg)
+        {
+          list_delete(newmsg);
+          goto found;
+        }
+
+      if ((msgflg & IPC_NOWAIT) != 0)
+        {
+          return -EAGAIN;
+        }
+
+      /* The queue is empty!  Should we block until there the above condition
+       * has been satisfied?
+       */
+
+      rtcb          = this_task();
+      rtcb->waitobj = msgq;
+      msgq->cmn.nwaitnotempty++;
+
+      /* Initialize the 'errcode" used to communication wake-up error
+       * conditions.
+       */
+
+      rtcb->errcode  = OK;
+
+      /* Make sure this is not the idle task, descheduling that
+       * isn't going to end well.
+       */
+
+      DEBUGASSERT(NULL != rtcb->flink);
+      up_block_task(rtcb, TSTATE_WAIT_MQNOTEMPTY);
+
+      /* When we resume at this point, either (1) the message queue
+       * is no longer empty, or (2) the wait has been interrupted by
+       * a signal.  We can detect the latter case be examining the
+       * errno value (should be either EINTR or ETIMEDOUT).
+       */
+
+      if (rtcb->errcode != OK)
+        {
+          return -rtcb->errcode;
+        }
+    }
+
+found:
+  *rcvmsg = (FAR struct msgbuf_s *)newmsg;
+  return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgrcv
+ *
+ * Description:
+ *   The msgrcv() function reads a message from the message queue specified
+ *   by the msqid parameter and places it in the user-defined buffer
+ *   pointed to by the *msgp parameter.
+ *
+ * Input Parameters:
+ *   msqid  - Message queue identifier
+ *   msgp   - Pointer to a buffer in which the received message will be
+ *            stored
+ *   msgsz  - Length of the data part of the buffer
+ *   msgtyp - Type of message to be received.
+ *   msgflg - Operations flags.
+ *
+ * Returned Value:
+ *   On success, msgrcv() returns the number of bytes actually copied
+ *   into the mtext array.
+ *   On failure, both functions return -1, and set errno to indicate
+ *   the error.
+ *
+ ****************************************************************************/
+
+ssize_t msgrcv(int msqid, FAR void *msgp, size_t msgsz, long msgtyp,
+               int msgflg)
+{
+  FAR struct msgbuf_s *msg = NULL;
+  FAR struct mymsg *buf = msgp;
+  FAR struct msgq_s *msgq;
+  FAR struct tcb_s *btcb;
+  irqstate_t flags;
+  int ret;
+
+  if (msgp == NULL)
+    {
+      ret = -EFAULT;
+      goto errout;
+    }
+
+  flags = enter_critical_section();
+
+  msgq = nxmsg_lookup(msqid);
+  if (msgq == NULL)
+    {
+      ret = -EINVAL;
+      goto errout_with_critical;
+    }
+
+  if (msgsz < msgq->maxmsgsize &&
+      ((msgflg & MSG_NOERROR) == 0))
+    {
+      ret = -EMSGSIZE;
+      goto errout_with_critical;
+    }
+
+  ret = msgrcv_wait(msgq, &msg, msgtyp, msgflg);
+  if (ret < 0)
+    {
+      goto errout_with_critical;
+    }
+
+  msgq->nmsgs--;

Review Comment:
   move to msgrcv_wait



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r999761431


##########
sched/mqueue/msgctl.c:
##########
@@ -0,0 +1,124 @@
+/****************************************************************************
+ * sched/mqueue/msgctl.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 "mqueue/msg.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgctl
+ *
+ * Description:
+ *   System V message control operations.
+ *   msgctl() performs the control operation specified by cmd on the
+ *   System V message queue with identifier msqid.
+ *
+ * Input Parameters:
+ *   msqid    - System V message queue identifier
+ *   cmd      - Command operations
+ *   msqid_ds - Defines a message queue
+ *
+ * Returned Value:
+ *   On success, IPC_STAT, IPC_SET, and IPC_RMID return 0.  A
+ *   successful IPC_INFO or MSG_INFO operation returns the index of
+ *   the highest used entry in the kernel's internal array recording
+ *   information about all message queues.  (This information can be
+ *   used with repeated MSG_STAT or MSG_STAT_ANY operations to obtain
+ *   information about all queues on the system.)  A successful
+ *   MSG_STAT or MSG_STAT_ANY operation returns the identifier of the
+ *   queue whose index was given in msqid.
+ *
+ *   On failure, -1 is returned and errno is set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgctl(int msqid, int cmd, struct msqid_ds *buf)
+{
+  FAR struct msgq_s *msgq;
+  irqstate_t flags;
+  int ret = OK;
+
+  flags = enter_critical_section();
+
+  msgq = nxmsg_lookup((key_t)msqid);

Review Comment:
   change the argument type of nxmsg_lookup to int instead cast



##########
sched/mqueue/msg.h:
##########
@@ -0,0 +1,98 @@
+/********************************************************************************
+ * sched/mqueue/msg.h
+ *
+ * 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.
+ *
+ ********************************************************************************/
+
+#ifndef __SCHED_MQUEUE_MSG_H
+#define __SCHED_MQUEUE_MSG_H
+
+/********************************************************************************
+ * Included Files
+ ********************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/list.h>
+#include <nuttx/mqueue.h>
+#include <sys/msg.h>
+
+#include <errno.h>
+
+#if defined(CONFIG_MQ_MAXMSGSIZE) && CONFIG_MQ_MAXMSGSIZE > 0
+
+/********************************************************************************
+ * Pre-processor Definitions
+ ********************************************************************************/
+
+#define MSG_MAX_BYTES   CONFIG_MQ_MAXMSGSIZE
+#define MSG_MAX_MSGS    16
+
+/********************************************************************************
+ * Public Type Definitions
+ ********************************************************************************/
+
+struct msgq_s
+{
+  struct mqueue_cmn_s  cmn;
+  struct list_node     msglist;       /* Prioritized message list */
+  key_t                key;
+  int16_t              maxmsgs;       /* Maximum number of messages in the queue */
+  int16_t              nmsgs;         /* Number of message in the queue */
+  uint16_t             maxmsgsize;    /* Max size of message in message queue */
+};
+
+struct msgbuf_s
+{
+  struct list_node node;
+  uint16_t         msize;                /* Message data length */
+  long             mtype;                /* Message type, must be > 0 */
+  char             mtext[MSG_MAX_BYTES]; /* Message data */
+};
+
+/********************************************************************************
+ * Public Data
+ ********************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+EXTERN struct list_node g_msgfreelist;

Review Comment:
   change to static



##########
sched/mqueue/msg.h:
##########
@@ -0,0 +1,98 @@
+/********************************************************************************
+ * sched/mqueue/msg.h
+ *
+ * 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.
+ *
+ ********************************************************************************/
+
+#ifndef __SCHED_MQUEUE_MSG_H
+#define __SCHED_MQUEUE_MSG_H
+
+/********************************************************************************
+ * Included Files
+ ********************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/list.h>

Review Comment:
   remove



##########
sched/mqueue/msginternal.c:
##########
@@ -0,0 +1,198 @@
+/****************************************************************************
+ * sched/mqueue/msginternal.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 <nuttx/kmalloc.h>
+#include "mqueue/msg.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MQ_PERBLOCK 10
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+struct nxmsg_manager_s
+{
+  uint8_t             nmsgq;  /* The number of groups of msgs array */
+  FAR struct msgq_s **msgqs;  /* The pointer of two layer file descriptors array */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct nxmsg_manager_s g_msgmgrs;

Review Comment:
   remove nxmsg_manager_s and use nmsgq/msgqs directly?



##########
sched/mqueue/msginternal.c:
##########
@@ -0,0 +1,198 @@
+/****************************************************************************
+ * sched/mqueue/msginternal.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 <nuttx/kmalloc.h>
+#include "mqueue/msg.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MQ_PERBLOCK 10
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+struct nxmsg_manager_s
+{
+  uint8_t             nmsgq;  /* The number of groups of msgs array */
+  FAR struct msgq_s **msgqs;  /* The pointer of two layer file descriptors array */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct nxmsg_manager_s g_msgmgrs;
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+struct list_node g_msgfreelist = LIST_INITIAL_VALUE(g_msgfreelist);
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxmsg_alloc_internal
+ ****************************************************************************/
+
+static FAR struct msgq_s *nxmsg_alloc_internal(void)
+{
+  FAR struct msgq_s *msgq;
+  FAR struct msgq_s **tmp;
+  int i;
+
+  msgq = kmm_zalloc(sizeof(struct msgq_s));
+  if (msgq == NULL)
+    {
+      return NULL;
+    }
+
+  for (i = 0; i < g_msgmgrs.nmsgq; i++)
+    {
+      if (g_msgmgrs.msgqs[i] == NULL)
+        {
+          g_msgmgrs.msgqs[i] = msgq;
+          msgq->key = i + 1;
+          return msgq;
+        }
+    }
+
+  tmp = kmm_realloc(g_msgmgrs.msgqs, sizeof(FAR void *) *
+                                            (g_msgmgrs.nmsgq + MQ_PERBLOCK));
+  if (tmp == NULL)
+    {
+      kmm_free(msgq);
+      return NULL;
+    }
+
+  g_msgmgrs.msgqs = tmp;
+
+  memset(&g_msgmgrs.msgqs[g_msgmgrs.nmsgq], 0,
+         sizeof(FAR void *) * MQ_PERBLOCK);
+
+  g_msgmgrs.msgqs[g_msgmgrs.nmsgq] = msgq;
+
+  msgq->key = g_msgmgrs.nmsgq + 1;
+
+  g_msgmgrs.nmsgq += MQ_PERBLOCK;
+
+  return msgq;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxmsg_initialize
+ ****************************************************************************/
+
+void nxmsg_initialize(void)
+{
+  FAR struct msgbuf_s *msg;
+
+  msg = (FAR struct msgbuf_s *)kmm_malloc(sizeof(*msg) *
+                                          CONFIG_PREALLOC_MQ_MSGS);
+  if (msg)
+    {
+      int i;
+      for (i = 0; i < CONFIG_PREALLOC_MQ_MSGS; i++)
+        {
+          list_add_tail(&g_msgfreelist, &msg->node);
+          msg++;
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: nxmsg_alloc
+ ****************************************************************************/
+
+int nxmsg_alloc(FAR struct msgq_s **pmsgq)
+{
+  FAR struct msgq_s *msgq;
+
+  msgq = nxmsg_alloc_internal();
+  if (msgq == NULL)
+    {
+      return -ENOMEM;
+    }
+
+  /* Initialize the new named message queue */
+
+  list_initialize(&msgq->msglist);
+
+  msgq->maxmsgs    = MSG_MAX_MSGS;
+  msgq->maxmsgsize = MSG_MAX_BYTES;
+
+  *pmsgq = msgq;
+  return OK;
+}
+
+/****************************************************************************
+ * Name: nxmsg_free
+ ****************************************************************************/
+
+void nxmsg_free(FAR struct msgq_s *msgq)
+{
+  FAR struct msgbuf_s *entry;
+  FAR struct msgbuf_s *tmp;
+  int index;
+
+  if (msgq == NULL || msgq->key <= 0 || msgq->key > g_msgmgrs.nmsgq)
+    {
+      return;
+    }
+
+  index = msgq->key - 1;
+
+  list_for_every_entry_safe(&msgq->msglist, entry,
+                            tmp, struct msgbuf_s, node)
+    {
+      list_delete(&entry->node);
+      list_add_tail(&g_msgfreelist, &entry->node);
+    }
+
+  kmm_free(g_msgmgrs.msgqs[index]);
+  g_msgmgrs.msgqs[index] = NULL;
+}
+
+/****************************************************************************
+ * Name: nxmsg_lookup
+ ****************************************************************************/
+
+FAR struct msgq_s *nxmsg_lookup(key_t key)

Review Comment:
   key_t to int



##########
sched/mqueue/msgsnd.c:
##########
@@ -0,0 +1,246 @@
+/****************************************************************************
+ * sched/mqueue/msgsnd.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: msgsnd_wait
+ ****************************************************************************/
+
+static int msgsnd_wait(FAR struct msgq_s *msgq, int msgflg)
+{
+  FAR struct tcb_s *rtcb;
+
+#ifdef CONFIG_CANCELLATION_POINTS
+  /* msgsnd_wait() is not a cancellation point, but may be called via
+   * msgsnd() which are cancellation points.
+   */
+
+  if (check_cancellation_point())
+    {
+      /* If there is a pending cancellation, then do not perform
+       * the wait.  Exit now with ECANCELED.
+       */
+
+      return -ECANCELED;
+    }
+#endif
+
+  /* Verify that the queue is indeed full as the caller thinks
+   * Loop until there are fewer than max allowable messages in the
+   * receiving message queue
+   */
+
+  while (msgq->nmsgs >= msgq->maxmsgs)
+    {
+      /* Should we block until there is sufficient space in the
+       * message queue?
+       */
+
+      if ((msgflg & IPC_NOWAIT) != 0)
+        {
+          return -EAGAIN;
+        }
+
+      /* Block until the message queue is no longer full.
+       * When we are unblocked, we will try again
+       */
+
+      rtcb          = this_task();
+      rtcb->waitobj = msgq;
+      msgq->cmn.nwaitnotfull++;
+
+      /* Initialize the errcode used to communication wake-up error
+       * conditions.
+       */
+
+      rtcb->errcode  = OK;
+
+      /* Make sure this is not the idle task, descheduling that
+       * isn't going to end well.
+       */
+
+      DEBUGASSERT(NULL != rtcb->flink);
+      up_block_task(rtcb, TSTATE_WAIT_MQNOTFULL);
+
+      /* When we resume at this point, either (1) the message queue
+       * is no longer empty, or (2) the wait has been interrupted by
+       * a signal.  We can detect the latter case be examining the
+       * per-task errno value (should be EINTR or ETIMEOUT).
+       */
+
+      if (rtcb->errcode != OK)
+        {
+          return -rtcb->errcode;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgsnd
+ *
+ * Description:
+ *   The msgsnd() function is used to send a message to the queue
+ *   associated with the message queue identifier specified by msqid.
+ *   The msgp argument points to a user-defined buffer that must contain
+ *   first a field of type long int that will specify the type of the
+ *   message, and then a data portion that will hold the data bytes of
+ *   the message.
+ *
+ * Input Parameters:
+ *   msqid  - Message queue identifier
+ *   msgp   - Pointer to a buffer with the message to be sent
+ *   msgsz  - Length of the data part of the message to be sent
+ *   msgflg - Operations flags
+ *
+ * Returned Value:
+ *   On success, mq_send() returns 0 (OK); on error, -1 (ERROR)
+ *   is returned, with errno set to indicate the error:
+ *
+ *   EAGAIN   The queue was full and the O_NONBLOCK flag was set for the
+ *            message queue description referred to by mqdes.
+ *   EINVAL   Either msg or mqdes is NULL or the value of prio is invalid.
+ *   EPERM    Message queue opened not opened for writing.
+ *   EMSGSIZE 'msglen' was greater than the maxmsgsize attribute of the
+ *            message queue.
+ *   EINTR    The call was interrupted by a signal handler.
+ *
+ ****************************************************************************/
+
+int msgsnd(int msqid, FAR const void *msgp, size_t msgsz, int msgflg)
+{
+  FAR const struct mymsg *buf = msgp;
+  FAR struct msgbuf_s *msg;
+  FAR struct msgq_s *msgq;
+  FAR struct tcb_s *btcb;
+  irqstate_t flags;
+  int ret = OK;
+
+  if (msgp == NULL)
+    {
+      ret = -EFAULT;
+      goto errout;
+    }
+
+  flags = enter_critical_section();
+
+  msgq = nxmsg_lookup(msqid);
+  if (msgq == NULL)
+    {
+      ret = -EINVAL;
+      goto errout_with_critical;
+    }
+
+  if (msgsz > msgq->maxmsgsize)
+    {
+      ret = -EMSGSIZE;
+      goto errout_with_critical;
+    }
+
+  if (!up_interrupt_context())           /* In an interrupt handler? */
+    {
+      /* No.. Not in an interrupt handler.  Is the message queue FULL? */
+
+      if (msgq->nmsgs >= msgq->maxmsgs)
+        {
+          /* Yes.. the message queue is full.  Wait for space to become
+           * available in the message queue.
+           */
+
+          ret = msgsnd_wait(msgq, msgflg);
+        }

Review Comment:
   should we return error in else branch



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1000107487


##########
sched/mqueue/msginternal.c:
##########
@@ -0,0 +1,198 @@
+/****************************************************************************
+ * sched/mqueue/msginternal.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 <nuttx/kmalloc.h>
+#include "mqueue/msg.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MQ_PERBLOCK 10
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+struct nxmsg_manager_s
+{
+  uint8_t             nmsgq;  /* The number of groups of msgs array */
+  FAR struct msgq_s **msgqs;  /* The pointer of two layer file descriptors array */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct nxmsg_manager_s g_msgmgrs;

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1001399545


##########
sched/mqueue/msgget.c:
##########
@@ -0,0 +1,84 @@
+/****************************************************************************
+ * sched/mqueue/msgget.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 "mqueue/msg.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgget
+ *
+ * Description:
+ *   Get a System V message queue identifier
+ *   The msgget() system call returns the System V message queue
+ *   identifier associated with the value of the key argument.  It may
+ *   be used either to obtain the identifier of a previously created
+ *   message queue (when msgflg is zero and key does not have the
+ *   value IPC_PRIVATE), or to create a new set.
+ *
+ * Input Parameters:
+ *   key    - Key associated with the message queue
+ *   msgflg - Operations and permissions flag
+ *
+ * Returned Value:
+ *   On success, msgget() returns the message queue identifier (a
+ *   nonnegative integer).  On failure, -1 is returned, and errno is
+ *   set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgget(key_t key, int msgflg)

Review Comment:
   Done



##########
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:
   Done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r997208839


##########
sched/mqueue/msginternal.c:
##########
@@ -0,0 +1,137 @@
+/****************************************************************************
+ * sched/mqueue/msginternal.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 <nuttx/kmalloc.h>
+#include "mqueue/msg.h"
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+struct list_node g_msgfreelist = LIST_INITIAL_VALUE(g_msgfreelist);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct list_node g_msgqactivelist =
+                        LIST_INITIAL_VALUE(g_msgqactivelist);
+static struct list_node g_msgqfreelist   =
+                        LIST_INITIAL_VALUE(g_msgqfreelist);
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxmsg_initialize
+ ****************************************************************************/
+
+void nxmsg_initialize(void)
+{
+  FAR struct msgbuf_s *msg;
+
+  msg = (FAR struct msgbuf_s *)kmm_malloc(sizeof(*msg) *
+                                          CONFIG_PREALLOC_MQ_MSGS);
+  if (msg)
+    {
+      int i;
+      for (i = 0; i < CONFIG_PREALLOC_MQ_MSGS; i++)
+        {
+          list_add_tail(&g_msgfreelist, &msg->node);
+          msg++;
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: nxmsg_alloc
+ ****************************************************************************/
+
+int nxmsg_alloc(FAR struct msgq_s **pmsgq)
+{
+  FAR struct msgq_s *msgq;
+
+  /* Allocate memory for the new message queue. */
+
+  msgq = list_remove_head_type(&g_msgqfreelist, struct msgq_s, node);
+  if (msgq == NULL)
+    {
+      msgq = (FAR struct msgq_s *)kmm_zalloc(sizeof(struct msgq_s));
+    }
+
+  if (msgq == NULL)
+    {
+      return -ENOSPC;
+    }
+
+  /* Initialize the new named message queue */
+
+  list_add_tail(&g_msgqactivelist, &msgq->node);
+  list_initialize(&msgq->msglist);
+
+  msgq->maxmsgs    = MSG_MAX_MSGS;
+  msgq->maxmsgsize = MSG_MAX_BYTES;
+
+  *pmsgq = msgq;
+  return OK;
+}
+
+/****************************************************************************
+ * Name: nxmsg_free
+ ****************************************************************************/
+
+void nxmsg_free(FAR struct msgq_s *msgq)
+{
+  FAR struct msgq_s *entry;
+  FAR struct msgq_s *tmp;
+
+  list_for_every_entry_safe(&msgq->msglist, entry, tmp, struct msgq_s, node)
+    {
+      list_delete(&entry->node);
+      list_add_tail(&g_msgfreelist, &entry->node);
+    }
+
+  list_delete(&msgq->node);
+  list_add_tail(&g_msgqfreelist, &msgq->node);
+}
+
+/****************************************************************************
+ * Name: nxmsg_lookup
+ ****************************************************************************/
+
+FAR struct msgq_s *nxmsg_lookup(key_t key)
+{
+  FAR struct msgq_s *msgq;
+
+  list_for_every_entry(&g_msgqactivelist, msgq, struct msgq_s, node)

Review Comment:
   Done



##########
fs/procfs/fs_procfsproc.c:
##########
@@ -411,7 +411,7 @@ static FAR const char * const g_statenames[] =
   "Inactive",
   "Waiting,Semaphore",
   "Waiting,Signal"
-#ifndef CONFIG_DISABLE_MQUEUE
+#if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_MQUEUE_SYSV)

Review Comment:
   Done



##########
include/nuttx/mqueue.h:
##########
@@ -83,16 +83,23 @@
  * Public Type Declarations
  ****************************************************************************/
 
+/* Common prologue of all message queue structures. */
+
+struct mqueue_comm_s
+{
+  int16_t nwaitnotfull;       /* Number tasks waiting for not full */
+  int16_t nwaitnotempty;      /* Number tasks waiting for not empty */
+};
+
 /* This structure defines a message queue */
 
 struct mqueue_inode_s
 {
+  struct mqueue_comm_s comm;  /* Common prologue */

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r999563375


##########
sched/mqueue/msginternal.c:
##########
@@ -0,0 +1,202 @@
+/****************************************************************************
+ * sched/mqueue/msginternal.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 <nuttx/kmalloc.h>
+#include "mqueue/msg.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MQ_PERBLOCK 10
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+struct nxmsglist

Review Comment:
   Done



##########
include/nuttx/mqueue.h:
##########
@@ -96,6 +96,8 @@
 
 struct mqueue_cmn_s
 {
+  dq_queue_t waitfornotempty; /* Task list waiting for not empty */
+  dq_queue_t waitfornotfull;  /* Task list waiting for not full */

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1000108292


##########
sched/mqueue/msgsnd.c:
##########
@@ -0,0 +1,246 @@
+/****************************************************************************
+ * sched/mqueue/msgsnd.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: msgsnd_wait
+ ****************************************************************************/
+
+static int msgsnd_wait(FAR struct msgq_s *msgq, int msgflg)
+{
+  FAR struct tcb_s *rtcb;
+
+#ifdef CONFIG_CANCELLATION_POINTS
+  /* msgsnd_wait() is not a cancellation point, but may be called via
+   * msgsnd() which are cancellation points.
+   */
+
+  if (check_cancellation_point())
+    {
+      /* If there is a pending cancellation, then do not perform
+       * the wait.  Exit now with ECANCELED.
+       */
+
+      return -ECANCELED;
+    }
+#endif
+
+  /* Verify that the queue is indeed full as the caller thinks
+   * Loop until there are fewer than max allowable messages in the
+   * receiving message queue
+   */
+
+  while (msgq->nmsgs >= msgq->maxmsgs)
+    {
+      /* Should we block until there is sufficient space in the
+       * message queue?
+       */
+
+      if ((msgflg & IPC_NOWAIT) != 0)
+        {
+          return -EAGAIN;
+        }
+
+      /* Block until the message queue is no longer full.
+       * When we are unblocked, we will try again
+       */
+
+      rtcb          = this_task();
+      rtcb->waitobj = msgq;
+      msgq->cmn.nwaitnotfull++;
+
+      /* Initialize the errcode used to communication wake-up error
+       * conditions.
+       */
+
+      rtcb->errcode  = OK;
+
+      /* Make sure this is not the idle task, descheduling that
+       * isn't going to end well.
+       */
+
+      DEBUGASSERT(NULL != rtcb->flink);
+      up_block_task(rtcb, TSTATE_WAIT_MQNOTFULL);
+
+      /* When we resume at this point, either (1) the message queue
+       * is no longer empty, or (2) the wait has been interrupted by
+       * a signal.  We can detect the latter case be examining the
+       * per-task errno value (should be EINTR or ETIMEOUT).
+       */
+
+      if (rtcb->errcode != OK)
+        {
+          return -rtcb->errcode;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgsnd
+ *
+ * Description:
+ *   The msgsnd() function is used to send a message to the queue
+ *   associated with the message queue identifier specified by msqid.
+ *   The msgp argument points to a user-defined buffer that must contain
+ *   first a field of type long int that will specify the type of the
+ *   message, and then a data portion that will hold the data bytes of
+ *   the message.
+ *
+ * Input Parameters:
+ *   msqid  - Message queue identifier
+ *   msgp   - Pointer to a buffer with the message to be sent
+ *   msgsz  - Length of the data part of the message to be sent
+ *   msgflg - Operations flags
+ *
+ * Returned Value:
+ *   On success, mq_send() returns 0 (OK); on error, -1 (ERROR)
+ *   is returned, with errno set to indicate the error:
+ *
+ *   EAGAIN   The queue was full and the O_NONBLOCK flag was set for the
+ *            message queue description referred to by mqdes.
+ *   EINVAL   Either msg or mqdes is NULL or the value of prio is invalid.
+ *   EPERM    Message queue opened not opened for writing.
+ *   EMSGSIZE 'msglen' was greater than the maxmsgsize attribute of the
+ *            message queue.
+ *   EINTR    The call was interrupted by a signal handler.
+ *
+ ****************************************************************************/
+
+int msgsnd(int msqid, FAR const void *msgp, size_t msgsz, int msgflg)
+{
+  FAR const struct mymsg *buf = msgp;
+  FAR struct msgbuf_s *msg;
+  FAR struct msgq_s *msgq;
+  FAR struct tcb_s *btcb;
+  irqstate_t flags;
+  int ret = OK;
+
+  if (msgp == NULL)
+    {
+      ret = -EFAULT;
+      goto errout;
+    }
+
+  flags = enter_critical_section();
+
+  msgq = nxmsg_lookup(msqid);
+  if (msgq == NULL)
+    {
+      ret = -EINVAL;
+      goto errout_with_critical;
+    }
+
+  if (msgsz > msgq->maxmsgsize)
+    {
+      ret = -EMSGSIZE;
+      goto errout_with_critical;
+    }
+
+  if (!up_interrupt_context())           /* In an interrupt handler? */
+    {
+      /* No.. Not in an interrupt handler.  Is the message queue FULL? */
+
+      if (msgq->nmsgs >= msgq->maxmsgs)
+        {
+          /* Yes.. the message queue is full.  Wait for space to become
+           * available in the message queue.
+           */
+
+          ret = msgsnd_wait(msgq, msgflg);
+        }

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1000094760


##########
sched/mqueue/msg.h:
##########
@@ -0,0 +1,98 @@
+/********************************************************************************
+ * sched/mqueue/msg.h
+ *
+ * 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.
+ *
+ ********************************************************************************/
+
+#ifndef __SCHED_MQUEUE_MSG_H
+#define __SCHED_MQUEUE_MSG_H
+
+/********************************************************************************
+ * Included Files
+ ********************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/list.h>

Review Comment:
   Done



##########
sched/mqueue/msginternal.c:
##########
@@ -0,0 +1,198 @@
+/****************************************************************************
+ * sched/mqueue/msginternal.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 <nuttx/kmalloc.h>
+#include "mqueue/msg.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MQ_PERBLOCK 10
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+struct nxmsg_manager_s
+{
+  uint8_t             nmsgq;  /* The number of groups of msgs array */
+  FAR struct msgq_s **msgqs;  /* The pointer of two layer file descriptors array */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct nxmsg_manager_s g_msgmgrs;
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+struct list_node g_msgfreelist = LIST_INITIAL_VALUE(g_msgfreelist);
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxmsg_alloc_internal
+ ****************************************************************************/
+
+static FAR struct msgq_s *nxmsg_alloc_internal(void)
+{
+  FAR struct msgq_s *msgq;
+  FAR struct msgq_s **tmp;
+  int i;
+
+  msgq = kmm_zalloc(sizeof(struct msgq_s));
+  if (msgq == NULL)
+    {
+      return NULL;
+    }
+
+  for (i = 0; i < g_msgmgrs.nmsgq; i++)
+    {
+      if (g_msgmgrs.msgqs[i] == NULL)
+        {
+          g_msgmgrs.msgqs[i] = msgq;
+          msgq->key = i + 1;
+          return msgq;
+        }
+    }
+
+  tmp = kmm_realloc(g_msgmgrs.msgqs, sizeof(FAR void *) *
+                                            (g_msgmgrs.nmsgq + MQ_PERBLOCK));

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1000095259


##########
include/sys/msg.h:
##########
@@ -0,0 +1,212 @@
+/****************************************************************************
+ * include/sys/msg.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_SYS_MSG_H
+#define __INCLUDE_SYS_MSG_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/ipc.h>
+#include <time.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct
+ * are as defined by the SV API Intel 386 Processor Supplement.
+ */
+
+#define MSG_NOERROR 010000  /* No error if message is too big */
+#define MSG_EXCEPT  020000  /* Recv any msg except of specified type.*/
+#define MSG_COPY    040000  /* Copy (not remove) all queue messages */
+
+/****************************************************************************
+ * Public Type Declarations
+ ****************************************************************************/
+
+typedef unsigned long msgqnum_t;
+typedef unsigned long msglen_t;
+
+struct msqid_ds
+{
+  struct ipc_perm msg_perm;   /* Ownership and permissions */
+  time_t          msg_stime;  /* Time of last msgsnd(2) */
+  time_t          msg_rtime;  /* Time of last msgrcv(2) */
+  time_t          msg_ctime;  /* Time of last change */
+  unsigned long   msg_cbytes; /* Current number of bytes in
+                               * queue (nonstandard) */
+  msgqnum_t       msg_qnum;   /* Current number of messages
+                               * in queue */
+  msglen_t        msg_qbytes; /* Maximum number of bytes
+                               * allowed in queue */
+  pid_t           msg_lspid;  /* PID of last msgsnd(2) */
+  pid_t           msg_lrpid;  /* PID of last msgrcv(2) */
+};
+
+/* Structure describing a message.  The SVID doesn't suggest any
+ * particular name for this structure.  There is a reference in the
+ * msgop man page that reads "The structure mymsg is an example of what
+ * this user defined buffer might look like, and includes the following
+ * members:".  This sentence is followed by two lines equivalent
+ * to the mtype and mtext field declarations below.  It isn't clear
+ * if "mymsg" refers to the name of the structure type or the name of an
+ * instance of the structure...
+ */
+
+struct mymsg
+{
+  long  mtype;    /* message type (+ve integer) */
+  char  mtext[1]; /* message body */
+};
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgctl
+ *
+ * Description:
+ *   System V message control operations.
+ *   msgctl() performs the control operation specified by cmd on the
+ *   System V message queue with identifier msqid.
+ *
+ * Input Parameters:
+ *   msqid    - System V message queue identifier
+ *   cmd      - Command operations
+ *   msqid_ds - Defines a message queue
+ *
+ * Returned Value:
+ *   On success, IPC_STAT, IPC_SET, and IPC_RMID return 0.  A
+ *   successful IPC_INFO or MSG_INFO operation returns the index of
+ *   the highest used entry in the kernel's internal array recording
+ *   information about all message queues.  (This information can be
+ *   used with repeated MSG_STAT or MSG_STAT_ANY operations to obtain
+ *   information about all queues on the system.)  A successful
+ *   MSG_STAT or MSG_STAT_ANY operation returns the identifier of the
+ *   queue whose index was given in msqid.
+ *
+ *   On failure, -1 is returned and errno is set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgctl(int msqid, int cmd, FAR struct msqid_ds *buf);
+
+/****************************************************************************
+ * Name: msgget
+ *
+ * Description:
+ *   Get a System V message queue identifier
+ *   The msgget() system call returns the System V message queue
+ *   identifier associated with the value of the key argument.  It may
+ *   be used either to obtain the identifier of a previously created
+ *   message queue (when msgflg is zero and key does not have the
+ *   value IPC_PRIVATE), or to create a new set.
+ *
+ * Input Parameters:
+ *   key    - Key associated with the message queue
+ *   msgflg - Operations and permissions flag
+ *
+ * Returned Value:
+ *   On success, msgget() returns the message queue identifier (a
+ *   nonnegative integer).  On failure, -1 is returned, and errno is
+ *   set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgget(key_t key, int msgflg);
+
+/****************************************************************************
+ * Name: msgsnd
+ *
+ * Description:
+ *   The msgsnd() function is used to send a message to the queue
+ *   associated with the message queue identifier specified by msqid.
+ *   The msgp argument points to a user-defined buffer that must contain
+ *   first a field of type long int that will specify the type of the
+ *   message, and then a data portion that will hold the data bytes of
+ *   the message.
+ *
+ * Input Parameters:
+ *   msqid  - Message queue identifier
+ *   msgp   - Pointer to a buffer with the message to be sent
+ *   msgsz  - Length of the data part of the message to be sent
+ *   msgflg - Operations flags
+ *
+ * Returned Value:
+ *   On success, mq_send() returns 0 (OK); on error, -1 (ERROR)
+ *   is returned, with errno set to indicate the error:
+ *
+ *   EAGAIN   The queue was full and the O_NONBLOCK flag was set for the
+ *            message queue description referred to by mqdes.
+ *   EINVAL   Either msg or mqdes is NULL or the value of prio is invalid.
+ *   EPERM    Message queue opened not opened for writing.
+ *   EMSGSIZE 'msglen' was greater than the maxmsgsize attribute of the
+ *            message queue.
+ *   EINTR    The call was interrupted by a signal handler.
+ *
+ ****************************************************************************/
+
+int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r997306041


##########
include/nuttx/mqueue.h:
##########
@@ -83,16 +83,23 @@
  * Public Type Declarations
  ****************************************************************************/
 
+/* Common prologue of all message queue structures. */
+
+struct mqueue_comm_s
+{
+  int16_t nwaitnotfull;       /* Number tasks waiting for not full */
+  int16_t nwaitnotempty;      /* Number tasks waiting for not empty */
+};
+
 /* This structure defines a message queue */
 
 struct mqueue_inode_s
 {
+  struct mqueue_comm_s comm;  /* Common prologue */

Review Comment:
   no change?



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1000107066


##########
sched/mqueue/msg.h:
##########
@@ -0,0 +1,98 @@
+/********************************************************************************
+ * sched/mqueue/msg.h
+ *
+ * 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.
+ *
+ ********************************************************************************/
+
+#ifndef __SCHED_MQUEUE_MSG_H
+#define __SCHED_MQUEUE_MSG_H
+
+/********************************************************************************
+ * Included Files
+ ********************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/list.h>
+#include <nuttx/mqueue.h>
+#include <sys/msg.h>
+
+#include <errno.h>
+
+#if defined(CONFIG_MQ_MAXMSGSIZE) && CONFIG_MQ_MAXMSGSIZE > 0
+
+/********************************************************************************
+ * Pre-processor Definitions
+ ********************************************************************************/
+
+#define MSG_MAX_BYTES   CONFIG_MQ_MAXMSGSIZE
+#define MSG_MAX_MSGS    16
+
+/********************************************************************************
+ * Public Type Definitions
+ ********************************************************************************/
+
+struct msgq_s
+{
+  struct mqueue_cmn_s  cmn;
+  struct list_node     msglist;       /* Prioritized message list */
+  key_t                key;
+  int16_t              maxmsgs;       /* Maximum number of messages in the queue */
+  int16_t              nmsgs;         /* Number of message in the queue */
+  uint16_t             maxmsgsize;    /* Max size of message in message queue */
+};
+
+struct msgbuf_s
+{
+  struct list_node node;
+  uint16_t         msize;                /* Message data length */
+  long             mtype;                /* Message type, must be > 0 */
+  char             mtext[MSG_MAX_BYTES]; /* Message data */
+};
+
+/********************************************************************************
+ * Public Data
+ ********************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+EXTERN struct list_node g_msgfreelist;
+
+/********************************************************************************

Review Comment:
   Done



##########
sched/mqueue/msgctl.c:
##########
@@ -0,0 +1,124 @@
+/****************************************************************************
+ * sched/mqueue/msgctl.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 "mqueue/msg.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgctl
+ *
+ * Description:
+ *   System V message control operations.
+ *   msgctl() performs the control operation specified by cmd on the
+ *   System V message queue with identifier msqid.
+ *
+ * Input Parameters:
+ *   msqid    - System V message queue identifier
+ *   cmd      - Command operations
+ *   msqid_ds - Defines a message queue
+ *
+ * Returned Value:
+ *   On success, IPC_STAT, IPC_SET, and IPC_RMID return 0.  A
+ *   successful IPC_INFO or MSG_INFO operation returns the index of
+ *   the highest used entry in the kernel's internal array recording
+ *   information about all message queues.  (This information can be
+ *   used with repeated MSG_STAT or MSG_STAT_ANY operations to obtain
+ *   information about all queues on the system.)  A successful
+ *   MSG_STAT or MSG_STAT_ANY operation returns the identifier of the
+ *   queue whose index was given in msqid.
+ *
+ *   On failure, -1 is returned and errno is set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgctl(int msqid, int cmd, struct msqid_ds *buf)
+{
+  FAR struct msgq_s *msgq;
+  irqstate_t flags;
+  int ret = OK;
+
+  flags = enter_critical_section();
+
+  msgq = nxmsg_lookup((key_t)msqid);

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1001077687


##########
sched/mqueue/msgget.c:
##########
@@ -0,0 +1,84 @@
+/****************************************************************************
+ * sched/mqueue/msgget.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 "mqueue/msg.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgget
+ *
+ * Description:
+ *   Get a System V message queue identifier
+ *   The msgget() system call returns the System V message queue
+ *   identifier associated with the value of the key argument.  It may
+ *   be used either to obtain the identifier of a previously created
+ *   message queue (when msgflg is zero and key does not have the
+ *   value IPC_PRIVATE), or to create a new set.
+ *
+ * Input Parameters:
+ *   key    - Key associated with the message queue
+ *   msgflg - Operations and permissions flag
+ *
+ * Returned Value:
+ *   On success, msgget() returns the message queue identifier (a
+ *   nonnegative integer).  On failure, -1 is returned, and errno is
+ *   set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgget(key_t key, int msgflg)

Review Comment:
   Do we need to use `key_t` or `int` for key?



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r999746287


##########
include/nuttx/mqueue.h:
##########
@@ -85,25 +85,32 @@
 # define nxmq_pollnotify(msgq, eventset)
 #endif
 
-# define MQ_WNELIST(mq)               (&((mq)->waitfornotempty))
-# define MQ_WNFLIST(mq)               (&((mq)->waitfornotfull))
+# define MQ_WNELIST(cmn)              (&((cmn).waitfornotempty))
+# define MQ_WNFLIST(cmn)              (&((cmn).waitfornotfull))
 
 /****************************************************************************
  * Public Type Declarations
  ****************************************************************************/
 
+/* Common prologue of all message queue structures. */
+
+struct mqueue_cmn_s
+{
+  dq_queue_t waitfornotempty; /* Task list waiting for not empty */
+  dq_queue_t waitfornotfull;  /* Task list waiting for not full */
+  int16_t nwaitnotfull;       /* Number tasks waiting for not full */
+  int16_t nwaitnotempty;      /* Number tasks waiting for not empty */
+};
+
 /* This structure defines a message queue */
 
 struct mqueue_inode_s
 {
+  struct mqueue_cmn_s cmn;    /* Common prologue */

Review Comment:
   This follow task_tcb_s and pthread_tcb_s name the shared state as `struct tcb_s cmn`



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r999747461


##########
include/nuttx/mqueue.h:
##########
@@ -85,25 +85,32 @@
 # define nxmq_pollnotify(msgq, eventset)
 #endif
 
-# define MQ_WNELIST(mq)               (&((mq)->waitfornotempty))
-# define MQ_WNFLIST(mq)               (&((mq)->waitfornotfull))
+# define MQ_WNELIST(cmn)              (&((cmn).waitfornotempty))
+# define MQ_WNFLIST(cmn)              (&((cmn).waitfornotfull))
 
 /****************************************************************************
  * Public Type Declarations
  ****************************************************************************/
 
+/* Common prologue of all message queue structures. */
+
+struct mqueue_cmn_s
+{
+  dq_queue_t waitfornotempty; /* Task list waiting for not empty */
+  dq_queue_t waitfornotfull;  /* Task list waiting for not full */
+  int16_t nwaitnotfull;       /* Number tasks waiting for not full */
+  int16_t nwaitnotempty;      /* Number tasks waiting for not empty */
+};
+
 /* This structure defines a message queue */
 
 struct mqueue_inode_s
 {
+  struct mqueue_cmn_s cmn;    /* Common prologue */

Review Comment:
   Ok. If that is already used then let's keep it



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1000094888


##########
sched/mqueue/msgctl.c:
##########
@@ -0,0 +1,124 @@
+/****************************************************************************
+ * sched/mqueue/msgctl.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 "mqueue/msg.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgctl
+ *
+ * Description:
+ *   System V message control operations.
+ *   msgctl() performs the control operation specified by cmd on the
+ *   System V message queue with identifier msqid.
+ *
+ * Input Parameters:
+ *   msqid    - System V message queue identifier
+ *   cmd      - Command operations
+ *   msqid_ds - Defines a message queue
+ *
+ * Returned Value:
+ *   On success, IPC_STAT, IPC_SET, and IPC_RMID return 0.  A
+ *   successful IPC_INFO or MSG_INFO operation returns the index of
+ *   the highest used entry in the kernel's internal array recording
+ *   information about all message queues.  (This information can be
+ *   used with repeated MSG_STAT or MSG_STAT_ANY operations to obtain
+ *   information about all queues on the system.)  A successful
+ *   MSG_STAT or MSG_STAT_ANY operation returns the identifier of the
+ *   queue whose index was given in msqid.
+ *
+ *   On failure, -1 is returned and errno is set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgctl(int msqid, int cmd, struct msqid_ds *buf)

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r998508458


##########
include/nuttx/mqueue.h:
##########
@@ -96,6 +96,8 @@
 
 struct mqueue_cmn_s
 {
+  dq_queue_t waitfornotempty; /* Task list waiting for not empty */
+  dq_queue_t waitfornotfull;  /* Task list waiting for not full */

Review Comment:
   Move the related change to the previous patch too



##########
sched/mqueue/msginternal.c:
##########
@@ -0,0 +1,202 @@
+/****************************************************************************
+ * sched/mqueue/msginternal.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 <nuttx/kmalloc.h>
+#include "mqueue/msg.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MQ_PERBLOCK 10
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+struct nxmsglist

Review Comment:
   change to other name since we don't use list now



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1000098656


##########
sched/mqueue/msg.h:
##########
@@ -0,0 +1,98 @@
+/********************************************************************************
+ * sched/mqueue/msg.h
+ *
+ * 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.
+ *
+ ********************************************************************************/
+
+#ifndef __SCHED_MQUEUE_MSG_H
+#define __SCHED_MQUEUE_MSG_H
+
+/********************************************************************************
+ * Included Files
+ ********************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/list.h>
+#include <nuttx/mqueue.h>
+#include <sys/msg.h>
+
+#include <errno.h>
+
+#if defined(CONFIG_MQ_MAXMSGSIZE) && CONFIG_MQ_MAXMSGSIZE > 0
+
+/********************************************************************************
+ * Pre-processor Definitions
+ ********************************************************************************/
+
+#define MSG_MAX_BYTES   CONFIG_MQ_MAXMSGSIZE
+#define MSG_MAX_MSGS    16
+
+/********************************************************************************
+ * Public Type Definitions
+ ********************************************************************************/
+
+struct msgq_s
+{
+  struct mqueue_cmn_s  cmn;
+  struct list_node     msglist;       /* Prioritized message list */
+  key_t                key;
+  int16_t              maxmsgs;       /* Maximum number of messages in the queue */
+  int16_t              nmsgs;         /* Number of message in the queue */
+  uint16_t             maxmsgsize;    /* Max size of message in message queue */
+};
+
+struct msgbuf_s
+{
+  struct list_node node;
+  uint16_t         msize;                /* Message data length */
+  long             mtype;                /* Message type, must be > 0 */
+  char             mtext[MSG_MAX_BYTES]; /* Message data */
+};
+
+/********************************************************************************
+ * Public Data
+ ********************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+EXTERN struct list_node g_msgfreelist;

Review Comment:
   reference from other files:
   
   sched/mqueue/msgrcv.c:219:  list_add_tail(&g_msgfreelist, &msg->node);
   sched/mqueue/msgsnd.c:194:      msg = (FAR struct msgbuf_s *)list_remove_head(&g_msgfreelist);
   sched/mqueue/msginternal.c:54:struct list_node g_msgfreelist = LIST_INITIAL_VALUE(g_msgfreelist);
   sched/mqueue/msginternal.c:127:          list_add_tail(&g_msgfreelist, &msg->node);
   sched/mqueue/msginternal.c:179:      list_add_tail(&g_msgfreelist, &entry->node);
   sched/mqueue/msg.h:79:EXTERN struct list_node g_msgfreelist;
   



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] xiaoxiang781216 merged pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088


-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r997208581


##########
include/nuttx/mqueue.h:
##########
@@ -83,16 +83,23 @@
  * Public Type Declarations
  ****************************************************************************/
 
+/* Common prologue of all message queue structures. */
+
+struct mqueue_comm_s

Review Comment:
   Done



##########
sched/mqueue/msgget.c:
##########
@@ -0,0 +1,95 @@
+/****************************************************************************
+ * sched/mqueue/msgget.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 "mqueue/msg.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgget
+ *
+ * Description:
+ *   Get a System V message queue identifier
+ *   The msgget() system call returns the System V message queue
+ *   identifier associated with the value of the key argument.  It may
+ *   be used either to obtain the identifier of a previously created
+ *   message queue (when msgflg is zero and key does not have the
+ *   value IPC_PRIVATE), or to create a new set.
+ *
+ * Input Parameters:
+ *   key    - Key associated with the message queue
+ *   msgflg - Operations and permissions flag
+ *
+ * Returned Value:
+ *   On success, msgget() returns the message queue identifier (a
+ *   nonnegative integer).  On failure, -1 is returned, and errno is
+ *   set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgget(key_t key, int msgflg)
+{
+  FAR struct msgq_s *msgq;
+  irqstate_t flags;
+  int ret = OK;
+
+  flags = enter_critical_section();
+
+  msgq = nxmsg_lookup(key);
+
+  if (msgq)
+    {
+      if ((msgflg & IPC_CREAT) && (msgflg & IPC_EXCL))
+        {
+          ret = -EEXIST;
+        }
+    }
+  else
+    {
+      if (key != IPC_PRIVATE && !(msgflg & IPC_CREAT))

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r997303996


##########
include/nuttx/mqueue.h:
##########
@@ -83,16 +83,23 @@
  * Public Type Declarations
  ****************************************************************************/
 
+/* Common prologue of all message queue structures. */
+
+struct mqueue_comm_s

Review Comment:
   no change?



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r999598724


##########
include/sys/msg.h:
##########
@@ -0,0 +1,212 @@
+/****************************************************************************
+ * include/sys/msg.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_SYS_MSG_H
+#define __INCLUDE_SYS_MSG_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/ipc.h>
+#include <time.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct
+ * are as defined by the SV API Intel 386 Processor Supplement.
+ */
+
+#define MSG_NOERROR 010000  /* No error if message is too big */
+#define MSG_EXCEPT  020000  /* Recv any msg except of specified type.*/
+#define MSG_COPY    040000  /* Copy (not remove) all queue messages */
+
+/****************************************************************************
+ * Public Type Declarations
+ ****************************************************************************/
+
+typedef unsigned long msgqnum_t;
+typedef unsigned long msglen_t;
+
+struct msqid_ds
+{
+  struct ipc_perm msg_perm;   /* Ownership and permissions */
+  time_t          msg_stime;  /* Time of last msgsnd(2) */
+  time_t          msg_rtime;  /* Time of last msgrcv(2) */
+  time_t          msg_ctime;  /* Time of last change */
+  unsigned long   msg_cbytes; /* Current number of bytes in
+                               * queue (nonstandard) */
+  msgqnum_t       msg_qnum;   /* Current number of messages
+                               * in queue */
+  msglen_t        msg_qbytes; /* Maximum number of bytes
+                               * allowed in queue */
+  pid_t           msg_lspid;  /* PID of last msgsnd(2) */
+  pid_t           msg_lrpid;  /* PID of last msgrcv(2) */
+};
+
+/* Structure describing a message.  The SVID doesn't suggest any
+ * particular name for this structure.  There is a reference in the
+ * msgop man page that reads "The structure mymsg is an example of what
+ * this user defined buffer might look like, and includes the following
+ * members:".  This sentence is followed by two lines equivalent
+ * to the mtype and mtext field declarations below.  It isn't clear
+ * if "mymsg" refers to the name of the structure type or the name of an
+ * instance of the structure...
+ */
+
+struct mymsg
+{
+  long  mtype;    /* message type (+ve integer) */
+  char  mtext[1]; /* message body */
+};
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgctl
+ *
+ * Description:
+ *   System V message control operations.
+ *   msgctl() performs the control operation specified by cmd on the
+ *   System V message queue with identifier msqid.
+ *
+ * Input Parameters:
+ *   msqid    - System V message queue identifier
+ *   cmd      - Command operations
+ *   msqid_ds - Defines a message queue
+ *
+ * Returned Value:
+ *   On success, IPC_STAT, IPC_SET, and IPC_RMID return 0.  A
+ *   successful IPC_INFO or MSG_INFO operation returns the index of
+ *   the highest used entry in the kernel's internal array recording
+ *   information about all message queues.  (This information can be
+ *   used with repeated MSG_STAT or MSG_STAT_ANY operations to obtain
+ *   information about all queues on the system.)  A successful
+ *   MSG_STAT or MSG_STAT_ANY operation returns the identifier of the
+ *   queue whose index was given in msqid.
+ *
+ *   On failure, -1 is returned and errno is set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgctl(int msqid, int cmd, FAR struct msqid_ds *buf);
+
+/****************************************************************************
+ * Name: msgget
+ *
+ * Description:
+ *   Get a System V message queue identifier
+ *   The msgget() system call returns the System V message queue
+ *   identifier associated with the value of the key argument.  It may
+ *   be used either to obtain the identifier of a previously created
+ *   message queue (when msgflg is zero and key does not have the
+ *   value IPC_PRIVATE), or to create a new set.
+ *
+ * Input Parameters:
+ *   key    - Key associated with the message queue
+ *   msgflg - Operations and permissions flag
+ *
+ * Returned Value:
+ *   On success, msgget() returns the message queue identifier (a
+ *   nonnegative integer).  On failure, -1 is returned, and errno is
+ *   set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgget(key_t key, int msgflg);
+
+/****************************************************************************
+ * Name: msgsnd
+ *
+ * Description:
+ *   The msgsnd() function is used to send a message to the queue
+ *   associated with the message queue identifier specified by msqid.
+ *   The msgp argument points to a user-defined buffer that must contain
+ *   first a field of type long int that will specify the type of the
+ *   message, and then a data portion that will hold the data bytes of
+ *   the message.
+ *
+ * Input Parameters:
+ *   msqid  - Message queue identifier
+ *   msgp   - Pointer to a buffer with the message to be sent
+ *   msgsz  - Length of the data part of the message to be sent
+ *   msgflg - Operations flags
+ *
+ * Returned Value:
+ *   On success, mq_send() returns 0 (OK); on error, -1 (ERROR)
+ *   is returned, with errno set to indicate the error:
+ *
+ *   EAGAIN   The queue was full and the O_NONBLOCK flag was set for the
+ *            message queue description referred to by mqdes.
+ *   EINVAL   Either msg or mqdes is NULL or the value of prio is invalid.
+ *   EPERM    Message queue opened not opened for writing.
+ *   EMSGSIZE 'msglen' was greater than the maxmsgsize attribute of the
+ *            message queue.
+ *   EINTR    The call was interrupted by a signal handler.
+ *
+ ****************************************************************************/
+
+int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
+
+/****************************************************************************
+ * Name: msgrcv
+ *
+ * Description:
+ *   The msgrcv() function reads a message from the message queue specified
+ *   by the msqid parameter and places it in the user-defined buffer
+ *   pointed to by the *msgp parameter.
+ *
+ * Input Parameters:
+ *   msqid  - Message queue identifier
+ *   msgp   - Pointer to a buffer in which the received message will be
+ *            stored
+ *   msgsz  - Length of the data part of the buffer
+ *   msgtyp - Type of message to be received.
+ *   msgflg - Operations flags.
+ *
+ * Returned Value:
+ *   On success, msgrcv() returns the number of bytes actually copied
+ *   into the mtext array.
+ *   On failure, both functions return -1, and set errno to indicate
+ *   the error.
+ *
+ ****************************************************************************/
+
+ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg);

Review Comment:
   ```suggestion
   ssize_t msgrcv(int msqid, FAR void *msgp, size_t msgsz, long msgtyp, int msgflg);
   ```



##########
sched/mqueue/msg.h:
##########
@@ -0,0 +1,98 @@
+/********************************************************************************
+ * sched/mqueue/msg.h
+ *
+ * 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.
+ *
+ ********************************************************************************/
+
+#ifndef __SCHED_MQUEUE_MSG_H
+#define __SCHED_MQUEUE_MSG_H
+
+/********************************************************************************
+ * Included Files
+ ********************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/list.h>
+#include <nuttx/mqueue.h>
+#include <sys/msg.h>
+
+#include <errno.h>
+
+#if defined(CONFIG_MQ_MAXMSGSIZE) && CONFIG_MQ_MAXMSGSIZE > 0
+
+/********************************************************************************
+ * Pre-processor Definitions
+ ********************************************************************************/
+
+#define MSG_MAX_BYTES   CONFIG_MQ_MAXMSGSIZE
+#define MSG_MAX_MSGS    16
+
+/********************************************************************************
+ * Public Type Definitions
+ ********************************************************************************/
+
+struct msgq_s
+{
+  struct mqueue_cmn_s  cmn;
+  struct list_node     msglist;       /* Prioritized message list */
+  key_t                key;
+  int16_t              maxmsgs;       /* Maximum number of messages in the queue */
+  int16_t              nmsgs;         /* Number of message in the queue */
+  uint16_t             maxmsgsize;    /* Max size of message in message queue */
+};
+
+struct msgbuf_s
+{
+  struct list_node node;
+  uint16_t         msize;                /* Message data length */
+  long             mtype;                /* Message type, must be > 0 */
+  char             mtext[MSG_MAX_BYTES]; /* Message data */
+};
+
+/********************************************************************************
+ * Public Data
+ ********************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+EXTERN struct list_node g_msgfreelist;
+
+/********************************************************************************
+ * Public Function Prototypes
+ ********************************************************************************/
+
+void               nxmsg_initialize(void);
+int                nxmsg_alloc(FAR struct msgq_s **pmsgq);
+void               nxmsg_free(FAR struct msgq_s *msgq);
+FAR struct msgq_s *nxmsg_lookup(key_t key);

Review Comment:
   description is missing



##########
sched/mqueue/msginternal.c:
##########
@@ -0,0 +1,198 @@
+/****************************************************************************
+ * sched/mqueue/msginternal.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 <nuttx/kmalloc.h>
+#include "mqueue/msg.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MQ_PERBLOCK 10
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+struct nxmsg_manager_s
+{
+  uint8_t             nmsgq;  /* The number of groups of msgs array */
+  FAR struct msgq_s **msgqs;  /* The pointer of two layer file descriptors array */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct nxmsg_manager_s g_msgmgrs;
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+struct list_node g_msgfreelist = LIST_INITIAL_VALUE(g_msgfreelist);
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxmsg_alloc_internal
+ ****************************************************************************/
+
+static FAR struct msgq_s *nxmsg_alloc_internal(void)
+{
+  FAR struct msgq_s *msgq;
+  FAR struct msgq_s **tmp;
+  int i;
+
+  msgq = kmm_zalloc(sizeof(struct msgq_s));
+  if (msgq == NULL)
+    {
+      return NULL;
+    }
+
+  for (i = 0; i < g_msgmgrs.nmsgq; i++)
+    {
+      if (g_msgmgrs.msgqs[i] == NULL)
+        {
+          g_msgmgrs.msgqs[i] = msgq;
+          msgq->key = i + 1;
+          return msgq;
+        }
+    }
+
+  tmp = kmm_realloc(g_msgmgrs.msgqs, sizeof(FAR void *) *
+                                            (g_msgmgrs.nmsgq + MQ_PERBLOCK));

Review Comment:
   ```suggestion
     tmp = kmm_realloc(g_msgmgrs.msgqs, sizeof(FAR void *) *
                       (g_msgmgrs.nmsgq + MQ_PERBLOCK));
   ```



##########
sched/mqueue/msg.h:
##########
@@ -0,0 +1,98 @@
+/********************************************************************************
+ * sched/mqueue/msg.h
+ *
+ * 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.
+ *
+ ********************************************************************************/
+
+#ifndef __SCHED_MQUEUE_MSG_H
+#define __SCHED_MQUEUE_MSG_H
+
+/********************************************************************************
+ * Included Files
+ ********************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/list.h>
+#include <nuttx/mqueue.h>
+#include <sys/msg.h>
+
+#include <errno.h>
+
+#if defined(CONFIG_MQ_MAXMSGSIZE) && CONFIG_MQ_MAXMSGSIZE > 0
+
+/********************************************************************************
+ * Pre-processor Definitions
+ ********************************************************************************/
+
+#define MSG_MAX_BYTES   CONFIG_MQ_MAXMSGSIZE
+#define MSG_MAX_MSGS    16
+
+/********************************************************************************
+ * Public Type Definitions
+ ********************************************************************************/
+
+struct msgq_s
+{
+  struct mqueue_cmn_s  cmn;
+  struct list_node     msglist;       /* Prioritized message list */
+  key_t                key;
+  int16_t              maxmsgs;       /* Maximum number of messages in the queue */
+  int16_t              nmsgs;         /* Number of message in the queue */
+  uint16_t             maxmsgsize;    /* Max size of message in message queue */
+};
+
+struct msgbuf_s
+{
+  struct list_node node;
+  uint16_t         msize;                /* Message data length */
+  long             mtype;                /* Message type, must be > 0 */
+  char             mtext[MSG_MAX_BYTES]; /* Message data */
+};
+
+/********************************************************************************
+ * Public Data
+ ********************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+EXTERN struct list_node g_msgfreelist;
+
+/********************************************************************************

Review Comment:
   comments in this file seems to be too long



##########
include/nuttx/mqueue.h:
##########
@@ -85,25 +85,32 @@
 # define nxmq_pollnotify(msgq, eventset)
 #endif
 
-# define MQ_WNELIST(mq)               (&((mq)->waitfornotempty))
-# define MQ_WNFLIST(mq)               (&((mq)->waitfornotfull))
+# define MQ_WNELIST(cmn)              (&((cmn).waitfornotempty))
+# define MQ_WNFLIST(cmn)              (&((cmn).waitfornotfull))
 
 /****************************************************************************
  * Public Type Declarations
  ****************************************************************************/
 
+/* Common prologue of all message queue structures. */
+
+struct mqueue_cmn_s
+{
+  dq_queue_t waitfornotempty; /* Task list waiting for not empty */
+  dq_queue_t waitfornotfull;  /* Task list waiting for not full */
+  int16_t nwaitnotfull;       /* Number tasks waiting for not full */
+  int16_t nwaitnotempty;      /* Number tasks waiting for not empty */
+};
+
 /* This structure defines a message queue */
 
 struct mqueue_inode_s
 {
+  struct mqueue_cmn_s cmn;    /* Common prologue */

Review Comment:
   Can we name it something like `struct mqueue_wait_node_s wnode;`? This is just a suggestion.



##########
sched/mqueue/msgctl.c:
##########
@@ -0,0 +1,124 @@
+/****************************************************************************
+ * sched/mqueue/msgctl.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 "mqueue/msg.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgctl
+ *
+ * Description:
+ *   System V message control operations.
+ *   msgctl() performs the control operation specified by cmd on the
+ *   System V message queue with identifier msqid.
+ *
+ * Input Parameters:
+ *   msqid    - System V message queue identifier
+ *   cmd      - Command operations
+ *   msqid_ds - Defines a message queue
+ *
+ * Returned Value:
+ *   On success, IPC_STAT, IPC_SET, and IPC_RMID return 0.  A
+ *   successful IPC_INFO or MSG_INFO operation returns the index of
+ *   the highest used entry in the kernel's internal array recording
+ *   information about all message queues.  (This information can be
+ *   used with repeated MSG_STAT or MSG_STAT_ANY operations to obtain
+ *   information about all queues on the system.)  A successful
+ *   MSG_STAT or MSG_STAT_ANY operation returns the identifier of the
+ *   queue whose index was given in msqid.
+ *
+ *   On failure, -1 is returned and errno is set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgctl(int msqid, int cmd, struct msqid_ds *buf)

Review Comment:
   ```suggestion
   int msgctl(int msqid, int cmd, FAR struct msqid_ds *buf)
   ```



##########
include/sys/msg.h:
##########
@@ -0,0 +1,212 @@
+/****************************************************************************
+ * include/sys/msg.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_SYS_MSG_H
+#define __INCLUDE_SYS_MSG_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/ipc.h>
+#include <time.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct
+ * are as defined by the SV API Intel 386 Processor Supplement.
+ */
+
+#define MSG_NOERROR 010000  /* No error if message is too big */
+#define MSG_EXCEPT  020000  /* Recv any msg except of specified type.*/
+#define MSG_COPY    040000  /* Copy (not remove) all queue messages */
+
+/****************************************************************************
+ * Public Type Declarations
+ ****************************************************************************/
+
+typedef unsigned long msgqnum_t;
+typedef unsigned long msglen_t;
+
+struct msqid_ds
+{
+  struct ipc_perm msg_perm;   /* Ownership and permissions */
+  time_t          msg_stime;  /* Time of last msgsnd(2) */
+  time_t          msg_rtime;  /* Time of last msgrcv(2) */
+  time_t          msg_ctime;  /* Time of last change */
+  unsigned long   msg_cbytes; /* Current number of bytes in
+                               * queue (nonstandard) */
+  msgqnum_t       msg_qnum;   /* Current number of messages
+                               * in queue */
+  msglen_t        msg_qbytes; /* Maximum number of bytes
+                               * allowed in queue */
+  pid_t           msg_lspid;  /* PID of last msgsnd(2) */
+  pid_t           msg_lrpid;  /* PID of last msgrcv(2) */
+};
+
+/* Structure describing a message.  The SVID doesn't suggest any
+ * particular name for this structure.  There is a reference in the
+ * msgop man page that reads "The structure mymsg is an example of what
+ * this user defined buffer might look like, and includes the following
+ * members:".  This sentence is followed by two lines equivalent
+ * to the mtype and mtext field declarations below.  It isn't clear
+ * if "mymsg" refers to the name of the structure type or the name of an
+ * instance of the structure...
+ */
+
+struct mymsg
+{
+  long  mtype;    /* message type (+ve integer) */
+  char  mtext[1]; /* message body */
+};
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgctl
+ *
+ * Description:
+ *   System V message control operations.
+ *   msgctl() performs the control operation specified by cmd on the
+ *   System V message queue with identifier msqid.
+ *
+ * Input Parameters:
+ *   msqid    - System V message queue identifier
+ *   cmd      - Command operations
+ *   msqid_ds - Defines a message queue
+ *
+ * Returned Value:
+ *   On success, IPC_STAT, IPC_SET, and IPC_RMID return 0.  A
+ *   successful IPC_INFO or MSG_INFO operation returns the index of
+ *   the highest used entry in the kernel's internal array recording
+ *   information about all message queues.  (This information can be
+ *   used with repeated MSG_STAT or MSG_STAT_ANY operations to obtain
+ *   information about all queues on the system.)  A successful
+ *   MSG_STAT or MSG_STAT_ANY operation returns the identifier of the
+ *   queue whose index was given in msqid.
+ *
+ *   On failure, -1 is returned and errno is set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgctl(int msqid, int cmd, FAR struct msqid_ds *buf);
+
+/****************************************************************************
+ * Name: msgget
+ *
+ * Description:
+ *   Get a System V message queue identifier
+ *   The msgget() system call returns the System V message queue
+ *   identifier associated with the value of the key argument.  It may
+ *   be used either to obtain the identifier of a previously created
+ *   message queue (when msgflg is zero and key does not have the
+ *   value IPC_PRIVATE), or to create a new set.
+ *
+ * Input Parameters:
+ *   key    - Key associated with the message queue
+ *   msgflg - Operations and permissions flag
+ *
+ * Returned Value:
+ *   On success, msgget() returns the message queue identifier (a
+ *   nonnegative integer).  On failure, -1 is returned, and errno is
+ *   set to indicate the error.
+ *
+ ****************************************************************************/
+
+int msgget(key_t key, int msgflg);
+
+/****************************************************************************
+ * Name: msgsnd
+ *
+ * Description:
+ *   The msgsnd() function is used to send a message to the queue
+ *   associated with the message queue identifier specified by msqid.
+ *   The msgp argument points to a user-defined buffer that must contain
+ *   first a field of type long int that will specify the type of the
+ *   message, and then a data portion that will hold the data bytes of
+ *   the message.
+ *
+ * Input Parameters:
+ *   msqid  - Message queue identifier
+ *   msgp   - Pointer to a buffer with the message to be sent
+ *   msgsz  - Length of the data part of the message to be sent
+ *   msgflg - Operations flags
+ *
+ * Returned Value:
+ *   On success, mq_send() returns 0 (OK); on error, -1 (ERROR)
+ *   is returned, with errno set to indicate the error:
+ *
+ *   EAGAIN   The queue was full and the O_NONBLOCK flag was set for the
+ *            message queue description referred to by mqdes.
+ *   EINVAL   Either msg or mqdes is NULL or the value of prio is invalid.
+ *   EPERM    Message queue opened not opened for writing.
+ *   EMSGSIZE 'msglen' was greater than the maxmsgsize attribute of the
+ *            message queue.
+ *   EINTR    The call was interrupted by a signal handler.
+ *
+ ****************************************************************************/
+
+int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);

Review Comment:
   ```suggestion
   int msgsnd(int msqid, FAR const void *msgp, size_t msgsz, int msgflg);
   ```



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1001401312


##########
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 ||
+                   ((FAR struct msgbuf_s *)node)->mtype == msgtyp)
+            {
+              newmsg = node;
+              break;
+            }
+        }
+
+      if (newmsg)
+        {
+          list_delete(newmsg);
+          goto found;
+        }
+
+      if ((msgflg & IPC_NOWAIT) != 0)
+        {
+          return -EAGAIN;
+        }
+
+      /* The queue is empty!  Should we block until there the above condition
+       * has been satisfied?
+       */
+
+      rtcb          = this_task();
+      rtcb->waitobj = msgq;
+      msgq->cmn.nwaitnotempty++;
+
+      /* Initialize the 'errcode" used to communication wake-up error
+       * conditions.
+       */
+
+      rtcb->errcode  = OK;
+
+      /* Make sure this is not the idle task, descheduling that
+       * isn't going to end well.
+       */
+
+      DEBUGASSERT(NULL != rtcb->flink);
+      up_block_task(rtcb, TSTATE_WAIT_MQNOTEMPTY);
+
+      /* When we resume at this point, either (1) the message queue
+       * is no longer empty, or (2) the wait has been interrupted by
+       * a signal.  We can detect the latter case be examining the
+       * errno value (should be either EINTR or ETIMEDOUT).
+       */
+
+      if (rtcb->errcode != OK)
+        {
+          return -rtcb->errcode;
+        }
+    }
+
+found:
+  *rcvmsg = (FAR struct msgbuf_s *)newmsg;
+  return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: msgrcv
+ *
+ * Description:
+ *   The msgrcv() function reads a message from the message queue specified
+ *   by the msqid parameter and places it in the user-defined buffer
+ *   pointed to by the *msgp parameter.
+ *
+ * Input Parameters:
+ *   msqid  - Message queue identifier
+ *   msgp   - Pointer to a buffer in which the received message will be
+ *            stored
+ *   msgsz  - Length of the data part of the buffer
+ *   msgtyp - Type of message to be received.
+ *   msgflg - Operations flags.
+ *
+ * Returned Value:
+ *   On success, msgrcv() returns the number of bytes actually copied
+ *   into the mtext array.
+ *   On failure, both functions return -1, and set errno to indicate
+ *   the error.
+ *
+ ****************************************************************************/
+
+ssize_t msgrcv(int msqid, FAR void *msgp, size_t msgsz, long msgtyp,
+               int msgflg)
+{
+  FAR struct msgbuf_s *msg = NULL;
+  FAR struct mymsg *buf = msgp;
+  FAR struct msgq_s *msgq;
+  FAR struct tcb_s *btcb;
+  irqstate_t flags;
+  int ret;
+
+  if (msgp == NULL)
+    {
+      ret = -EFAULT;
+      goto errout;
+    }
+
+  flags = enter_critical_section();
+
+  msgq = nxmsg_lookup(msqid);
+  if (msgq == NULL)
+    {
+      ret = -EINVAL;
+      goto errout_with_critical;
+    }
+
+  if (msgsz < msgq->maxmsgsize &&
+      ((msgflg & MSG_NOERROR) == 0))
+    {
+      ret = -EMSGSIZE;
+      goto errout_with_critical;
+    }
+
+  ret = msgrcv_wait(msgq, &msg, msgtyp, msgflg);
+  if (ret < 0)
+    {
+      goto errout_with_critical;
+    }
+
+  msgq->nmsgs--;

Review Comment:
   Done



##########
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;

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1001399634


##########
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)

Review Comment:
   Done



##########
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 ||
+                   ((FAR struct msgbuf_s *)node)->mtype == msgtyp)
+            {
+              newmsg = node;
+              break;
+            }
+        }
+
+      if (newmsg)
+        {
+          list_delete(newmsg);
+          goto found;
+        }
+
+      if ((msgflg & IPC_NOWAIT) != 0)
+        {
+          return -EAGAIN;
+        }
+
+      /* The queue is empty!  Should we block until there the above condition
+       * has been satisfied?
+       */
+
+      rtcb          = this_task();
+      rtcb->waitobj = msgq;
+      msgq->cmn.nwaitnotempty++;
+
+      /* Initialize the 'errcode" used to communication wake-up error
+       * conditions.
+       */
+
+      rtcb->errcode  = OK;

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7088:
URL: https://github.com/apache/incubator-nuttx/pull/7088#discussion_r1000098728


##########
sched/mqueue/msginternal.c:
##########
@@ -0,0 +1,198 @@
+/****************************************************************************
+ * sched/mqueue/msginternal.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 <nuttx/kmalloc.h>
+#include "mqueue/msg.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MQ_PERBLOCK 10
+
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+struct nxmsg_manager_s
+{
+  uint8_t             nmsgq;  /* The number of groups of msgs array */
+  FAR struct msgq_s **msgqs;  /* The pointer of two layer file descriptors array */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct nxmsg_manager_s g_msgmgrs;
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+struct list_node g_msgfreelist = LIST_INITIAL_VALUE(g_msgfreelist);
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxmsg_alloc_internal
+ ****************************************************************************/
+
+static FAR struct msgq_s *nxmsg_alloc_internal(void)
+{
+  FAR struct msgq_s *msgq;
+  FAR struct msgq_s **tmp;
+  int i;
+
+  msgq = kmm_zalloc(sizeof(struct msgq_s));
+  if (msgq == NULL)
+    {
+      return NULL;
+    }
+
+  for (i = 0; i < g_msgmgrs.nmsgq; i++)
+    {
+      if (g_msgmgrs.msgqs[i] == NULL)
+        {
+          g_msgmgrs.msgqs[i] = msgq;
+          msgq->key = i + 1;
+          return msgq;
+        }
+    }
+
+  tmp = kmm_realloc(g_msgmgrs.msgqs, sizeof(FAR void *) *
+                                            (g_msgmgrs.nmsgq + MQ_PERBLOCK));
+  if (tmp == NULL)
+    {
+      kmm_free(msgq);
+      return NULL;
+    }
+
+  g_msgmgrs.msgqs = tmp;
+
+  memset(&g_msgmgrs.msgqs[g_msgmgrs.nmsgq], 0,
+         sizeof(FAR void *) * MQ_PERBLOCK);
+
+  g_msgmgrs.msgqs[g_msgmgrs.nmsgq] = msgq;
+
+  msgq->key = g_msgmgrs.nmsgq + 1;
+
+  g_msgmgrs.nmsgq += MQ_PERBLOCK;
+
+  return msgq;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxmsg_initialize
+ ****************************************************************************/
+
+void nxmsg_initialize(void)
+{
+  FAR struct msgbuf_s *msg;
+
+  msg = (FAR struct msgbuf_s *)kmm_malloc(sizeof(*msg) *
+                                          CONFIG_PREALLOC_MQ_MSGS);
+  if (msg)
+    {
+      int i;
+      for (i = 0; i < CONFIG_PREALLOC_MQ_MSGS; i++)
+        {
+          list_add_tail(&g_msgfreelist, &msg->node);
+          msg++;
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: nxmsg_alloc
+ ****************************************************************************/
+
+int nxmsg_alloc(FAR struct msgq_s **pmsgq)
+{
+  FAR struct msgq_s *msgq;
+
+  msgq = nxmsg_alloc_internal();
+  if (msgq == NULL)
+    {
+      return -ENOMEM;
+    }
+
+  /* Initialize the new named message queue */
+
+  list_initialize(&msgq->msglist);
+
+  msgq->maxmsgs    = MSG_MAX_MSGS;
+  msgq->maxmsgsize = MSG_MAX_BYTES;
+
+  *pmsgq = msgq;
+  return OK;
+}
+
+/****************************************************************************
+ * Name: nxmsg_free
+ ****************************************************************************/
+
+void nxmsg_free(FAR struct msgq_s *msgq)
+{
+  FAR struct msgbuf_s *entry;
+  FAR struct msgbuf_s *tmp;
+  int index;
+
+  if (msgq == NULL || msgq->key <= 0 || msgq->key > g_msgmgrs.nmsgq)
+    {
+      return;
+    }
+
+  index = msgq->key - 1;
+
+  list_for_every_entry_safe(&msgq->msglist, entry,
+                            tmp, struct msgbuf_s, node)
+    {
+      list_delete(&entry->node);
+      list_add_tail(&g_msgfreelist, &entry->node);
+    }
+
+  kmm_free(g_msgmgrs.msgqs[index]);
+  g_msgmgrs.msgqs[index] = NULL;
+}
+
+/****************************************************************************
+ * Name: nxmsg_lookup
+ ****************************************************************************/
+
+FAR struct msgq_s *nxmsg_lookup(key_t key)

Review Comment:
   Done



-- 
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-unsubscribe@nuttx.apache.org

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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #7088: sched/msgq: add support of System V message queue

Posted by GitBox <gi...@apache.org>.
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-unsubscribe@nuttx.apache.org

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