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-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org