Move mq_open.c, mq_close.c, and mq_unlink.c from sched/mqueue to fs/mqueue

This commit is contained in:
Gregory Nutt
2014-09-29 13:35:32 -06:00
parent e3fa34681b
commit b0f80cc8db
16 changed files with 59 additions and 48 deletions
+4 -4
View File
@@ -35,10 +35,10 @@
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_msgfree.c
MQUEUE_SRCS += mq_msgqfree.c mq_release.c mq_recover.c
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
ifneq ($(CONFIG_DISABLE_SIGNALS),y)
MQUEUE_SRCS += mq_waitirq.c mq_notify.c
-191
View File
@@ -1,191 +0,0 @@
/****************************************************************************
* sched/mqueue/mq_close.c
*
* Copyright (C) 2007, 2009, 2013 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 <mqueue.h>
#include <sched.h>
#include <assert.h>
#include "sched/sched.h"
#include "mqueue/mqueue.h"
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Private Type Declarations
****************************************************************************/
/****************************************************************************
* Global Variables
****************************************************************************/
/****************************************************************************
* Private Variables
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: mq_desfree
*
* Description:
* Deallocate a message queue descriptor but returning it to the free list
*
* Inputs:
* mqdes - message queue descriptor to free
*
****************************************************************************/
#define mq_desfree(mqdes) sq_addlast((FAR sq_entry_t*)mqdes, &g_desfree)
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mq_close
*
* Description:
* This function is used to indicate that the calling task is finished
* with the specified message queued mqdes. The mq_close() deallocates
* any system resources allocated by the system for use by this task for
* its message queue.
*
* If the calling task has attached a notification to the message queue
* via this mqdes, this attachment will be removed and the message queue
* is available for another process to attach a notification.
*
* Parameters:
* mqdes - Message queue descriptor.
*
* Return Value:
* 0 (OK) if the message queue is closed successfully,
* otherwise, -1 (ERROR).
*
* Assumptions:
* - The behavior of a task that is blocked on either a mq_send() or
* mq_receive() is undefined when mq_close() is called.
* - The results of using this message queue descriptor after a successful
* return from mq_close() is undefined.
*
****************************************************************************/
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 struct mqueue_inode_s *msgq;
irqstate_t saved_state;
int ret = ERROR;
DEBUGASSERT(group);
/* Verify the inputs */
if (mqdes)
{
sched_lock();
/* Remove the message descriptor from the current task's
* list of message descriptors.
*/
sq_rem((FAR sq_entry_t*)mqdes, &group->tg_msgdesq);
/* Find the message queue associated with the message descriptor */
msgq = mqdes->msgq;
/* Check if the calling task has a notification attached to
* the message queue via this mqdes.
*/
#ifndef CONFIG_DISABLE_SIGNALS
if (msgq->ntmqdes == mqdes)
{
msgq->ntpid = INVALID_PROCESS_ID;
msgq->ntsigno = 0;
msgq->ntvalue.sival_int = 0;
msgq->ntmqdes = NULL;
}
#endif
/* Decrement the connection count on the message queue. */
if (msgq->nconnect)
{
msgq->nconnect--;
}
/* If it is no longer connected to any message descriptor and if the
* message queue has already been unlinked, then we can discard the
* message queue.
*/
if (!msgq->nconnect && msgq->unlinked)
{
/* Remove the message queue from the list of all
* message queues
*/
saved_state = irqsave();
(void)sq_rem((FAR sq_entry_t*)msgq, &g_msgqueues);
irqrestore(saved_state);
/* Then deallocate it (and any messages left in it) */
mq_msgqfree(msgq);
}
/* Deallocate the message descriptor */
mq_desfree(mqdes);
sched_unlock();
ret = OK;
}
return ret;
}
+11 -8
View File
@@ -93,17 +93,17 @@ sq_queue_t g_desfree;
* messages.
*/
static mqmsg_t *g_msgalloc;
static struct mqueue_msg_s *g_msgalloc;
/* g_msgfreeirqalloc is a pointer to the start of the allocated block of
* messages.
*/
static mqmsg_t *g_msgfreeirqalloc;
static struct mqueue_msg_s *g_msgfreeirqalloc;
/* g_desalloc is a list of allocated block of message queue descriptors. */
static sq_queue_t g_desalloc;
static sq_queue_t g_desalloc;
/************************************************************************
* Private Functions
@@ -120,19 +120,22 @@ static sq_queue_t g_desalloc;
*
************************************************************************/
static mqmsg_t *mq_msgblockalloc(sq_queue_t *queue, uint16_t nmsgs,
uint8_t alloc_type)
static struct mqueue_msg_s *
mq_msgblockalloc(FAR sq_queue_t *queue, uint16_t nmsgs,
uint8_t alloc_type)
{
mqmsg_t *mqmsgblock;
struct mqueue_msg_s *mqmsgblock;
/* The g_msgfree must be loaded at initialization time to hold the
* configured number of messages.
*/
mqmsgblock = (mqmsg_t*)kmm_malloc(sizeof(mqmsg_t) * nmsgs);
mqmsgblock = (FAR struct mqueue_msg_s*)
kmm_malloc(sizeof(struct mqueue_msg_s) * nmsgs);
if (mqmsgblock)
{
mqmsg_t *mqmsg = mqmsgblock;
struct mqueue_msg_s *mqmsg = mqmsgblock;
int i;
for (i = 0; i < nmsgs; i++)
+1 -1
View File
@@ -86,7 +86,7 @@
*
************************************************************************/
void mq_msgfree(FAR mqmsg_t *mqmsg)
void mq_msgfree(FAR struct mqueue_msg_s *mqmsg)
{
irqstate_t saved_state;
+3 -3
View File
@@ -87,12 +87,12 @@
void mq_msgqfree(FAR struct mqueue_inode_s *msgq)
{
FAR mqmsg_t *curr;
FAR mqmsg_t *next;
FAR struct mqueue_msg_s *curr;
FAR struct mqueue_msg_s *next;
/* Deallocate any stranded messages in the message queue. */
curr = (FAR mqmsg_t*)msgq->msglist.head;
curr = (FAR struct mqueue_msg_s*)msgq->msglist.head;
while (curr)
{
/* Deallocate the message structure. */
-235
View File
@@ -1,235 +0,0 @@
/****************************************************************************
* sched/mqueue/mq_open.c
*
* Copyright (C) 2007-2009, 2011 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 <sys/types.h>
#include <stdint.h>
#include <stdarg.h>
#include <mqueue.h>
#include <fcntl.h>
#include <string.h>
#include <sched.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/kmalloc.h>
#include "sched/sched.h"
#include "mqueue/mqueue.h"
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Private Type Declarations
****************************************************************************/
/****************************************************************************
* Global Variables
****************************************************************************/
/****************************************************************************
* Private Variables
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mq_open
*
* Description:
* This function establish a connection between a named message queue and
* the calling task. After a successful call of mq_open(), the task can
* reference the message queue using the address returned by the call. The
* message queue remains usable until it is closed by a successful call to
* mq_close().
*
* Parameters:
* mq_name - Name of the queue to open
* oflags - open flags
* Optional parameters. When the O_CREAT flag is specified, two optional
* parameters are expected:
*
* 1. mode_t mode (ignored), and
* 2. struct mq_attr *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:
* A message queue descriptor or -1 (ERROR)
*
* Assumptions:
*
****************************************************************************/
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 */
/* Make sure that a non-NULL name is supplied */
if (mq_name)
{
sched_lock();
namelen = strlen(mq_name);
if (namelen > 0)
{
/* See if the message queue already exists */
msgq = mq_findnamed(mq_name);
if (msgq)
{
/* It does. Check if the caller wanted to create a new
* message queue with this name (i.e., O_CREAT|O_EXCL)
*/
if ((oflags & O_CREAT) == 0 || (oflags & O_EXCL) == 0)
{
/* Create a message queue descriptor for the TCB */
mqdes = mq_descreate(rtcb, msgq, oflags);
if (mqdes)
{
/* Allow a new connection to the message queue */
msgq->nconnect++;
}
}
}
/* It doesn't exist. Should we create one? */
else if ((oflags & O_CREAT) != 0)
{
/* 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);
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);
}
}
}
}
sched_unlock();
}
if (mqdes == NULL)
{
return (mqd_t)ERROR;
}
else
{
return mqdes;
}
}
+5 -4
View File
@@ -154,11 +154,11 @@ int mq_verifyreceive(mqd_t mqdes, void *msg, size_t msglen)
*
****************************************************************************/
FAR mqmsg_t *mq_waitreceive(mqd_t mqdes)
FAR struct mqueue_msg_s *mq_waitreceive(mqd_t mqdes)
{
FAR struct tcb_s *rtcb;
FAR struct mqueue_inode_s *msgq;
FAR mqmsg_t *rcvmsg;
FAR struct mqueue_msg_s *rcvmsg;
/* Get a pointer to the message queue */
@@ -166,7 +166,7 @@ FAR mqmsg_t *mq_waitreceive(mqd_t mqdes)
/* Get the message from the head of the queue */
while ((rcvmsg = (FAR mqmsg_t*)sq_remfirst(&msgq->msglist)) == NULL)
while ((rcvmsg = (FAR struct mqueue_msg_s*)sq_remfirst(&msgq->msglist)) == NULL)
{
/* The queue is empty! Should we block until there the above condition
* has been satisfied?
@@ -245,7 +245,8 @@ FAR mqmsg_t *mq_waitreceive(mqd_t mqdes)
*
****************************************************************************/
ssize_t mq_doreceive(mqd_t mqdes, mqmsg_t *mqmsg, void *ubuffer, int *prio)
ssize_t mq_doreceive(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg,
FAR void *ubuffer, int *prio)
{
FAR struct tcb_s *btcb;
irqstate_t saved_state;
+3 -3
View File
@@ -114,9 +114,9 @@
ssize_t mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio)
{
FAR mqmsg_t *mqmsg;
irqstate_t saved_state;
ssize_t ret = ERROR;
FAR struct mqueue_msg_s *mqmsg;
irqstate_t saved_state;
ssize_t ret = ERROR;
DEBUGASSERT(up_interrupt_context() == false);
+3 -3
View File
@@ -118,9 +118,9 @@
int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
{
FAR struct mqueue_inode_s *msgq;
FAR mqmsg_t *mqmsg = NULL;
irqstate_t saved_state;
int ret = ERROR;
FAR struct mqueue_msg_s *mqmsg = NULL;
irqstate_t saved_state;
int ret = ERROR;
/* Verify the input parameters -- setting errno appropriately
* on any failures to verify.
+12 -11
View File
@@ -160,10 +160,10 @@ int mq_verifysend(mqd_t mqdes, const void *msg, size_t msglen, int prio)
*
****************************************************************************/
FAR mqmsg_t *mq_msgalloc(void)
FAR struct mqueue_msg_s *mq_msgalloc(void)
{
FAR mqmsg_t *mqmsg;
irqstate_t saved_state;
FAR struct mqueue_msg_s *mqmsg;
irqstate_t saved_state;
/* If we were called from an interrupt handler, then try to get the message
* from generally available list of messages. If this fails, then try the
@@ -174,12 +174,12 @@ FAR mqmsg_t *mq_msgalloc(void)
{
/* Try the general free list */
mqmsg = (FAR mqmsg_t*)sq_remfirst(&g_msgfree);
mqmsg = (FAR struct mqueue_msg_s*)sq_remfirst(&g_msgfree);
if (!mqmsg)
{
/* Try the free list reserved for interrupt handlers */
mqmsg = (FAR mqmsg_t*)sq_remfirst(&g_msgfreeirq);
mqmsg = (FAR struct mqueue_msg_s*)sq_remfirst(&g_msgfreeirq);
}
}
@@ -192,14 +192,14 @@ FAR mqmsg_t *mq_msgalloc(void)
*/
saved_state = irqsave();
mqmsg = (FAR mqmsg_t*)sq_remfirst(&g_msgfree);
mqmsg = (FAR struct mqueue_msg_s*)sq_remfirst(&g_msgfree);
irqrestore(saved_state);
/* If we cannot a message from the free list, then we will have to allocate one. */
if (!mqmsg)
{
mqmsg = (FAR mqmsg_t *)kmm_malloc((sizeof (mqmsg_t)));
mqmsg = (FAR struct mqueue_msg_s *)kmm_malloc((sizeof (struct mqueue_msg_s)));
/* Check if we got an allocated message */
@@ -324,12 +324,13 @@ int mq_waitsend(mqd_t mqdes)
*
****************************************************************************/
int mq_dosend(mqd_t mqdes, FAR mqmsg_t *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)
{
FAR struct tcb_s *btcb;
FAR struct mqueue_inode_s *msgq;
FAR mqmsg_t *next;
FAR mqmsg_t *prev;
FAR struct mqueue_msg_s *next;
FAR struct mqueue_msg_s *prev;
irqstate_t saved_state;
/* Get a pointer to the message queue */
@@ -354,7 +355,7 @@ int mq_dosend(mqd_t mqdes, FAR mqmsg_t *mqmsg, const void *msg, size_t msglen, i
* message. Each is list is maintained in ascending priority order.
*/
for (prev = NULL, next = (FAR mqmsg_t*)msgq->msglist.head;
for (prev = NULL, next = (FAR struct mqueue_msg_s*)msgq->msglist.head;
next && prio <= next->priority;
prev = next, next = next->next);
+1 -1
View File
@@ -183,7 +183,7 @@ ssize_t mq_timedreceive(mqd_t mqdes, void *msg, size_t msglen,
int *prio, const struct timespec *abstime)
{
FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head;
FAR mqmsg_t *mqmsg;
FAR struct mqueue_msg_s *mqmsg;
irqstate_t saved_state;
int ret = ERROR;
+1 -1
View File
@@ -185,7 +185,7 @@ int mq_timedsend(mqd_t mqdes, const char *msg, size_t msglen, int prio,
{
FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head;
FAR struct mqueue_inode_s *msgq;
FAR mqmsg_t *mqmsg = NULL;
FAR struct mqueue_msg_s *mqmsg = NULL;
irqstate_t saved_state;
int ret = ERROR;
-145
View File
@@ -1,145 +0,0 @@
/************************************************************************
* sched/mqueue/mq_unlink.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 <stdbool.h>
#include <mqueue.h>
#include <sched.h>
#include "mqueue/mqueue.h"
/************************************************************************
* Pre-processor Definitions
************************************************************************/
/************************************************************************
* Private Type Declarations
************************************************************************/
/************************************************************************
* Global Variables
************************************************************************/
/************************************************************************
* Private Variables
************************************************************************/
/************************************************************************
* Private Functions
************************************************************************/
/************************************************************************
* Public Functions
************************************************************************/
/************************************************************************
* Name: mq_unlink
*
* Description:
* This function removes the message queue named by "mq_name." If one
* or more tasks have the message queue open when mq_unlink() is called,
* removal of the message queue is postponed until all references to the
* message queue have been closed.
*
* Parameters:
* mq_name - Name of the message queue
*
* Return Value:
* None
*
* Assumptions:
*
************************************************************************/
int mq_unlink(const char *mq_name)
{
FAR struct mqueue_inode_s *msgq;
irqstate_t saved_state;
int ret = ERROR;
/* Verify the input values */
if (mq_name)
{
sched_lock();
/* Find the named message queue */
msgq = mq_findnamed(mq_name);
if (msgq)
{
/* If it is no longer connected, then we can just
* discard the message queue now.
*/
if (!msgq->nconnect)
{
/* Remove the message queue from the list of all
* message queues
*/
saved_state = irqsave();
(void)sq_rem((FAR sq_entry_t*)msgq, &g_msgqueues);
irqrestore(saved_state);
/* Then deallocate it (and any messages left in it) */
mq_msgqfree(msgq);
}
/* If the message queue is still connected to a message descriptor,
* then mark it for deletion when the last message descriptor is
* closed
*/
else
{
msgq->unlinked = true;
}
ret = OK;
}
sched_unlock();
}
return ret;
}
+7 -8
View File
@@ -88,7 +88,7 @@ enum mqalloc_e
/* This structure describes one buffered POSIX message. */
struct mqmsg
struct mqueue_msg_s
{
FAR struct mqmsg *next; /* Forward link to next message */
uint8_t type; /* (Used to manage allocations) */
@@ -101,8 +101,6 @@ struct mqmsg
uint8_t mail[MQ_MAX_BYTES]; /* Message data */
};
typedef struct mqmsg mqmsg_t;
/****************************************************************************
* Global Variables
****************************************************************************/
@@ -145,7 +143,7 @@ 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);
void mq_msgfree(FAR mqmsg_t *mqmsg);
void mq_msgfree(FAR struct mqueue_msg_s *mqmsg);
void mq_msgqfree(FAR msgq_t *msgq);
/* mq_waitirq.c ************************************************************/
@@ -155,15 +153,16 @@ void mq_waitirq(FAR struct tcb_s *wtcb, int errcode);
/* mq_rcvinternal.c ********************************************************/
int mq_verifyreceive(mqd_t mqdes, void *msg, size_t msglen);
FAR mqmsg_t *mq_waitreceive(mqd_t mqdes);
ssize_t mq_doreceive(mqd_t mqdes, mqmsg_t *mqmsg, void *ubuffer, int *prio);
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);
/* mq_sndinternal.c ********************************************************/
int mq_verifysend(mqd_t mqdes, const void *msg, size_t msglen, int prio);
FAR mqmsg_t *mq_msgalloc(void);
FAR struct mqueue_msg_s *mq_msgalloc(void);
int mq_waitsend(mqd_t mqdes);
int mq_dosend(mqd_t mqdes, FAR mqmsg_t *mqmsg, const void *msg,
int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, const void *msg,
size_t msglen, int prio);
/* mq_release.c ************************************************************/