2007-03-29 15:25:18 +02:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* sched/mqueue/mq_sndinternal.c
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
2024-09-11 13:45:11 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
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>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2014-09-29 23:33:34 +02:00
|
|
|
#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:
|
2020-12-22 15:02:48 +01:00
|
|
|
* msgq - Message queue descriptor
|
|
|
|
* msg - Message to send
|
2007-03-29 15:25:18 +02:00
|
|
|
* msglen - The length of the message in bytes
|
2020-12-22 15:02:48 +01: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:
|
2021-05-06 04:18:49 +02:00
|
|
|
* On success, 0 (OK) is returned. On failure, a negated errno value is
|
2017-10-10 16:43:10 +02:00
|
|
|
* returned.
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
2020-12-22 15:02:48 +01:00
|
|
|
* EINVAL Either msg or msgq is NULL or the value of prio is invalid.
|
2023-06-09 11:45:22 +02:00
|
|
|
* EBADF Message queue opened not opened for writing.
|
2017-10-10 16:43:10 +02:00
|
|
|
* EMSGSIZE 'msglen' was greater than the maxmsgsize attribute of the
|
|
|
|
* message queue.
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-06-09 07:37:11 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2024-08-25 01:21:12 +02:00
|
|
|
int nxmq_verify_send(FAR struct file *mq, FAR const char *msg,
|
2022-06-09 07:37:11 +02:00
|
|
|
size_t msglen, unsigned int prio)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
2022-06-09 07:37:11 +02:00
|
|
|
FAR struct inode *inode = mq->f_inode;
|
|
|
|
FAR struct mqueue_inode_s *msgq;
|
|
|
|
|
|
|
|
if (inode == NULL)
|
|
|
|
{
|
|
|
|
return -EBADF;
|
|
|
|
}
|
|
|
|
|
|
|
|
msgq = inode->i_private;
|
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
/* Verify the input parameters */
|
|
|
|
|
2023-06-09 11:45:22 +02:00
|
|
|
if (msg == NULL || msgq == 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
|
|
|
}
|
|
|
|
|
2022-06-09 07:37:11 +02:00
|
|
|
if ((mq->f_oflags & O_WROK) == 0)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
2023-06-09 11:45:22 +02:00
|
|
|
return -EBADF;
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-22 15:02:48 +01:00
|
|
|
if (msglen > (size_t)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;
|
|
|
|
}
|
2022-06-09 07:37:11 +02:00
|
|
|
#endif
|
2007-03-29 15:25:18 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
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
|
|
|
{
|
2022-06-08 16:42:01 +02:00
|
|
|
FAR struct list_node *mqmsg;
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2022-06-08 16:42:01 +02:00
|
|
|
/* Try to get the message from the generally available free list. */
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2022-06-08 16:42:01 +02:00
|
|
|
mqmsg = list_remove_head(&g_msgfree);
|
|
|
|
if (mqmsg == NULL)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
2022-06-08 16:42:01 +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
|
|
|
|
*/
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2022-06-08 16:42:01 +02:00
|
|
|
if (up_interrupt_context())
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
|
|
|
/* Try the free list reserved for interrupt handlers */
|
|
|
|
|
2022-06-08 16:42:01 +02:00
|
|
|
mqmsg = list_remove_head(&g_msgfreeirq);
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
|
|
|
|
2022-06-08 16:42:01 +02:00
|
|
|
/* We were not called from an interrupt handler. */
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2022-06-08 16:42:01 +02:00
|
|
|
else
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
2022-06-08 16:42:01 +02:00
|
|
|
/* If we cannot a message from the free list, then we will have to
|
|
|
|
* allocate one.
|
|
|
|
*/
|
|
|
|
|
|
|
|
mqmsg = (FAR struct list_node *)
|
2016-09-15 20:42:24 +02:00
|
|
|
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
|
|
|
|
2022-06-08 16:42:01 +02:00
|
|
|
((FAR struct mqueue_msg_s *)mqmsg)->type = MQ_ALLOC_DYN;
|
2016-09-15 20:42:24 +02:00
|
|
|
}
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 16:42:01 +02:00
|
|
|
return (FAR struct mqueue_msg_s *)mqmsg;
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
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:
|
2020-12-22 15:02:48 +01:00
|
|
|
* msgq - Message queue descriptor
|
|
|
|
* oflags - flags from user set
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
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
|
|
|
*
|
2022-06-27 02:04:32 +02:00
|
|
|
* EAGAIN The queue was full and the O_NONBLOCK flag was set for the
|
|
|
|
* message queue description referred to by msgq.
|
|
|
|
* EINTR The call was interrupted by a signal handler.
|
|
|
|
* ETIMEDOUT A timeout expired before the message queue became non-full
|
|
|
|
* (mq_timedsend only).
|
2007-03-29 15:25:18 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-12-22 15:02:48 +01:00
|
|
|
int nxmq_wait_send(FAR struct mqueue_inode_s *msgq, int oflags)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
2013-02-04 19:46:28 +01:00
|
|
|
FAR struct tcb_s *rtcb;
|
2022-11-13 13:39:14 +01:00
|
|
|
bool switch_needed;
|
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
|
|
|
/* Verify that the queue is indeed full as the caller thinks */
|
|
|
|
|
2022-06-08 14:39:03 +02:00
|
|
|
/* Loop until there are fewer than max allowable messages in the
|
|
|
|
* receiving message queue
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (msgq->nmsgs >= msgq->maxmsgs)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
|
|
|
/* Should we block until there is sufficient space in the
|
|
|
|
* message queue?
|
|
|
|
*/
|
|
|
|
|
2020-12-22 15:02:48 +01:00
|
|
|
if ((oflags & O_NONBLOCK) != 0)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
2022-06-08 14:39:03 +02:00
|
|
|
/* Block until the message queue is no longer full.
|
|
|
|
* When we are unblocked, we will try again
|
2007-03-29 15:25:18 +02:00
|
|
|
*/
|
|
|
|
|
2022-09-22 04:31:40 +02:00
|
|
|
rtcb = this_task();
|
|
|
|
rtcb->waitobj = msgq;
|
2022-10-17 09:49:16 +02:00
|
|
|
msgq->cmn.nwaitnotfull++;
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2022-06-08 14:39:03 +02:00
|
|
|
/* Initialize the errcode used to communication wake-up error
|
|
|
|
* conditions.
|
|
|
|
*/
|
2017-10-10 16:43:10 +02:00
|
|
|
|
2022-06-08 14:39:03 +02:00
|
|
|
rtcb->errcode = OK;
|
2017-10-10 16:43:10 +02:00
|
|
|
|
2022-06-08 14:39:03 +02:00
|
|
|
/* Make sure this is not the idle task, descheduling that
|
|
|
|
* isn't going to end well.
|
|
|
|
*/
|
2018-11-30 13:54:15 +01:00
|
|
|
|
2022-10-28 08:22:17 +02:00
|
|
|
DEBUGASSERT(!is_idle_task(rtcb));
|
2022-11-13 13:39:14 +01:00
|
|
|
|
|
|
|
/* Remove the tcb task from the ready-to-run list. */
|
|
|
|
|
|
|
|
switch_needed = nxsched_remove_readytorun(rtcb, true);
|
|
|
|
|
|
|
|
/* Add the task to the specified blocked task list */
|
|
|
|
|
|
|
|
rtcb->task_state = TSTATE_WAIT_MQNOTFULL;
|
|
|
|
nxsched_add_prioritized(rtcb, MQ_WNFLIST(msgq->cmn));
|
|
|
|
|
|
|
|
/* Now, perform the context switch if one is needed */
|
|
|
|
|
|
|
|
if (switch_needed)
|
|
|
|
{
|
2022-11-15 09:52:40 +01:00
|
|
|
up_switch_context(this_task(), rtcb);
|
2022-11-13 13:39:14 +01:00
|
|
|
}
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2022-06-08 14:39:03 +02:00
|
|
|
/* 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
|
2022-06-27 02:04:32 +02:00
|
|
|
* per-task errno value (should be EINTR or ETIMEDOUT).
|
2022-06-08 14:39:03 +02:00
|
|
|
*/
|
2007-03-29 15:25:18 +02:00
|
|
|
|
2022-06-08 14:39:03 +02:00
|
|
|
if (rtcb->errcode != OK)
|
|
|
|
{
|
|
|
|
return -rtcb->errcode;
|
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
|
2020-12-22 15:02:48 +01:00
|
|
|
* message queue (msgq). Then it notifies any tasks that were waiting
|
2017-10-10 16:43:10 +02:00
|
|
|
* 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:
|
2020-12-22 15:02:48 +01:00
|
|
|
* msgq - Message queue descriptor
|
2017-10-10 16:43:10 +02:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-12-22 15:02:48 +01:00
|
|
|
int nxmq_do_send(FAR struct mqueue_inode_s *msgq,
|
|
|
|
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
|
|
|
{
|
2022-06-08 16:42:01 +02:00
|
|
|
FAR struct mqueue_msg_s *prev = NULL;
|
2014-09-29 21:35:32 +02:00
|
|
|
FAR struct mqueue_msg_s *next;
|
2022-06-08 16:42:01 +02:00
|
|
|
FAR struct tcb_s *btcb;
|
2007-03-29 15:25:18 +02:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
2022-06-08 14:39:03 +02:00
|
|
|
/* Insert the new message in the message queue
|
|
|
|
* Search the message list to find the location to insert the new
|
2007-03-29 15:25:18 +02:00
|
|
|
* message. Each is list is maintained in ascending priority order.
|
|
|
|
*/
|
|
|
|
|
2022-06-08 16:42:01 +02:00
|
|
|
list_for_every_entry(&msgq->msglist, next, struct mqueue_msg_s, node)
|
|
|
|
{
|
|
|
|
if (prio > next->priority)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev = next;
|
|
|
|
}
|
|
|
|
}
|
2007-03-29 15:25:18 +02:00
|
|
|
|
|
|
|
/* Add the message at the right place */
|
|
|
|
|
|
|
|
if (prev)
|
|
|
|
{
|
2022-06-08 16:42:01 +02:00
|
|
|
list_add_after(&prev->node, &mqmsg->node);
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-08 16:42:01 +02:00
|
|
|
list_add_head(&msgq->msglist, &mqmsg->node);
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Increment the count of messages in the queue */
|
|
|
|
|
2021-01-08 06:43:33 +01:00
|
|
|
if (msgq->nmsgs++ == 0)
|
|
|
|
{
|
|
|
|
nxmq_pollnotify(msgq, POLLIN);
|
|
|
|
}
|
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
/* Check if we need to notify any tasks that are attached to the
|
|
|
|
* message queue
|
|
|
|
*/
|
|
|
|
|
2022-06-09 09:19:01 +02:00
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE_NOTIFICATION
|
2020-12-22 15:02:48 +01:00
|
|
|
if (msgq->ntpid != INVALID_PROCESS_ID)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
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));
|
2020-12-22 15:02:48 +01:00
|
|
|
msgq->ntpid = INVALID_PROCESS_ID;
|
2015-12-30 20:20:31 +01:00
|
|
|
|
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
|
|
|
}
|
2022-06-09 09:19:01 +02:00
|
|
|
#endif
|
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. */
|
|
|
|
|
2022-10-17 09:49:16 +02:00
|
|
|
if (msgq->cmn.nwaitnotempty > 0)
|
2007-03-29 15:25:18 +02:00
|
|
|
{
|
2022-11-01 02:52:11 +01:00
|
|
|
FAR struct tcb_s *rtcb = this_task();
|
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
/* Find the highest priority task that is waiting for
|
2022-09-09 08:26:43 +02:00
|
|
|
* this queue to be non-empty in waitfornotempty
|
2022-06-08 11:55:39 +02:00
|
|
|
* list. leave_critical_section() should give us sufficient
|
|
|
|
* protection since interrupts should never cause a change
|
|
|
|
* in this list
|
2007-03-29 15:25:18 +02:00
|
|
|
*/
|
|
|
|
|
2022-11-01 02:52:11 +01:00
|
|
|
btcb = (FAR struct tcb_s *)dq_remfirst(MQ_WNELIST(msgq->cmn));
|
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
|
|
|
|
2022-09-06 10:33:58 +02:00
|
|
|
if (WDOG_ISACTIVE(&btcb->waitdog))
|
|
|
|
{
|
|
|
|
wd_cancel(&btcb->waitdog);
|
|
|
|
}
|
|
|
|
|
2022-10-17 09:49:16 +02:00
|
|
|
msgq->cmn.nwaitnotempty--;
|
2022-11-01 02:52:11 +01:00
|
|
|
|
|
|
|
/* Indicate that the wait is over. */
|
|
|
|
|
|
|
|
btcb->waitobj = NULL;
|
|
|
|
|
|
|
|
/* Add the task to ready-to-run task list and
|
|
|
|
* perform the context switch if one is needed
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (nxsched_add_readytorun(btcb))
|
|
|
|
{
|
2022-11-15 09:52:40 +01:00
|
|
|
up_switch_context(btcb, rtcb);
|
2022-11-01 02:52:11 +01:00
|
|
|
}
|
2007-03-29 15:25:18 +02:00
|
|
|
}
|
2012-05-17 18:55:13 +02:00
|
|
|
|
2007-03-29 15:25:18 +02:00
|
|
|
return OK;
|
|
|
|
}
|