anchao commented on code in PR #16226:
URL: https://github.com/apache/nuttx/pull/16226#discussion_r2049210554


##########
include/nuttx/msgq.h:
##########
@@ -0,0 +1,315 @@
+/****************************************************************************
+ * include/nuttx/msgq.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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_NUTTX_MSGQ_H
+#define ___INCLUDE_NUTTX_MSGQ_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/irq.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/circbuf.h>
+#include <nuttx/spinlock.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: NXMSGQ_INITIALIZER
+ *
+ * Description:
+ *   Statically define and initialize a message queue.
+ *
+ *   The message queue's ring buffer contains space for max_msgs messages,
+ *   each of which is msg_size bytes long.
+ *
+ * Input Parameters:
+ *   buffer   - Ring buffer of Message Queue
+ *   msg_size - Message size (in bytes).
+ *   max_msgs - Maximum number of messages that can be queued.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SMP
+#  define NXMSGQ_INITIALIZER(buffer, msg_size, max_msgs) \
+    { \
+      CIRCBUF_INITIALIZER(buffer, msg_size * max_msgs), \
+      msg_size, \
+      NXSEM_INITIALIZER(0, 0), \
+      NXSEM_INITIALIZER(0, 0), \
+      false, \
+      SP_UNLOCKED, \
+    }
+#else
+#  define NXMSGQ_INITIALIZER(buffer, msg_size, max_msgs) \
+    { \
+      CIRCBUF_INITIALIZER(buffer, msg_size * max_msgs), \
+      msg_size, \
+      NXSEM_INITIALIZER(0, 0), \
+      NXSEM_INITIALIZER(0, 0), \
+      false, \
+    }
+#endif
+
+/****************************************************************************
+ * Public Type Declarations
+ ****************************************************************************/
+
+/* This structure defines a kernel message queue */
+
+typedef struct nxmsgq
+{
+  struct circbuf_s cbuf;
+  int              msg_size;
+  sem_t            txsem;
+  sem_t            rxsem;
+  bool             alloc;
+#ifdef CONFIG_SMP
+  spinlock_t       lock;
+#endif
+} nxmsgq_t;
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Name: nxmsgq_init
+ *
+ * Description:
+ *   Initialize a message queue with static ring buffer
+ *
+ *   This routine initializes a message queue object, prior to its first use.
+ *
+ *   The message queue's ring buffer must contain space for max_msgs
+ *   messages, each of which is msg_size bytes long. Alignment of the
+ *   message queue's ring buffer is not necessary.
+ *
+ * Input Parameters:
+ *   msgq     - Address of the message queue.
+ *   buffer   - Pointer to ring buffer that holds queued messages.
+ *   msg_size - Message size (in bytes).
+ *   max_msgs - Maximum number of messages that can be queued.
+ *
+ * Returned Value:
+ *   None.
+ *
+ ****************************************************************************/
+
+void nxmsgq_init(FAR nxmsgq_t *msgq, FAR void *buffer,
+                 size_t msg_size, uint32_t max_msgs);
+
+/****************************************************************************
+ * Name: nxmsgq_create
+ *
+ * Description:
+ *   Create a message queue.
+ *
+ *   This routine initializes a message queue object, prior to its first use,
+ *   allocating its internal ring buffer from the calling thread's resource
+ *   pool.
+ *
+ *   Memory allocated for the ring buffer can be released by calling
+ *   nxmsgq_destroy()
+ *
+ * Input Parameters:
+ *   msg_size - Message size (in bytes).

Review Comment:
   Yes, this is just aligned with other operating systems
   
   FreeRTOS:
   
https://freertos.org/Documentation/02-Kernel/04-API-references/06-Queues/02-xQueueCreateStatic
   ThreadX:
   
https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/threadx/chapter4.md#tx_queue_create



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

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

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

Reply via email to