Beispiel #1
0
void mq_desclose(mqd_t mqdes)
{
	FAR struct tcb_s *rtcb = (FAR struct tcb_s *)sched_self();
	FAR struct task_group_s *group = rtcb->group;
	FAR struct mqueue_inode_s *msgq;

	DEBUGASSERT(mqdes && group);

	/* 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

	/* Deallocate the message descriptor */

	mq_desfree(mqdes);
}
Beispiel #2
0
int mq_close(mqd_t mqdes)
{
  FAR _TCB    *rtcb = (FAR _TCB*)g_readytorun.head;
  FAR msgq_t *msgq;
  irqstate_t  saved_state;
  int         ret = ERROR;

  /* 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, &rtcb->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;
}