Convert mqueue structure for use in VFS as inode data; rename mqueue_inode_s; remove links, reference counts and name from mqueue structure. These will be replaced by VFS data. Remove g_msgqueues and mq_findnamed.c; these will be replace with VFS logic

This commit is contained in:
Gregory Nutt 2014-09-29 13:19:11 -06:00
parent 3973c2676d
commit e3fa34681b
17 changed files with 30 additions and 157 deletions

View File

@ -1,7 +1,7 @@
/****************************************************************************
* include/nuttx/mqueue.h
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2011, 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -64,13 +64,11 @@
struct mq_des; /* forward reference */
struct msgq_s
struct mqueue_inode_s
{
FAR struct msgq_s *flink; /* Forward link to next message queue */
sq_queue_t msglist; /* Prioritized message list */
int16_t maxmsgs; /* Maximum number of messages in the queue */
int16_t nmsgs; /* Number of message in the queue */
int16_t nconnect; /* Number of connections to message queue */
int16_t nwaitnotfull; /* Number tasks waiting for not full */
int16_t nwaitnotempty; /* Number tasks waiting for not empty */
#if CONFIG_MQ_MAXMSGSIZE < 256
@ -78,19 +76,15 @@ struct msgq_s
#else
uint16_t maxmsgsize; /* Max size of message in message queue */
#endif
bool unlinked; /* true if the msg queue has been unlinked */
#ifndef CONFIG_DISABLE_SIGNALS
FAR struct mq_des *ntmqdes; /* Notification: Owning mqdes (NULL if none) */
pid_t ntpid; /* Notification: Receiving Task's PID */
int ntsigno; /* Notification: Signal number */
union sigval ntvalue; /* Notification: Signal value */
#endif
char name[1]; /* Start of the queue name */
};
typedef struct msgq_s msgq_t;
#define SIZEOF_MQ_HEADER ((int)(((msgq_t*)NULL)->name))
#define SIZEOF_MQ_HEADER ((int)(((struct mqueue_inode_s*)NULL)->name))
/* This describes the message queue descriptor that is held in the
* task's TCB
@ -98,9 +92,9 @@ typedef struct msgq_s msgq_t;
struct mq_des
{
FAR struct mq_des *flink; /* Forward link to next message descriptor */
FAR msgq_t *msgq; /* Pointer to associated message queue */
int oflags; /* Flags set when message queue was opened */
FAR struct mq_des *flink; /* Forward link to next message descriptor */
FAR struct mqueue_inode_s *msgq; /* Pointer to associated message queue */
int oflags; /* Flags set when message queue was opened */
};
/****************************************************************************

View File

@ -224,10 +224,6 @@ typedef CODE void (*atexitfunc_t)(void);
typedef CODE void (*onexitfunc_t)(int exitcode, FAR void *arg);
#endif
/* POSIX Message queue */
typedef struct msgq_s msgq_t;
/* struct child_status_s *********************************************************/
/* This structure is used to maintin information about child tasks.
* pthreads work differently, they have join information. This is
@ -523,7 +519,7 @@ struct tcb_s
/* POSIX Named Message Queue Fields *******************************************/
#ifndef CONFIG_DISABLE_MQUEUE
FAR msgq_t *msgwaitq; /* Waiting for this message queue */
FAR struct mqueue_inode_s *msgwaitq; /* Waiting for this message queue */
#endif
/* Library related fields *****************************************************/

View File

@ -37,7 +37,7 @@ ifneq ($(CONFIG_DISABLE_MQUEUE),y)
MQUEUE_SRCS = mq_open.c mq_close.c mq_unlink.c mq_send.c mq_timedsend.c
MQUEUE_SRCS += mq_sndinternal.c mq_receive.c mq_timedreceive.c mq_rcvinternal.c
MQUEUE_SRCS += mq_initialize.c mq_descreate.c mq_findnamed.c mq_msgfree.c
MQUEUE_SRCS += mq_initialize.c mq_descreate.c mq_msgfree.c
MQUEUE_SRCS += mq_msgqfree.c mq_release.c mq_recover.c
ifneq ($(CONFIG_DISABLE_SIGNALS),y)
@ -49,4 +49,5 @@ endif
DEPPATH += --dep-path mqueue
VPATH += :mqueue
endif
endif

