mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
Complete re-implementation of mq_close
This commit is contained in:
+32
-37
@@ -39,11 +39,15 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <mqueue.h>
|
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
|
#include <mqueue.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "sched/sched.h"
|
#include <nuttx/kmalloc.h>
|
||||||
|
#include <nuttx/sched.h>
|
||||||
|
#include <nuttx/mqueue.h>
|
||||||
|
|
||||||
|
#include "inode/inode.h"
|
||||||
#include "mqueue/mqueue.h"
|
#include "mqueue/mqueue.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -66,19 +70,6 @@
|
|||||||
* Private Functions
|
* 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
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -113,11 +104,10 @@
|
|||||||
|
|
||||||
int mq_close(mqd_t mqdes)
|
int mq_close(mqd_t mqdes)
|
||||||
{
|
{
|
||||||
FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head;
|
FAR struct tcb_s *rtcb = sched_self();
|
||||||
FAR struct task_group_s *group = rtcb->group;
|
FAR struct task_group_s *group = rtcb->group;
|
||||||
FAR struct mqueue_inode_s *msgq;
|
FAR struct mqueue_inode_s *msgq;
|
||||||
irqstate_t saved_state;
|
struct inode *inode ;
|
||||||
int ret = ERROR;
|
|
||||||
|
|
||||||
DEBUGASSERT(group);
|
DEBUGASSERT(group);
|
||||||
|
|
||||||
@@ -136,6 +126,12 @@ int mq_close(mqd_t mqdes)
|
|||||||
/* Find the message queue associated with the message descriptor */
|
/* Find the message queue associated with the message descriptor */
|
||||||
|
|
||||||
msgq = mqdes->msgq;
|
msgq = mqdes->msgq;
|
||||||
|
DEBUGASSERT(msgq && msgq->inode);
|
||||||
|
|
||||||
|
/* Get the inode from the message queue structure */
|
||||||
|
|
||||||
|
inode = msgq->inode;
|
||||||
|
DEBUGASSERT(inode->u.i_mqueue == msgq);
|
||||||
|
|
||||||
/* Check if the calling task has a notification attached to
|
/* Check if the calling task has a notification attached to
|
||||||
* the message queue via this mqdes.
|
* the message queue via this mqdes.
|
||||||
@@ -151,31 +147,31 @@ int mq_close(mqd_t mqdes)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Decrement the connection count on the message queue. */
|
/* Decrement the reference count on the inode */
|
||||||
|
|
||||||
if (msgq->nconnect)
|
inode_semtake();
|
||||||
|
if (inode->i_crefs > 0)
|
||||||
{
|
{
|
||||||
msgq->nconnect--;
|
inode->i_crefs--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If it is no longer connected to any message descriptor and if the
|
/* If the message queue was previously unlinked and the reference
|
||||||
* message queue has already been unlinked, then we can discard the
|
* count has decremented to zero, then release the message queue and
|
||||||
* message queue.
|
* delete the inode now.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!msgq->nconnect && msgq->unlinked)
|
if (inode->i_crefs <= 0 && (inode->i_flags & FSNODEFLAG_DELETED) != 0)
|
||||||
{
|
{
|
||||||
/* Remove the message queue from the list of all
|
/* Free the message queue (and any messages left in it) */
|
||||||
* 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);
|
mq_msgqfree(msgq);
|
||||||
|
|
||||||
|
/* Release and free the inode container */
|
||||||
|
|
||||||
|
inode_semgive();
|
||||||
|
inode_free(inode->i_child);
|
||||||
|
kmm_free(inode);
|
||||||
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Deallocate the message descriptor */
|
/* Deallocate the message descriptor */
|
||||||
@@ -183,9 +179,8 @@ int mq_close(mqd_t mqdes)
|
|||||||
mq_desfree(mqdes);
|
mq_desfree(mqdes);
|
||||||
|
|
||||||
sched_unlock();
|
sched_unlock();
|
||||||
ret = OK;
|
inode_semgive();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -234,9 +234,10 @@ mqd_t mq_open(const char *mq_name, int oflags, ...)
|
|||||||
goto errout_with_msgq;
|
goto errout_with_msgq;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the message queue in the inode structure */
|
/* Bind the message queue and the inode structure */
|
||||||
|
|
||||||
inode->u.i_mqueue = msgq;
|
inode->u.i_mqueue = msgq;
|
||||||
|
msgq->inode = inode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ int sem_close(FAR sem_t *sem)
|
|||||||
/* Decrement the reference count on the inode */
|
/* Decrement the reference count on the inode */
|
||||||
|
|
||||||
inode_semtake();
|
inode_semtake();
|
||||||
if (inode->i_crefs)
|
if (inode->i_crefs > 0)
|
||||||
{
|
{
|
||||||
inode->i_crefs--;
|
inode->i_crefs--;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ struct mq_des; /* forward reference */
|
|||||||
|
|
||||||
struct mqueue_inode_s
|
struct mqueue_inode_s
|
||||||
{
|
{
|
||||||
|
FAR struct inode *inode; /* Containing inode */
|
||||||
sq_queue_t msglist; /* Prioritized message list */
|
sq_queue_t msglist; /* Prioritized message list */
|
||||||
int16_t maxmsgs; /* Maximum number of messages in the queue */
|
int16_t maxmsgs; /* Maximum number of messages in the queue */
|
||||||
int16_t nmsgs; /* Number of message in the queue */
|
int16_t nmsgs; /* Number of message in the queue */
|
||||||
@@ -175,6 +176,19 @@ struct tcb_s;
|
|||||||
mqd_t mq_descreate(FAR struct tcb_s* mtcb, FAR struct mqueue_inode_s* msgq,
|
mqd_t mq_descreate(FAR struct tcb_s* mtcb, FAR struct mqueue_inode_s* msgq,
|
||||||
int oflags);
|
int oflags);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mq_desfree
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Deallocate a message queue descriptor but returning it to the free list
|
||||||
|
*
|
||||||
|
* Inputs:
|
||||||
|
* mqdes - message queue descriptor to free
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void mq_desfree(mqd_t mqdes);
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,6 +116,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Task Management Definitions **************************************************/
|
/* Task Management Definitions **************************************************/
|
||||||
|
/* Special task IDS. Any negative PID is invalid. */
|
||||||
|
|
||||||
|
#define NULL_TASK_PROCESS_ID (pid_t)0
|
||||||
|
#define INVALID_PROCESS_ID (pid_t)-1
|
||||||
|
|
||||||
/* This is the maximum number of times that a lock can be set */
|
/* This is the maximum number of times that a lock can be set */
|
||||||
|
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ struct nsem_inode_s
|
|||||||
{
|
{
|
||||||
/* Inode payload unique to named semaphores */
|
/* Inode payload unique to named semaphores */
|
||||||
|
|
||||||
sem_t ns_sem; /* The semaphore */
|
|
||||||
FAR struct inode *ns_inode; /* Containing inode */
|
FAR struct inode *ns_inode; /* Containing inode */
|
||||||
|
sem_t ns_sem; /* The semaphore */
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
|
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/compiler.h>
|
#include <nuttx/compiler.h>
|
||||||
|
#include <nuttx/sched.h>
|
||||||
#include <nuttx/fs/fs.h>
|
#include <nuttx/fs/fs.h>
|
||||||
#include <nuttx/net/net.h>
|
#include <nuttx/net/net.h>
|
||||||
#include <nuttx/lib.h>
|
#include <nuttx/lib.h>
|
||||||
|
|||||||
@@ -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_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_timedreceive.c mq_rcvinternal.c mq_initialize.c
|
||||||
MQUEUE_SRCS += mq_descreate.c mq_msgfree.c mq_msgqalloc.c mq_msgqfree.c
|
MQUEUE_SRCS += mq_descreate.c mq_desfree.c mq_msgfree.c mq_msgqalloc.c
|
||||||
MQUEUE_SRCS += mq_release.c mq_recover.c
|
MQUEUE_SRCS += mq_msgqfree.c mq_release.c mq_recover.c
|
||||||
|
|
||||||
ifneq ($(CONFIG_DISABLE_SIGNALS),y)
|
ifneq ($(CONFIG_DISABLE_SIGNALS),y)
|
||||||
MQUEUE_SRCS += mq_waitirq.c mq_notify.c
|
MQUEUE_SRCS += mq_waitirq.c mq_notify.c
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* sched/mqueue/mq_desfree.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 <queue.h>
|
||||||
|
|
||||||
|
#include <nuttx/mqueue.h>
|
||||||
|
|
||||||
|
#include "mqueue/mqueue.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Type Declarations
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public 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
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void mq_desfree(mqd_t mqdes)
|
||||||
|
{
|
||||||
|
sq_addlast((FAR sq_entry_t*)mqdes, &g_desfree);
|
||||||
|
}
|
||||||
@@ -44,6 +44,8 @@
|
|||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/sched.h>
|
||||||
|
|
||||||
#include "sched/sched.h"
|
#include "sched/sched.h"
|
||||||
#include "mqueue/mqueue.h"
|
#include "mqueue/mqueue.h"
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@
|
|||||||
|
|
||||||
#include <nuttx/kmalloc.h>
|
#include <nuttx/kmalloc.h>
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
|
#include <nuttx/sched.h>
|
||||||
#include "sched/sched.h"
|
#include "sched/sched.h"
|
||||||
#ifndef CONFIG_DISABLE_SIGNALS
|
#ifndef CONFIG_DISABLE_SIGNALS
|
||||||
# include "signal/signal.h"
|
# include "signal/signal.h"
|
||||||
|
|||||||
@@ -53,11 +53,6 @@
|
|||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* Special task IDS. Any negative PID is invalid. */
|
|
||||||
|
|
||||||
#define NULL_TASK_PROCESS_ID (pid_t)0
|
|
||||||
#define INVALID_PROCESS_ID (pid_t)-1
|
|
||||||
|
|
||||||
/* Although task IDs can take the (positive, non-zero)
|
/* Although task IDs can take the (positive, non-zero)
|
||||||
* range of pid_t, the number of tasks that will be supported
|
* range of pid_t, the number of tasks that will be supported
|
||||||
* at any one time is (artificially) limited by the CONFIG_MAX_TASKS
|
* at any one time is (artificially) limited by the CONFIG_MAX_TASKS
|
||||||
|
|||||||
@@ -42,7 +42,9 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
|
#include <nuttx/sched.h>
|
||||||
|
|
||||||
#include "sched/sched.h"
|
#include "sched/sched.h"
|
||||||
#include "group/group.h"
|
#include "group/group.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user