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
|
|
|
*
|
2020-03-10 16:26:30 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
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: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)
|
|
|
|
{
|
2020-05-09 16:04:45 +02:00
|
|
|
mtcb = nxsched_self();
|
2014-09-29 22:59:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|