2008-01-30 15:01:22 +01:00
|
|
|
/****************************************************************************
|
2014-08-08 20:31:23 +02:00
|
|
|
* sched/mqueue/mq_descreate.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2016-04-11 19:14:18 +02:00
|
|
|
* Copyright (C) 2007-2009, 2013, 2016 Gregory Nutt. All rights reserved.
|
2012-07-14 21:30:31 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2008-01-30 15:01:22 +01:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-02-18 00:21:28 +01:00
|
|
|
* 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.
|
|
|
|
*
|
2008-01-30 15:01:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-30 15:01:22 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-01-30 15:01:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2009-12-14 19:39:29 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
#include <stdarg.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <mqueue.h>
|
|
|
|
#include <sched.h>
|
2012-07-14 21:30:31 +02:00
|
|
|
#include <queue.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <debug.h>
|
2012-07-14 21:30:31 +02:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <nuttx/arch.h>
|
2012-07-14 21:30:31 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
2016-04-11 19:14:18 +02:00
|
|
|
#include <nuttx/sched.h>
|
2014-09-29 22:59:31 +02:00
|
|
|
#include <nuttx/mqueue.h>
|
2012-07-14 21:30:31 +02:00
|
|
|
|
2014-08-08 20:44:44 +02:00
|
|
|
#include "signal/signal.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-08 20:31:23 +02:00
|
|
|
#include "mqueue/mqueue.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-30 15:01:22 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Private Functions
|
2008-01-30 15:01:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-30 15:01:22 +01:00
|
|
|
/****************************************************************************
|
2017-10-09 17:06:46 +02:00
|
|
|
* Name: nxmq_alloc_des
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Allocate a message queue descriptor.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2007-02-18 00:21:28 +01:00
|
|
|
* None
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2007-02-18 00:21:28 +01:00
|
|
|
* Reference to the allocated mq descriptor.
|
|
|
|
*
|
2008-01-30 15:01:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-10-09 17:06:46 +02:00
|
|
|
static mqd_t nxmq_alloc_des(void)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
mqd_t mqdes;
|
|
|
|
|
|
|
|
/* Try to get the message descriptorfrom the free list */
|
|
|
|
|
|
|
|
mqdes = (mqd_t)sq_remfirst(&g_desfree);
|
|
|
|
|
|
|
|
/* Check if we got one. */
|
|
|
|
|
|
|
|
if (!mqdes)
|
|
|
|
{
|
|
|
|
/* Add another block of message descriptors to the list */
|
|
|
|
|
2017-10-09 17:06:46 +02:00
|
|
|
nxmq_alloc_desblock();
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* And try again */
|
|
|
|
|
|
|
|
mqdes = (mqd_t)sq_remfirst(&g_desfree);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mqdes;
|
|
|
|
}
|
|
|
|
|
2008-01-30 15:01:22 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2008-01-30 15:01:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-30 15:01:22 +01:00
|
|
|
/****************************************************************************
|
2017-10-10 16:43:10 +02:00
|
|
|
* Name: nxmq_create_des
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Create a message queue descriptor for the specified TCB
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2014-09-29 22:59:31 +02:00
|
|
|
* mtcb - task that needs the descriptor.
|
|
|
|
* msgq - Named message queue containing the message
|
2007-02-18 00:21:28 +01:00
|
|
|
* oflags - access rights for the descriptor
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2012-07-14 21:30:31 +02:00
|
|
|
* On success, the message queue descriptor is returned. NULL is returned
|
|
|
|
* on a failure to allocate.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-01-30 15:01:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-10-10 16:43:10 +02:00
|
|
|
mqd_t nxmq_create_des(FAR struct tcb_s *mtcb,
|
|
|
|
FAR struct mqueue_inode_s *msgq, int oflags)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2014-09-29 22:59:31 +02:00
|
|
|
FAR struct task_group_s *group;
|
2007-02-18 00:21:28 +01:00
|
|
|
mqd_t mqdes;
|
|
|
|
|
2014-09-29 22:59:31 +02:00
|
|
|
/* A NULL TCB pointer means to use the TCB of the currently executing
|
|
|
|
* task/thread.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!mtcb)
|
|
|
|
{
|
|
|
|
mtcb = sched_self();
|
|
|
|
}
|
|
|
|
|
|
|
|
group = mtcb->group;
|
2013-02-04 17:55:38 +01:00
|
|
|
DEBUGASSERT(group);
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Create a message queue descriptor for the TCB */
|
|
|
|
|
2017-10-09 17:06:46 +02:00
|
|
|
mqdes = nxmq_alloc_des();
|
2007-02-18 00:21:28 +01:00
|
|
|
if (mqdes)
|
|
|
|
{
|
2014-09-29 22:59:31 +02:00
|
|
|
/* Initialize the message queue descriptor */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
memset(mqdes, 0, sizeof(struct mq_des));
|
|
|
|
mqdes->msgq = msgq;
|
|
|
|
mqdes->oflags = oflags;
|
|
|
|
|
2014-09-29 22:59:31 +02:00
|
|
|
/* And add it to the specified task's TCB */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
sq_addlast((FAR sq_entry_t *)mqdes, &group->tg_msgdesq);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return mqdes;
|
|
|
|
}
|