View File

@ -115,7 +115,7 @@ int mq_close(mqd_t mqdes)
{
FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head;
FAR struct task_group_s *group = rtcb->group;
FAR msgq_t *msgq;
FAR struct mqueue_inode_s *msgq;
irqstate_t saved_state;
int ret = ERROR;

View File

@ -134,7 +134,8 @@ static mqd_t mq_desalloc(void)
*
****************************************************************************/
mqd_t mq_descreate(FAR struct tcb_s* mtcb, FAR msgq_t* msgq, int oflags)
mqd_t mq_descreate(FAR struct tcb_s* mtcb, FAR struct mqueue_inode_s* msgq,
int oflags)
{
FAR struct task_group_s *group = mtcb->group;
mqd_t mqdes;

View File

@ -1,105 +0,0 @@
/************************************************************************
* sched/mqueue/mq_findnamed.c
*
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************************/
/************************************************************************
* Included Files
************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include "mqueue/mqueue.h"
/************************************************************************
* Definitions
************************************************************************/
/************************************************************************
* Private Type Declarations
************************************************************************/
/************************************************************************
* Global Variables
************************************************************************/
/************************************************************************
* Private Variables
************************************************************************/
/************************************************************************
* Private Functions
************************************************************************/
/************************************************************************
* Public Functions
************************************************************************/
/************************************************************************
* Name: mq_findnamed
*
* Description:
* This function finds the named message queue with the specified name
* in the list of message queues.
*
* Inputs:
* mq_name - the name of the message queue to find
*
* Return Value:
* A reference to the matching named message queue structure (or NULL
* if none was found).
*
************************************************************************/
FAR msgq_t *mq_findnamed(const char *mq_name)
{
FAR msgq_t *msgq;
/* Search the list of named message queues */
for (msgq = (FAR msgq_t*)g_msgqueues.head; (msgq); msgq = msgq->flink)
{
/* Break out of the lloop with a non-NULL msgq if the
* name matches.
*/
if (!strcmp(mq_name, msgq->name))
{
break;
}
}
return msgq;
}

View File

@ -65,10 +65,6 @@ struct mq_des_block_s
* Global Variables
************************************************************************/
/* This is a list of all opened message queues */
sq_queue_t g_msgqueues;
/* The g_msgfree is a list of messages that are available for general
* use. The number of messages in this list is a system configuration
* item.
@ -171,10 +167,6 @@ static mqmsg_t *mq_msgblockalloc(sq_queue_t *queue, uint16_t nmsgs,
void mq_initialize(void)
{
/* Initialize the list of message queues */
sq_init(&g_msgqueues);
/* Initialize the message free lists */
sq_init(&g_msgfree);

View File

@ -85,7 +85,7 @@
*
************************************************************************/
void mq_msgqfree(FAR msgq_t *msgq)
void mq_msgqfree(FAR struct mqueue_inode_s *msgq)
{
FAR mqmsg_t *curr;
FAR mqmsg_t *next;

View File

@ -127,7 +127,7 @@
int mq_notify(mqd_t mqdes, const struct sigevent *notification)
{
struct tcb_s *rtcb;
msgq_t *msgq;
struct mqueue_inode_s *msgq;
int errval;
/* Was a valid message queue descriptor provided? */

View File

@ -110,7 +110,7 @@
mqd_t mq_open(const char *mq_name, int oflags, ...)
{
FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head;
FAR msgq_t *msgq;
FAR struct mqueue_inode_s *msgq;
mqd_t mqdes = NULL;
va_list arg; /* Points to each un-named argument */
struct mq_attr *attr; /* MQ creation attributes */
@ -152,11 +152,11 @@ mqd_t mq_open(const char *mq_name, int oflags, ...)
else if ((oflags & O_CREAT) != 0)
{
/* Allocate memory for the new message queue. The size to
* allocate is the size of the msgq_t header plus the size
* of the message queue name+1.
* allocate is the size of the struct mqueue_inode_s header
* plus the size of the message queue name+1.
*/
msgq = (FAR msgq_t*)kmm_zalloc(SIZEOF_MQ_HEADER + namelen + 1);
msgq = (FAR struct mqueue_inode_s*)kmm_zalloc(SIZEOF_MQ_HEADER + namelen + 1);
if (msgq)
{
/* Create a message queue descriptor for the TCB */

View File

@ -157,7 +157,7 @@ int mq_verifyreceive(mqd_t mqdes, void *msg, size_t msglen)
FAR mqmsg_t *mq_waitreceive(mqd_t mqdes)
{
FAR struct tcb_s *rtcb;
FAR msgq_t *msgq;
FAR struct mqueue_inode_s *msgq;
FAR mqmsg_t *rcvmsg;
/* Get a pointer to the message queue */
@ -249,7 +249,7 @@ ssize_t mq_doreceive(mqd_t mqdes, mqmsg_t *mqmsg, void *ubuffer, int *prio)
{
FAR struct tcb_s *btcb;
irqstate_t saved_state;
FAR msgq_t *msgq;
FAR struct mqueue_inode_s *msgq;
ssize_t rcvmsglen;
/* Get the length of the message (also the return value) */

View File

@ -117,7 +117,7 @@
int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
{
FAR msgq_t *msgq;
FAR struct mqueue_inode_s *msgq;
FAR mqmsg_t *mqmsg = NULL;
irqstate_t saved_state;
int ret = ERROR;

View File

@ -240,7 +240,7 @@ FAR mqmsg_t *mq_msgalloc(void)
int mq_waitsend(mqd_t mqdes)
{
FAR struct tcb_s *rtcb;
FAR msgq_t *msgq;
FAR struct mqueue_inode_s *msgq;
/* Get a pointer to the message queue */
@ -327,7 +327,7 @@ int mq_waitsend(mqd_t mqdes)
int mq_dosend(mqd_t mqdes, FAR mqmsg_t *mqmsg, const void *msg, size_t msglen, int prio)
{
FAR struct tcb_s *btcb;
FAR msgq_t *msgq;
FAR struct mqueue_inode_s *msgq;
FAR mqmsg_t *next;
FAR mqmsg_t *prev;
irqstate_t saved_state;

View File

@ -184,7 +184,7 @@ int mq_timedsend(mqd_t mqdes, const char *msg, size_t msglen, int prio,
const struct timespec *abstime)
{
FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head;
FAR msgq_t *msgq;
FAR struct mqueue_inode_s *msgq;
FAR mqmsg_t *mqmsg = NULL;
irqstate_t saved_state;
int ret = ERROR;

View File

@ -90,9 +90,9 @@
int mq_unlink(const char *mq_name)
{
FAR msgq_t *msgq;
irqstate_t saved_state;
int ret = ERROR;
FAR struct mqueue_inode_s *msgq;
irqstate_t saved_state;
int ret = ERROR;
/* Verify the input values */

View File

@ -92,7 +92,7 @@
void mq_waitirq(FAR struct tcb_s *wtcb, int errcode)
{
FAR msgq_t *msgq;
FAR struct mqueue_inode_s *msgq;
irqstate_t saved_state;
/* Disable interrupts. This is necessary because an interrupt handler may

View File

@ -56,7 +56,7 @@
#if CONFIG_MQ_MAXMSGSIZE > 0
/****************************************************************************
* Definitions
* Pre-processor Definitions
****************************************************************************/
#define MQ_MAX_BYTES CONFIG_MQ_MAXMSGSIZE
@ -86,8 +86,6 @@ enum mqalloc_e
MQ_ALLOC_IRQ /* Preallocated, reserved for interrupt handling */
};
typedef enum mqalloc_e mqalloc_t;
/* This structure describes one buffered POSIX message. */
struct mqmsg
@ -117,10 +115,6 @@ extern "C"
#define EXTERN extern
#endif
/* This is a list of all opened message queues */
EXTERN sq_queue_t g_msgqueues;
/* The g_msgfree is a list of messages that are available for general use.
* The number of messages in this list is a system configuration item.
*/