summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nuttx/fs/mqueue/mq_close.c69
-rw-r--r--nuttx/fs/mqueue/mq_open.c3
-rw-r--r--nuttx/fs/semaphore/sem_close.c2
-rw-r--r--nuttx/include/nuttx/mqueue.h32
-rw-r--r--nuttx/include/nuttx/sched.h4
-rw-r--r--nuttx/include/nuttx/semaphore.h2
-rw-r--r--nuttx/sched/init/os_start.c1
-rw-r--r--nuttx/sched/mqueue/Make.defs4
-rw-r--r--nuttx/sched/mqueue/mq_desfree.c82
-rw-r--r--nuttx/sched/mqueue/mq_notify.c2
-rw-r--r--nuttx/sched/mqueue/mq_sndinternal.c32
-rw-r--r--nuttx/sched/sched/sched.h5
-rw-r--r--nuttx/sched/sched/sched_releasetcb.c2
13 files changed, 168 insertions, 72 deletions
diff --git a/nuttx/fs/mqueue/mq_close.c b/nuttx/fs/mqueue/mq_close.c
index e4a4812fe..4526f0771 100644
--- a/nuttx/fs/mqueue/mq_close.c
+++ b/nuttx/fs/mqueue/mq_close.c
@@ -39,11 +39,15 @@
#include <nuttx/config.h>
-#include <mqueue.h>
#include <sched.h>
+#include <mqueue.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"
/****************************************************************************
@@ -67,19 +71,6 @@
****************************************************************************/
/****************************************************************************
- * 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
****************************************************************************/
@@ -113,11 +104,10 @@
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 mqueue_inode_s *msgq;
- irqstate_t saved_state;
- int ret = ERROR;
+ struct inode *inode ;
DEBUGASSERT(group);
@@ -136,6 +126,12 @@ int mq_close(mqd_t mqdes)
/* Find the message queue associated with the message descriptor */
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
* the message queue via this mqdes.
@@ -151,41 +147,40 @@ int mq_close(mqd_t mqdes)
}
#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
- * message queue has already been unlinked, then we can discard the
- * message queue.
+ /* If the message queue was previously unlinked and the reference
+ * count has decremented to zero, then release the message queue and
+ * 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
- * message queues
- */
+ /* Free the message queue (and any messages left in it) */
- saved_state = irqsave();
- (void)sq_rem((FAR sq_entry_t*)msgq, &g_msgqueues);
- irqrestore(saved_state);
+ mq_msgqfree(msgq);
- /* Then deallocate it (and any messages left in it) */
+ /* Release and free the inode container */
- mq_msgqfree(msgq);
- }
+ inode_semgive();
+ inode_free(inode->i_child);
+ kmm_free(inode);
+ return OK;
+ }
/* Deallocate the message descriptor */
mq_desfree(mqdes);
sched_unlock();
- ret = OK;
+ inode_semgive();
}
- return ret;
+ return OK;
}
-
diff --git a/nuttx/fs/mqueue/mq_open.c b/nuttx/fs/mqueue/mq_open.c
index 299afc4fd..4731e3a33 100644
--- a/nuttx/fs/mqueue/mq_open.c
+++ b/nuttx/fs/mqueue/mq_open.c
@@ -234,9 +234,10 @@ mqd_t mq_open(const char *mq_name, int oflags, ...)
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;
+ msgq->inode = inode;
}
}
diff --git a/nuttx/fs/semaphore/sem_close.c b/nuttx/fs/semaphore/sem_close.c
index d0691ed69..58bea67ce 100644
--- a/nuttx/fs/semaphore/sem_close.c
+++ b/nuttx/fs/semaphore/sem_close.c
@@ -117,7 +117,7 @@ int sem_close(FAR sem_t *sem)
/* Decrement the reference count on the inode */
inode_semtake();
- if (inode->i_crefs)
+ if (inode->i_crefs > 0)
{
inode->i_crefs--;
}
diff --git a/nuttx/include/nuttx/mqueue.h b/nuttx/include/nuttx/mqueue.h
index 748e4a6a6..e2884ac61 100644
--- a/nuttx/include/nuttx/mqueue.h
+++ b/nuttx/include/nuttx/mqueue.h
@@ -66,20 +66,21 @@ struct mq_des; /* forward reference */
struct mqueue_inode_s
{
- 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 nwaitnotfull; /* Number tasks waiting for not full */
- int16_t nwaitnotempty; /* Number tasks waiting for not empty */
+ FAR struct inode *inode; /* Containing inode */
+ 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 nwaitnotfull; /* Number tasks waiting for not full */
+ int16_t nwaitnotempty; /* Number tasks waiting for not empty */
#if CONFIG_MQ_MAXMSGSIZE < 256
- uint8_t maxmsgsize; /* Max size of message in message queue */
+ uint8_t maxmsgsize; /* Max size of message in message queue */
#else
- uint16_t maxmsgsize; /* Max size of message in message queue */
+ uint16_t maxmsgsize; /* Max size of message in message queue */
#endif
#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 */
+ pid_t ntpid; /* Notification: Receiving Task's PID */
+ int ntsigno; /* Notification: Signal number */
union sigval ntvalue; /* Notification: Signal value */
#endif
};
@@ -175,6 +176,19 @@ struct tcb_s;
mqd_t mq_descreate(FAR struct tcb_s* mtcb, FAR struct mqueue_inode_s* msgq,
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
#ifdef __cplusplus
}
diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h
index 3509d3456..563773ec1 100644
--- a/nuttx/include/nuttx/sched.h
+++ b/nuttx/include/nuttx/sched.h
@@ -116,6 +116,10 @@
#endif
/* 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 */
diff --git a/nuttx/include/nuttx/semaphore.h b/nuttx/include/nuttx/semaphore.h
index f0a9fba91..33e701cc8 100644
--- a/nuttx/include/nuttx/semaphore.h
+++ b/nuttx/include/nuttx/semaphore.h
@@ -62,8 +62,8 @@ struct nsem_inode_s
{
/* Inode payload unique to named semaphores */
- sem_t ns_sem; /* The semaphore */
FAR struct inode *ns_inode; /* Containing inode */
+ sem_t ns_sem; /* The semaphore */
};
#endif
diff --git a/nuttx/sched/init/os_start.c b/nuttx/sched/init/os_start.c
index 309cb4020..dae073b22 100644
--- a/nuttx/sched/init/os_start.c
+++ b/nuttx/sched/init/os_start.c
@@ -45,6 +45,7 @@
#include <nuttx/arch.h>
#include <nuttx/compiler.h>
+#include <nuttx/sched.h>
#include <nuttx/fs/fs.h>
#include <nuttx/net/net.h>
#include <nuttx/lib.h>
diff --git a/nuttx/sched/mqueue/Make.defs b/nuttx/sched/mqueue/Make.defs
index c4aec37fd..a43359b06 100644
--- a/nuttx/sched/mqueue/Make.defs
+++ b/nuttx/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_msgqalloc.c mq_msgqfree.c
-MQUEUE_SRCS += mq_release.c mq_recover.c
+MQUEUE_SRCS += mq_descreate.c mq_desfree.c mq_msgfree.c mq_msgqalloc.c
+MQUEUE_SRCS += mq_msgqfree.c mq_release.c mq_recover.c
ifneq ($(CONFIG_DISABLE_SIGNALS),y)
MQUEUE_SRCS += mq_waitirq.c mq_notify.c
diff --git a/nuttx/sched/mqueue/mq_desfree.c b/nuttx/sched/mqueue/mq_desfree.c
new file mode 100644
index 000000000..2c16a7f92
--- /dev/null
+++ b/nuttx/sched/mqueue/mq_desfree.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);
+}
diff --git a/nuttx/sched/mqueue/mq_notify.c b/nuttx/sched/mqueue/mq_notify.c
index 822405069..5c7a15cc9 100644
--- a/nuttx/sched/mqueue/mq_notify.c
+++ b/nuttx/sched/mqueue/mq_notify.c
@@ -44,6 +44,8 @@
#include <sched.h>
#include <errno.h>
+#include <nuttx/sched.h>
+
#include "sched/sched.h"
#include "mqueue/mqueue.h"
diff --git a/nuttx/sched/mqueue/mq_sndinternal.c b/nuttx/sched/mqueue/mq_sndinternal.c
index 2339d7a7f..4d2ce77c2 100644
--- a/nuttx/sched/mqueue/mq_sndinternal.c
+++ b/nuttx/sched/mqueue/mq_sndinternal.c
@@ -37,25 +37,25 @@
* Included Files
****************************************************************************/
-#include <nuttx/config.h>
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <fcntl.h>
-#include <mqueue.h>
-#include <string.h>
-#include <errno.h>
-#include <sched.h>
-#include <debug.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/arch.h>
-
-#include "sched/sched.h"
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <fcntl.h>
+#include <mqueue.h>
+#include <string.h>
+#include <errno.h>
+#include <sched.h>
+#include <debug.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/arch.h>
+#include <nuttx/sched.h>
+#include "sched/sched.h"
#ifndef CONFIG_DISABLE_SIGNALS
# include "signal/signal.h"
#endif
-#include "mqueue/mqueue.h"
+#include "mqueue/mqueue.h"
/****************************************************************************
* Definitions
diff --git a/nuttx/sched/sched/sched.h b/nuttx/sched/sched/sched.h
index 2f5f800af..d038d007c 100644
--- a/nuttx/sched/sched/sched.h
+++ b/nuttx/sched/sched/sched.h
@@ -53,11 +53,6 @@
* 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)
* range of pid_t, the number of tasks that will be supported
* at any one time is (artificially) limited by the CONFIG_MAX_TASKS
diff --git a/nuttx/sched/sched/sched_releasetcb.c b/nuttx/sched/sched/sched_releasetcb.c
index 1daa9d24b..79fcb2010 100644
--- a/nuttx/sched/sched/sched_releasetcb.c
+++ b/nuttx/sched/sched/sched_releasetcb.c
@@ -42,7 +42,9 @@
#include <sys/types.h>
#include <sched.h>
#include <errno.h>
+
#include <nuttx/arch.h>
+#include <nuttx/sched.h>
#include "sched/sched.h"
#include "group/group.h"