diff --git a/fs/mqueue/mq_close.c b/fs/mqueue/mq_close.c index 0a26cc8d3ba..e4a4812fe6c 100644 --- a/fs/mqueue/mq_close.c +++ b/fs/mqueue/mq_close.c @@ -47,7 +47,7 @@ #include "mqueue/mqueue.h" /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Variables ****************************************************************************/ /**************************************************************************** diff --git a/fs/mqueue/mq_open.c b/fs/mqueue/mq_open.c index b70582c2506..e0d47aa4657 100644 --- a/fs/mqueue/mq_open.c +++ b/fs/mqueue/mq_open.c @@ -55,7 +55,7 @@ #include "mqueue/mqueue.h" /**************************************************************************** - * Definitions + * Pre-procesor Definitions ****************************************************************************/ /**************************************************************************** @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Global Variables + * Public Variables ****************************************************************************/ /**************************************************************************** @@ -112,9 +112,10 @@ mqd_t mq_open(const char *mq_name, int oflags, ...) FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; 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 */ - int namelen; /* Length of MQ name */ + va_list arg; + struct mq_attr *attr; + mode_t mode; + int namelen; /* Make sure that a non-NULL name is supplied */ @@ -151,73 +152,28 @@ mqd_t mq_open(const char *mq_name, int oflags, ...) else if ((oflags & O_CREAT) != 0) { + /* Yes.. Get the optional arguments needed to create a message + * queue. + */ + + va_start(arg, oflags); + mode = va_arg(arg, mode_t); + attr = va_arg(arg, struct mq_attr*); + /* Allocate memory for the new message queue. The size to * allocate is the size of the struct mqueue_inode_s header * plus the size of the message queue name+1. */ - msgq = (FAR struct mqueue_inode_s*)kmm_zalloc(SIZEOF_MQ_HEADER + namelen + 1); + msgq = (FAR struct mqueue_inode_s*)mq_msgqalloc(oflags, mode, attr); if (msgq) { - /* Create a message queue descriptor for the TCB */ - - mqdes = mq_descreate(rtcb, msgq, oflags); - if (mqdes) - { - /* Set up to get the optional arguments needed to create - * a message queue. - */ - - va_start(arg, oflags); - (void)va_arg(arg, mode_t); /* MQ creation mode parameter (ignored) */ - attr = va_arg(arg, struct mq_attr*); - - /* Initialize the new named message queue */ - - sq_init(&msgq->msglist); - if (attr) - { - msgq->maxmsgs = (int16_t)attr->mq_maxmsg; - if (attr->mq_msgsize <= MQ_MAX_BYTES) - { - msgq->maxmsgsize = (int16_t)attr->mq_msgsize; - } - else - { - msgq->maxmsgsize = MQ_MAX_BYTES; - } - } - else - { - msgq->maxmsgs = MQ_MAX_MSGS; - msgq->maxmsgsize = MQ_MAX_BYTES; - } - - msgq->nconnect = 1; -#ifndef CONFIG_DISABLE_SIGNALS - msgq->ntpid = INVALID_PROCESS_ID; -#endif - strcpy(msgq->name, mq_name); - - /* Add the new message queue to the list of - * message queues - */ - - sq_addlast((FAR sq_entry_t*)msgq, &g_msgqueues); - - /* Clean-up variable argument stuff */ - - va_end(arg); - } - else - { - /* Deallocate the msgq structure. Since it is - * uninitialized, mq_deallocate() is not used. - */ - - sched_kfree(msgq); - } +#warning Missing logic } + + /* Clean-up variable argument stuff */ + + va_end(arg); } } diff --git a/fs/mqueue/mq_unlink.c b/fs/mqueue/mq_unlink.c index 5b33a4314a4..3ee6840f70b 100644 --- a/fs/mqueue/mq_unlink.c +++ b/fs/mqueue/mq_unlink.c @@ -54,7 +54,7 @@ ************************************************************************/ /************************************************************************ - * Global Variables + * Public Variables ************************************************************************/ /************************************************************************ diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index 44931aa6033..cf67bc4c554 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -52,6 +52,10 @@ # include #endif +#ifndef CONFIG_DISABLE_MQUEUE +# include +#endif + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -218,14 +222,18 @@ struct mountpt_operations union inode_ops_u { - FAR const struct file_operations *i_ops; /* Driver operations for inode */ + FAR const struct file_operations *i_ops; /* Driver operations for inode */ #ifndef CONFIG_DISABLE_MOUNTPOUNT - FAR const struct block_operations *i_bops; /* Block driver operations */ - FAR const struct mountpt_operations *i_mops; /* Operations on a mountpoint */ + FAR const struct block_operations *i_bops; /* Block driver operations */ + FAR const struct mountpt_operations *i_mops; /* Operations on a mountpoint */ #endif #ifdef CONFIG_FS_NAMED_SEMAPHORES - FAR struct nsem_inode_s *i_nsem; /* Named semaphore */ + FAR struct nsem_inode_s *i_nsem; /* Named semaphore */ #endif +#ifndef CONFIG_DISABLE_MQUEUE + FAR struct mqueue_inode_s *i_mqueue; /* POSIX message queue */ +#endif + }; /* This structure represents one inode in the Nuttx pseudo-file system */ diff --git a/include/nuttx/mqueue.h b/include/nuttx/mqueue.h index 7aa60ed52b0..e3c3de32c22 100644 --- a/include/nuttx/mqueue.h +++ b/include/nuttx/mqueue.h @@ -84,8 +84,6 @@ struct mqueue_inode_s #endif }; -#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 */ @@ -107,11 +105,55 @@ struct mq_des #ifdef __cplusplus #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif +/************************************************************************ + * Name: mq_msgqfree + * + * Description: + * This function deallocates an initialized message queue structure. + * First, it deallocates all of the queued messages in the message + * queue. It is assumed that this message is fully unlinked and + * closed so that no thread will attempt access it while it is being + * deleted. + * + * Inputs: + * msgq - Named essage queue to be freed + * + * Return Value: + * None + * + ************************************************************************/ + +void mq_msgqfree(FAR struct mqueue_inode_s *msgq); + +/**************************************************************************** + * Name: mq_msgqalloc + * + * Description: + * This function implements a part of the POSIX message queue open logic. + * It allocates and initializes a structu mqueue_inode_s structure. + * + * Parameters: + * oflags - open flags + * mode - mode_t value is ignored + * attr - The mq_maxmsg attribute is used at the time that the message + * queue is created to determine the maximum number of + * messages that may be placed in the message queue. + * + * Return Value: + * The allocated and initalized message queue structure or NULL in the + * event of a failure. + * + ****************************************************************************/ + +FAR struct mqueue_inode_s *mq_msgqalloc(int oflags, mode_t mode, + FAR struct mq_attr *attr); + #undef EXTERN #ifdef __cplusplus } diff --git a/sched/mqueue/Make.defs b/sched/mqueue/Make.defs index eacd605aaef..c4aec37fdb9 100644 --- a/sched/mqueue/Make.defs +++ b/sched/mqueue/Make.defs @@ -37,8 +37,8 @@ ifneq ($(CONFIG_DISABLE_MQUEUE),y) MQUEUE_SRCS = mq_send.c mq_timedsend.c mq_sndinternal.c mq_receive.c MQUEUE_SRCS += mq_timedreceive.c mq_rcvinternal.c mq_initialize.c -MQUEUE_SRCS += mq_descreate.c mq_msgfree.c mq_msgqfree.c mq_release.c -MQUEUE_SRCS += mq_recover.c +MQUEUE_SRCS += mq_descreate.c mq_msgfree.c mq_msgqalloc.c mq_msgqfree.c +MQUEUE_SRCS += mq_release.c mq_recover.c ifneq ($(CONFIG_DISABLE_SIGNALS),y) MQUEUE_SRCS += mq_waitirq.c mq_notify.c diff --git a/sched/mqueue/mq_msgqfree.c b/sched/mqueue/mq_msgqfree.c index e3a50d720a3..4a02e201c56 100644 --- a/sched/mqueue/mq_msgqfree.c +++ b/sched/mqueue/mq_msgqfree.c @@ -71,11 +71,11 @@ * Name: mq_msgqfree * * Description: - * This function deallocates an initialized message queue - * structure. First, it deallocates all of the queued - * messages in the message Q. It is assumed that this - * message is fully unlinked and closed so that not thread - * will attempt access it while it is being deleted. + * This function deallocates an initialized message queue structure. + * First, it deallocates all of the queued messages in the message + * queue. It is assumed that this message is fully unlinked and + * closed so that no thread will attempt access it while it is being + * deleted. * * Inputs: * msgq - Named essage queue to be freed diff --git a/sched/mqueue/mq_sndinternal.c b/sched/mqueue/mq_sndinternal.c index 7c15ba8f252..2339d7a7fe8 100644 --- a/sched/mqueue/mq_sndinternal.c +++ b/sched/mqueue/mq_sndinternal.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/mqueue/mq_send.c * - * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2013-2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/sched/mqueue/mqueue.h b/sched/mqueue/mqueue.h index 64c4ddca4b0..4b382b8b0e8 100644 --- a/sched/mqueue/mqueue.h +++ b/sched/mqueue/mqueue.h @@ -90,15 +90,15 @@ enum mqalloc_e struct mqueue_msg_s { - FAR struct mqmsg *next; /* Forward link to next message */ - uint8_t type; /* (Used to manage allocations) */ - uint8_t priority; /* priority of message */ + FAR struct mqueue_msg_s *next; /* Forward link to next message */ + uint8_t type; /* (Used to manage allocations) */ + uint8_t priority; /* priority of message */ #if MQ_MAX_BYTES < 256 - uint8_t msglen; /* Message data length */ + uint8_t msglen; /* Message data length */ #else - uint16_t msglen; /* Message data length */ + uint16_t msglen; /* Message data length */ #endif - uint8_t mail[MQ_MAX_BYTES]; /* Message data */ + uint8_t mail[MQ_MAX_BYTES]; /* Message data */ }; /**************************************************************************** @@ -141,10 +141,10 @@ EXTERN sq_queue_t g_desfree; void weak_function mq_initialize(void); void mq_desblockalloc(void); -mqd_t mq_descreate(FAR struct tcb_s* mtcb, FAR msgq_t* msgq, int oflags); -FAR msgq_t *mq_findnamed(const char *mq_name); +mqd_t mq_descreate(FAR struct tcb_s* mtcb, FAR struct mqueue_inode_s* msgq, + int oflags); +FAR struct mqueue_inode_s *mq_findnamed(FAR const char *mq_name); void mq_msgfree(FAR struct mqueue_msg_s *mqmsg); -void mq_msgqfree(FAR msgq_t *msgq); /* mq_waitirq.c ************************************************************/ @@ -154,16 +154,16 @@ void mq_waitirq(FAR struct tcb_s *wtcb, int errcode); int mq_verifyreceive(mqd_t mqdes, void *msg, size_t msglen); FAR struct mqueue_msg_s *mq_waitreceive(mqd_t mqdes); -ssize_t mq_doreceive(mqd_t mqdes, struct mqueue_msg_s *mqmsg, void *ubuffer, - int *prio); +ssize_t mq_doreceive(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, + FAR void *ubuffer, FAR int *prio); /* mq_sndinternal.c ********************************************************/ -int mq_verifysend(mqd_t mqdes, const void *msg, size_t msglen, int prio); +int mq_verifysend(mqd_t mqdes, FAR const void *msg, size_t msglen, int prio); FAR struct mqueue_msg_s *mq_msgalloc(void); int mq_waitsend(mqd_t mqdes); -int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, const void *msg, - size_t msglen, int prio); +int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, + FAR const void *msg, size_t msglen, int prio); /* mq_release.c ************************************************************/