summaryrefslogtreecommitdiff
path: root/nuttx/fs/mqueue
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-09-29 15:33:34 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-09-29 15:33:34 -0600
commit43b185f9cb9da1bde9caa42ad9daede6d7c10b4d (patch)
tree0a9db3519dd29c500ed5e555095ee25cae7af97c /nuttx/fs/mqueue
parent92b3c77f738b63b1eedc4977f1c68a1fdcc74268 (diff)
downloadpx4-nuttx-43b185f9cb9da1bde9caa42ad9daede6d7c10b4d.tar.gz
px4-nuttx-43b185f9cb9da1bde9caa42ad9daede6d7c10b4d.tar.bz2
px4-nuttx-43b185f9cb9da1bde9caa42ad9daede6d7c10b4d.zip
Complete re-implementation of mq_close
Diffstat (limited to 'nuttx/fs/mqueue')
-rw-r--r--nuttx/fs/mqueue/mq_close.c69
-rw-r--r--nuttx/fs/mqueue/mq_open.c3
2 files changed, 34 insertions, 38 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;
}
}