2007-03-29 15:25:18 +02:00
|
|
|
/****************************************************************************
|
2016-12-10 15:36:58 +01:00
|
|
|
* sched/mqueue/mq_sndinternal.c
|
2007-03-29 15:25:18 +02: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
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
2020-03-10 16:26:30 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
2020-03-10 16:26:30 +01:00
|
|
|
* 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-03-29 15:25:18 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-29 23:33:34 +02:00
|
|
|
#include <nuttx/config.h>
|
2009-12-14 20:30:18 +01:00
|
|
|
|
2014-09-29 23:33:34 +02:00
|
|
|
#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>
|
2009-12-14 20:30:18 +01:00
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
#include <nuttx/irq.h>
|
2014-09-29 23:33:34 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/sched.h>
|
2016-12-10 16:08:26 +01:00
|
|
|
#include <nuttx/cancelpt.h>
|
2015-12-30 20:20:31 +01:00
|
|
|
|
2014-09-29 23:33:34 +02:00
|
|
|
#include "sched/sched.h"
|
|
|
|
#include "mqueue/mqueue.h"
|
2007-03-29 15:25:18 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-10-09 17:06:46 +02:00
|
|
|
* Name: nxmq_verify_send
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-10-10 16:43:10 +02:00
|
|
|
* This is internal, common logic shared by both [nx]mq_send and
|
|
|
|
* [nx]mq_timesend. This function verifies the input parameters that are
|
|
|
|
* common to both functions.
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
2017-10-10 16:43:10 +02:00
|
|
|
* Input Parameters:
|
2007-03-29 15:25:18 +02:00
|
|
|
* mqdes - Message queue descriptor
|
|
|
|
* msg - Message to send
|
|
|
|
* msglen - The length of the message in bytes
|
|
|
|
* prio - The priority of the message
|
|
|
|
*
|
2017-10-10 16:43:10 +02:00
|
|
|
* Returned Value:
|
|
|
|
* One success, 0 (OK) is returned. On failure, a negated errno value is
|
|
|
|
* returned.
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
2017-10-10 16:43:10 +02:00
|
|
|
* EINVAL Either msg or mqdes is NULL or the value of prio is invalid.
|
|
|
|
* EPERM Message queue opened not opened for writing.
|
|
|
|
* EMSGSIZE 'msglen' was greater than the maxmsgsize attribute of the
|
|
|
|
* message queue.
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-10-09 17:06:46 +02:00
|
|
|
int nxmq_verify_send(mqd_t mqdes, FAR const char *msg, size_t msglen,
|
2019-02-16 02:18:55 +01:00
|
|
|
unsigned int prio)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
|
|
|
/* Verify the input parameters */
|
|
|
|
|
2019-02-16 02:18:55 +01:00
|
|
|
if (msg == NULL || mqdes == NULL || prio > MQ_PRIO_MAX)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
2017-10-10 16:43:10 +02:00
|
|
|
return -EINVAL;
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((mqdes->oflags & O_WROK) == 0)
|
|
|
|
{
|
2017-10-10 16:43:10 +02:00
|
|
|
return -EPERM;
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
|
|
|
|
2013-01-24 19:39:53 +01:00
|
|
|
if (msglen > (size_t)mqdes->msgq->maxmsgsize)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
2017-10-10 16:43:10 +02:00
|
|
|
return -EMSGSIZE;
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-10-09 17:06:46 +02:00
|
|
|
* Name: nxmq_alloc_msg
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-10-09 17:06:46 +02:00
|
|
|
* The nxmq_alloc_msg function will get a free message for use by the
|
2012-07-14 21:30:31 +02:00
|
|
|
* operating system. The message will be allocated from the g_msgfree
|
|
|
|
* list.
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
|
|
|
* If the list is empty AND the message is NOT being allocated from the
|
|
|
|
* interrupt level, then the message will be allocated. If a message
|
|
|
|
* cannot be obtained, the operating system is dead and therefore cannot
|
|
|
|
* continue.
|
|
|
|
*
|
|
|
|
* If the list is empty AND the message IS being allocated from the
|
2014-04-13 22:32:20 +02:00
|
|
|
* interrupt level. This function will attempt to get a message from
|
2007-03-29 15:25:18 +02:00
|
|
|
* the g_msgfreeirq list. If this is unsuccessful, the calling interrupt
|
|
|
|
* handler will be notified.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2007-03-29 15:25:18 +02:00
|
|
|
* None
|
|
|
|
*
|
2017-10-10 16:43:10 +02:00
|
|
|
* Returned Value:
|
2007-03-29 15:25:18 +02:00
|
|
|
* A reference to the allocated msg structure. On a failure to allocate,
|
|
|
|
* this function PANICs.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-10-09 17:06:46 +02:00
|
|
|
FAR struct mqueue_msg_s *nxmq_alloc_msg(void)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
2014-09-29 21:35:32 +02:00
|
|
|
FAR struct mqueue_msg_s *mqmsg;
|
2016-02-14 15:17:46 +01:00
|
|
|
irqstate_t flags;
|
2007-03-29 15:25:18 +02:00
|
|
|
|
|
|
|
/* If we were called from an interrupt handler, then try to get the message
|
|
|
|
* from generally available list of messages. If this fails, then try the
|
|
|
|
* list of messages reserved for interrupt handlers
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (up_interrupt_context())
|
|
|
|
{
|
|
|
|
/* Try the general free list */
|
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
mqmsg = (FAR struct mqueue_msg_s *)sq_remfirst(&g_msgfree);
|
2016-09-15 20:42:24 +02:00
|
|
|
if (mqmsg == NULL)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
|
|
|
/* Try the free list reserved for interrupt handlers */
|
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
mqmsg = (FAR struct mqueue_msg_s *)sq_remfirst(&g_msgfreeirq);
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We were not called from an interrupt handler. */
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Try to get the message from the generally available free list.
|
|
|
|
* Disable interrupts -- we might be called from an interrupt handler.
|
|
|
|
*/
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2015-10-08 03:59:14 +02:00
|
|
|
mqmsg = (FAR struct mqueue_msg_s *)sq_remfirst(&g_msgfree);
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2016-09-15 20:42:24 +02:00
|
|
|
/* If we cannot a message from the free list, then we will have to
|
|
|
|
* allocate one.
|
|
|
|
*/
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2016-09-15 20:42:24 +02:00
|
|
|
if (mqmsg == NULL)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
2016-09-15 20:42:24 +02:00
|
|
|
mqmsg = (FAR struct mqueue_msg_s *)
|
|
|
|
kmm_malloc((sizeof (struct mqueue_msg_s)));
|
|
|
|
|
|
|
|
/* Check if we allocated the message */
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2016-09-15 20:42:24 +02:00
|
|
|
if (mqmsg != NULL)
|
|
|
|
{
|
2020-04-11 22:23:39 +02:00
|
|
|
/* Yes... remember that this message was dynamically
|
|
|
|
* allocated.
|
|
|
|
*/
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2016-09-15 20:42:24 +02:00
|
|
|
mqmsg->type = MQ_ALLOC_DYN;
|
|
|
|
}
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mqmsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-10-09 17:06:46 +02:00
|
|
|
* Name: nxmq_wait_send
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-10-10 16:43:10 +02:00
|
|
|
* This is internal, common logic shared by both [nx]mq_send and
|
|
|
|
* [nx]mq_timesend. This function waits until the message queue is not
|
|
|
|
* full.
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
2017-10-10 16:43:10 +02:00
|
|
|
* Input Parameters:
|
2007-03-29 15:25:18 +02:00
|
|
|
* mqdes - Message queue descriptor
|
|
|
|
*
|
2017-10-10 16:43:10 +02:00
|
|
|
* Returned Value:
|
|
|
|
* On success, nxmq_wait_send() returns 0 (OK); a negated errno value is
|
|
|
|
* returned on any failure:
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
2016-09-15 16:46:41 +02:00
|
|
|
* EAGAIN The queue was full and the O_NONBLOCK flag was set for the
|
2007-03-29 15:25:18 +02:00
|
|
|
* message queue description referred to by mqdes.
|
|
|
|
* EINTR The call was interrupted by a signal handler.
|
|
|
|
* ETIMEOUT A timeout expired before the message queue became non-full
|
|
|
|
* (mq_timedsend only).
|
|
|
|
*
|
|
|
|
* Assumptions/restrictions:
|
2017-10-09 17:06:46 +02:00
|
|
|
* - The caller has verified the input parameters using nxmq_verify_send().
|
2017-02-24 17:07:23 +01:00
|
|
|
* - Executes within a critical section established by the caller.
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-10-09 17:06:46 +02:00
|
|
|
int nxmq_wait_send(mqd_t mqdes)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
2013-02-04 19:46:28 +01:00
|
|
|
FAR struct tcb_s *rtcb;
|
2014-09-29 21:19:11 +02:00
|
|
|
FAR struct mqueue_inode_s *msgq;
|
2017-10-10 16:43:10 +02:00
|
|
|
int ret;
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2017-10-10 16:43:10 +02:00
|
|
|
#ifdef CONFIG_CANCELLATION_POINTS
|
|
|
|
/* nxmq_wait_send() is not a cancellation point, but may be called via
|
|
|
|
* mq_send() or mq_timedsend() which are cancellation points.
|
2016-12-10 15:36:58 +01:00
|
|
|
*/
|
|
|
|
|
2017-10-10 16:43:10 +02:00
|
|
|
if (check_cancellation_point())
|
2016-12-10 15:36:58 +01:00
|
|
|
{
|
|
|
|
/* If there is a pending cancellation, then do not perform
|
|
|
|
* the wait. Exit now with ECANCELED.
|
|
|
|
*/
|
|
|
|
|
2017-10-10 16:43:10 +02:00
|
|
|
return -ECANCELED;
|
2016-12-10 15:36:58 +01:00
|
|
|
}
|
2017-10-10 16:43:10 +02:00
|
|
|
#endif
|
2016-12-10 15:36:58 +01:00
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
/* Get a pointer to the message queue */
|
|
|
|
|
|
|
|
msgq = mqdes->msgq;
|
|
|
|
|
|
|
|
/* Verify that the queue is indeed full as the caller thinks */
|
|
|
|
|
|
|
|
if (msgq->nmsgs >= msgq->maxmsgs)
|
|
|
|
{
|
|
|
|
/* Should we block until there is sufficient space in the
|
|
|
|
* message queue?
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((mqdes->oflags & O_NONBLOCK) != 0)
|
|
|
|
{
|
|
|
|
/* No... We will return an error to the caller. */
|
|
|
|
|
2017-10-10 16:43:10 +02:00
|
|
|
return -EAGAIN;
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Yes... We will not return control until the message queue is
|
2020-02-23 09:50:23 +01:00
|
|
|
* available or we receive a signal or at timeout occurs.
|
2007-03-29 15:25:18 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2014-04-13 22:32:20 +02:00
|
|
|
/* Loop until there are fewer than max allowable messages in the
|
2007-03-29 15:25:18 +02:00
|
|
|
* receiving message queue
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (msgq->nmsgs >= msgq->maxmsgs)
|
|
|
|
{
|
2017-10-10 16:43:10 +02:00
|
|
|
int saved_errno;
|
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
/* Block until the message queue is no longer full.
|
|
|
|
* When we are unblocked, we will try again
|
|
|
|
*/
|
|
|
|
|
2017-10-10 16:43:10 +02:00
|
|
|
rtcb = this_task();
|
2007-03-29 15:25:18 +02:00
|
|
|
rtcb->msgwaitq = msgq;
|
2011-09-21 15:28:16 +02:00
|
|
|
msgq->nwaitnotfull++;
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2017-10-10 16:43:10 +02:00
|
|
|
/* "Borrow" the per-task errno to communication wake-up error
|
|
|
|
* conditions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
saved_errno = rtcb->pterrno;
|
|
|
|
rtcb->pterrno = OK;
|
|
|
|
|
2018-11-30 13:54:15 +01:00
|
|
|
/* Make sure this is not the idle task, descheduling that
|
|
|
|
* isn't going to end well.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEBUGASSERT(NULL != rtcb->flink);
|
2007-03-29 15:25:18 +02:00
|
|
|
up_block_task(rtcb, TSTATE_WAIT_MQNOTFULL);
|
|
|
|
|
|
|
|
/* When we resume at this point, either (1) the message queue
|
|
|
|
* is no longer empty, or (2) the wait has been interrupted by
|
|
|
|
* a signal. We can detect the latter case be examining the
|
2017-10-10 16:43:10 +02:00
|
|
|
* per-task errno value (should be EINTR or ETIMEOUT).
|
2007-03-29 15:25:18 +02:00
|
|
|
*/
|
|
|
|
|
2017-10-10 16:43:10 +02:00
|
|
|
ret = rtcb->pterrno;
|
|
|
|
rtcb->pterrno = saved_errno;
|
|
|
|
|
|
|
|
if (ret != OK)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
2017-10-10 16:43:10 +02:00
|
|
|
return -ret;
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-10 19:05:33 +01:00
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-10-09 17:06:46 +02:00
|
|
|
* Name: nxmq_do_send
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-10-10 16:43:10 +02:00
|
|
|
* This is internal, common logic shared by both [nx]mq_send and
|
|
|
|
* [nx]mq_timesend. This function adds the specified message (msg) to the
|
|
|
|
* message queue (mqdes). Then it notifies any tasks that were waiting
|
|
|
|
* for message queue notifications setup by mq_notify. And, finally, it
|
|
|
|
* awakens any tasks that were waiting for the message not empty event.
|
2014-04-13 22:32:20 +02:00
|
|
|
*
|
2017-10-10 16:43:10 +02:00
|
|
|
* Input Parameters:
|
|
|
|
* mqdes - Message queue descriptor
|
|
|
|
* msg - Message to send
|
2007-03-29 15:25:18 +02:00
|
|
|
* msglen - The length of the message in bytes
|
2017-10-10 16:43:10 +02:00
|
|
|
* prio - The priority of the message
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
2017-10-10 16:43:10 +02:00
|
|
|
* Returned Value:
|
2007-03-29 15:25:18 +02:00
|
|
|
* This function always returns OK.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-10-09 17:06:46 +02:00
|
|
|
int nxmq_do_send(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg,
|
2019-02-16 02:18:55 +01:00
|
|
|
FAR const char *msg, size_t msglen, unsigned int prio)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
2013-02-04 19:46:28 +01:00
|
|
|
FAR struct tcb_s *btcb;
|
2014-09-29 21:19:11 +02:00
|
|
|
FAR struct mqueue_inode_s *msgq;
|
2014-09-29 21:35:32 +02:00
|
|
|
FAR struct mqueue_msg_s *next;
|
|
|
|
FAR struct mqueue_msg_s *prev;
|
2016-02-14 15:17:46 +01:00
|
|
|
irqstate_t flags;
|
2007-03-29 15:25:18 +02:00
|
|
|
|
|
|
|
/* Get a pointer to the message queue */
|
|
|
|
|
|
|
|
sched_lock();
|
|
|
|
msgq = mqdes->msgq;
|
|
|
|
|
|
|
|
/* Construct the message header info */
|
|
|
|
|
|
|
|
mqmsg->priority = prio;
|
|
|
|
mqmsg->msglen = msglen;
|
|
|
|
|
|
|
|
/* Copy the message data into the message */
|
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
memcpy((FAR void *)mqmsg->mail, (FAR const void *)msg, msglen);
|
2007-03-29 15:25:18 +02:00
|
|
|
|
|
|
|
/* Insert the new message in the message queue */
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2007-03-29 15:25:18 +02:00
|
|
|
|
|
|
|
/* Search the message list to find the location to insert the new
|
|
|
|
* message. Each is list is maintained in ascending priority order.
|
|
|
|
*/
|
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
for (prev = NULL, next = (FAR struct mqueue_msg_s *)msgq->msglist.head;
|
2007-03-29 15:25:18 +02:00
|
|
|
next && prio <= next->priority;
|
|
|
|
prev = next, next = next->next);
|
|
|
|
|
|
|
|
/* Add the message at the right place */
|
|
|
|
|
|
|
|
if (prev)
|
|
|
|
{
|
2015-10-08 03:59:14 +02:00
|
|
|
sq_addafter((FAR sq_entry_t *)prev, (FAR sq_entry_t *)mqmsg,
|
2007-03-29 15:25:18 +02:00
|
|
|
&msgq->msglist);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-08 03:59:14 +02:00
|
|
|
sq_addfirst((FAR sq_entry_t *)mqmsg, &msgq->msglist);
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Increment the count of messages in the queue */
|
|
|
|
|
|
|
|
msgq->nmsgs++;
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2007-03-29 15:25:18 +02:00
|
|
|
|
|
|
|
/* Check if we need to notify any tasks that are attached to the
|
|
|
|
* message queue
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (msgq->ntmqdes)
|
|
|
|
{
|
2015-12-30 20:20:31 +01:00
|
|
|
struct sigevent event;
|
|
|
|
pid_t pid;
|
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
/* Remove the message notification data from the message queue. */
|
|
|
|
|
2015-12-30 20:20:31 +01:00
|
|
|
memcpy(&event, &msgq->ntevent, sizeof(struct sigevent));
|
|
|
|
pid = msgq->ntpid;
|
2007-03-29 15:25:18 +02:00
|
|
|
|
|
|
|
/* Detach the notification */
|
|
|
|
|
2015-12-30 20:20:31 +01:00
|
|
|
memset(&msgq->ntevent, 0, sizeof(struct sigevent));
|
|
|
|
msgq->ntpid = INVALID_PROCESS_ID;
|
|
|
|
msgq->ntmqdes = NULL;
|
|
|
|
|
2018-11-08 15:19:17 +01:00
|
|
|
/* Notification the client */
|
2015-12-30 20:20:31 +01:00
|
|
|
|
2019-01-27 16:28:59 +01:00
|
|
|
DEBUGVERIFY(nxsig_notification(pid, &event,
|
|
|
|
SI_MESGQ, &msgq->ntwork));
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
2012-05-17 18:55:13 +02:00
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
/* Check if any tasks are waiting for the MQ not empty event. */
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2007-03-29 15:25:18 +02:00
|
|
|
if (msgq->nwaitnotempty > 0)
|
|
|
|
{
|
|
|
|
/* Find the highest priority task that is waiting for
|
|
|
|
* this queue to be non-empty in g_waitingformqnotempty
|
2020-02-22 19:31:14 +01:00
|
|
|
* list. sched_lock() should give us sufficient protection since
|
2007-03-29 15:25:18 +02:00
|
|
|
* interrupts should never cause a change in this list
|
|
|
|
*/
|
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
for (btcb = (FAR struct tcb_s *)g_waitingformqnotempty.head;
|
2007-03-29 15:25:18 +02:00
|
|
|
btcb && btcb->msgwaitq != msgq;
|
2020-04-11 22:23:39 +02:00
|
|
|
btcb = btcb->flink)
|
|
|
|
{
|
|
|
|
}
|
2007-03-29 15:25:18 +02:00
|
|
|
|
|
|
|
/* If one was found, unblock it */
|
|
|
|
|
2018-08-24 14:58:30 +02:00
|
|
|
DEBUGASSERT(btcb);
|
2013-04-25 23:19:59 +02:00
|
|
|
|
|
|
|
btcb->msgwaitq = NULL;
|
|
|
|
msgq->nwaitnotempty--;
|
|
|
|
up_unblock_task(btcb);
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
2012-05-17 18:55:13 +02:00
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2007-03-29 15:25:18 +02:00
|
|
|
sched_unlock();
|
|
|
|
return OK;
|
|
|
|
}
|