2011-04-02 01:23:08 +00:00
|
|
|
/****************************************************************************
|
|
|
|
|
* include/nuttx/mqueue.h
|
2007-02-17 23:21:28 +00:00
|
|
|
*
|
2017-10-10 08:43:10 -06:00
|
|
|
* Copyright (C) 2007, 2009, 2011, 2014-2017 Gregory Nutt. All rights
|
|
|
|
|
* reserved.
|
2012-07-17 03:58:11 +00:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-02-17 23:21:28 +00: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.
|
2009-12-14 18:39:29 +00:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-02-17 23:21:28 +00: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.
|
|
|
|
|
*
|
2011-04-02 01:23:08 +00:00
|
|
|
****************************************************************************/
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2011-04-02 01:23:08 +00:00
|
|
|
#ifndef ___INCLUDE_NUTTX_MQUEUE_H
|
|
|
|
|
#define ___INCLUDE_NUTTX_MQUEUE_H
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2007-02-17 23:21:28 +00:00
|
|
|
* Included Files
|
2011-04-02 01:23:08 +00:00
|
|
|
****************************************************************************/
|
2009-12-14 18:39:29 +00:00
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2011-04-02 01:23:08 +00:00
|
|
|
#include <nuttx/compiler.h>
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2011-04-02 01:23:08 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdbool.h>
|
2007-02-17 23:21:28 +00:00
|
|
|
#include <mqueue.h>
|
2011-04-02 01:23:08 +00:00
|
|
|
#include <queue.h>
|
|
|
|
|
#include <signal.h>
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2011-04-02 01:23:08 +00:00
|
|
|
#if CONFIG_MQ_MAXMSGSIZE > 0
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2011-04-02 01:23:08 +00:00
|
|
|
/****************************************************************************
|
2014-09-28 10:15:33 -06:00
|
|
|
* Pre-processor Definitions
|
2011-04-02 01:23:08 +00:00
|
|
|
****************************************************************************/
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2017-10-10 08:43:10 -06:00
|
|
|
/* Most internal nxsig_* interfaces are not available in the user space in
|
|
|
|
|
* PROTECTED and KERNEL builds. In that context, the application signal
|
|
|
|
|
* interfaces must be used. The differences between the two sets of
|
|
|
|
|
* interfaces are: (1) the nxsig_* interfaces do not cause cancellation
|
|
|
|
|
* points and (2) they do not modify the errno variable.
|
|
|
|
|
*
|
|
|
|
|
* This is only important when compiling libraries (libc or libnx) that are
|
|
|
|
|
* used both by the OS (libkc.a and libknx.a) or by the applications
|
|
|
|
|
* (libuc.a and libunx.a). The that case, the correct interface must be
|
|
|
|
|
* used for the build context.
|
|
|
|
|
*
|
|
|
|
|
* The interfaces sigtimedwait(), sigwait(), sigwaitinfo(), sleep(),
|
|
|
|
|
* nanosleep(), and usleep() are cancellation points.
|
|
|
|
|
*
|
|
|
|
|
* REVISIT: The fact that these interfaces are cancellation points is an
|
|
|
|
|
* issue and may cause violations: It use of these internally will cause
|
|
|
|
|
* the calling function to become a cancellation points!
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
|
|
|
|
|
# define _MQ_SEND(d,m,l,p) nxmq_send(d,m,l,p)
|
|
|
|
|
# define _MQ_TIMEDSEND(d,m,l,p,t) nxmq_send(d,m,l,p,t)
|
|
|
|
|
# define _MQ_ERRNO(r) (-(r))
|
|
|
|
|
# define _MQ_ERRVAL(r) (r)
|
|
|
|
|
#else
|
|
|
|
|
# define _MQ_SEND(d,m,l,p) mq_send(d,m,l,p)
|
|
|
|
|
# define _MQ_TIMEDSEND(d,m,l,p,t) mq_send(d,m,l,p,t)
|
|
|
|
|
# define _MQ_ERRNO(r) errno
|
|
|
|
|
# define _MQ_ERRVAL(r) (-errno)
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-04-02 01:23:08 +00:00
|
|
|
/****************************************************************************
|
2015-10-02 16:30:35 -06:00
|
|
|
* Public Type Declarations
|
2011-04-02 01:23:08 +00:00
|
|
|
****************************************************************************/
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2011-04-02 01:23:08 +00:00
|
|
|
/* This structure defines a message queue */
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2011-04-02 01:23:08 +00:00
|
|
|
struct mq_des; /* forward reference */
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2014-09-29 13:19:11 -06:00
|
|
|
struct mqueue_inode_s
|
2007-02-17 23:21:28 +00:00
|
|
|
{
|
2014-09-29 15:33:34 -06:00
|
|
|
FAR struct inode *inode; /* Containing inode */
|
|
|
|
|
sq_queue_t msglist; /* Prioritized message list */
|
|
|
|
|
int16_t maxmsgs; /* Maximum number of messages in the queue */
|
|
|
|
|
int16_t nmsgs; /* Number of message in the queue */
|
|
|
|
|
int16_t nwaitnotfull; /* Number tasks waiting for not full */
|
|
|
|
|
int16_t nwaitnotempty; /* Number tasks waiting for not empty */
|
2014-02-18 14:14:51 -06:00
|
|
|
#if CONFIG_MQ_MAXMSGSIZE < 256
|
2014-09-29 15:33:34 -06:00
|
|
|
uint8_t maxmsgsize; /* Max size of message in message queue */
|
2014-02-18 14:14:51 -06:00
|
|
|
#else
|
2014-09-29 15:33:34 -06:00
|
|
|
uint16_t maxmsgsize; /* Max size of message in message queue */
|
2014-02-18 14:14:51 -06:00
|
|
|
#endif
|
2011-04-02 01:23:08 +00:00
|
|
|
#ifndef CONFIG_DISABLE_SIGNALS
|
|
|
|
|
FAR struct mq_des *ntmqdes; /* Notification: Owning mqdes (NULL if none) */
|
2014-09-29 15:33:34 -06:00
|
|
|
pid_t ntpid; /* Notification: Receiving Task's PID */
|
2015-12-30 13:20:31 -06:00
|
|
|
struct sigevent ntevent; /* Notification description */
|
2011-04-02 01:23:08 +00:00
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* This describes the message queue descriptor that is held in the
|
|
|
|
|
* task's TCB
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
struct mq_des
|
|
|
|
|
{
|
2014-09-29 13:19:11 -06:00
|
|
|
FAR struct mq_des *flink; /* Forward link to next message descriptor */
|
|
|
|
|
FAR struct mqueue_inode_s *msgq; /* Pointer to associated message queue */
|
|
|
|
|
int oflags; /* Flags set when message queue was opened */
|
2011-04-02 01:23:08 +00:00
|
|
|
};
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2011-04-02 01:23:08 +00:00
|
|
|
/****************************************************************************
|
2015-10-02 16:30:35 -06:00
|
|
|
* Public Data
|
2011-04-02 01:23:08 +00:00
|
|
|
****************************************************************************/
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2011-04-02 01:23:08 +00:00
|
|
|
/****************************************************************************
|
2015-10-02 16:30:35 -06:00
|
|
|
* Public Function Prototypes
|
2011-04-02 01:23:08 +00:00
|
|
|
****************************************************************************/
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2011-04-02 01:23:08 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
#define EXTERN extern "C"
|
2014-09-29 14:09:31 -06:00
|
|
|
extern "C"
|
|
|
|
|
{
|
2011-04-02 01:23:08 +00:00
|
|
|
#else
|
|
|
|
|
#define EXTERN extern
|
|
|
|
|
#endif
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2016-04-11 11:14:18 -06:00
|
|
|
struct tcb_s; /* Forward reference */
|
2017-10-10 08:43:10 -06:00
|
|
|
struct mq_attr; /* Forward reference */
|
|
|
|
|
struct timespec; /* Forward reference */
|
2016-04-11 11:14:18 -06:00
|
|
|
struct task_group_s; /* Forward reference */
|
|
|
|
|
|
2015-10-02 17:48:24 -06:00
|
|
|
/****************************************************************************
|
2017-10-10 08:43:10 -06:00
|
|
|
* Name: nxmq_send
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function adds the specified message (msg) to the message queue
|
|
|
|
|
* (mqdes). This is an internal OS interface. It is functionally
|
|
|
|
|
* equivalent to mq_send() except that:
|
|
|
|
|
*
|
|
|
|
|
* - It is not a cancellaction point, and
|
|
|
|
|
* - It does not modify the errno value.
|
|
|
|
|
*
|
|
|
|
|
* See comments with mq_send() for a more complete description of the
|
|
|
|
|
* behavior of this function
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* mqdes - Message queue descriptor
|
|
|
|
|
* msg - Message to send
|
|
|
|
|
* msglen - The length of the message in bytes
|
|
|
|
|
* prio - The priority of the message
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* This is an internal OS interface and should not be used by applications.
|
|
|
|
|
* It follows the NuttX internal error return policy: Zero (OK) is
|
|
|
|
|
* returned on success. A negated errno value is returned on failure.
|
|
|
|
|
* (see mq_send() for the list list valid return values).
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int nxmq_send(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio);
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxmq_timedsend
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function adds the specified message (msg) to the message queue
|
|
|
|
|
* (mqdes). nxmq_timedsend() behaves just like mq_send(), except that if
|
|
|
|
|
* the queue is full and the O_NONBLOCK flag is not enabled for the
|
|
|
|
|
* message queue description, then abstime points to a structure which
|
|
|
|
|
* specifies a ceiling on the time for which the call will block.
|
|
|
|
|
*
|
|
|
|
|
* nxmq_timedsend() is functionally equivalent to mq_timedsend() except
|
|
|
|
|
* that:
|
|
|
|
|
*
|
|
|
|
|
* - It is not a cancellaction point, and
|
|
|
|
|
* - It does not modify the errno value.
|
|
|
|
|
*
|
|
|
|
|
* See comments with mq_timedsend() for a more complete description of the
|
|
|
|
|
* behavior of this function
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* mqdes - Message queue descriptor
|
|
|
|
|
* msg - Message to send
|
|
|
|
|
* msglen - The length of the message in bytes
|
|
|
|
|
* prio - The priority of the message
|
|
|
|
|
* abstime - the absolute time to wait until a timeout is decleared
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* This is an internal OS interface and should not be used by applications.
|
|
|
|
|
* It follows the NuttX internal error return policy: Zero (OK) is
|
|
|
|
|
* returned on success. A negated errno value is returned on failure.
|
|
|
|
|
* (see mq_timedsend() for the list list valid return values).
|
|
|
|
|
*
|
|
|
|
|
* EAGAIN The queue was empty, and the O_NONBLOCK flag was set for the
|
|
|
|
|
* message queue description referred to by mqdes.
|
|
|
|
|
* 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.
|
|
|
|
|
* EINTR The call was interrupted by a signal handler.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int nxmq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio,
|
|
|
|
|
FAR const struct timespec *abstime);
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxmq_free_msgq
|
2014-09-29 14:09:31 -06:00
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function deallocates an initialized message queue structure.
|
|
|
|
|
* First, it deallocates all of the queued messages in the message
|
|
|
|
|
* queue. It is assumed that this message is fully unlinked and
|
|
|
|
|
* closed so that no thread will attempt access it while it is being
|
|
|
|
|
* deleted.
|
|
|
|
|
*
|
|
|
|
|
* Inputs:
|
|
|
|
|
* msgq - Named essage queue to be freed
|
|
|
|
|
*
|
|
|
|
|
* Return Value:
|
|
|
|
|
* None
|
|
|
|
|
*
|
2015-10-02 17:48:24 -06:00
|
|
|
****************************************************************************/
|
2014-09-29 14:09:31 -06:00
|
|
|
|
2017-10-10 08:43:10 -06:00
|
|
|
void nxmq_free_msgq(FAR struct mqueue_inode_s *msgq);
|
2014-09-29 14:09:31 -06:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-10-10 08:43:10 -06:00
|
|
|
* Name: nxmq_alloc_msgq
|
2014-09-29 14:09:31 -06:00
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function implements a part of the POSIX message queue open logic.
|
|
|
|
|
* It allocates and initializes a structu mqueue_inode_s structure.
|
|
|
|
|
*
|
|
|
|
|
* Parameters:
|
|
|
|
|
* mode - mode_t value is ignored
|
|
|
|
|
* attr - The mq_maxmsg attribute is used at the time that the message
|
|
|
|
|
* queue is created to determine the maximum number of
|
|
|
|
|
* messages that may be placed in the message queue.
|
|
|
|
|
*
|
|
|
|
|
* Return Value:
|
|
|
|
|
* The allocated and initalized message queue structure or NULL in the
|
|
|
|
|
* event of a failure.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2017-10-10 08:43:10 -06:00
|
|
|
FAR struct mqueue_inode_s *nxmq_alloc_msgq(mode_t mode,
|
|
|
|
|
FAR struct mq_attr *attr);
|
2014-09-29 14:09:31 -06:00
|
|
|
|
2014-09-29 14:59:31 -06:00
|
|
|
/****************************************************************************
|
2017-10-10 08:43:10 -06:00
|
|
|
* Name: nxmq_create_des
|
2014-09-29 14:59:31 -06:00
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Create a message queue descriptor for the specified TCB
|
|
|
|
|
*
|
|
|
|
|
* Inputs:
|
|
|
|
|
* TCB - task that needs the descriptor.
|
|
|
|
|
* msgq - Named message queue containing the message
|
|
|
|
|
* oflags - access rights for the descriptor
|
|
|
|
|
*
|
|
|
|
|
* Return Value:
|
|
|
|
|
* On success, the message queue descriptor is returned. NULL is returned
|
|
|
|
|
* on a failure to allocate.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2017-10-10 08:43:10 -06:00
|
|
|
mqd_t nxmq_create_des(FAR struct tcb_s *mtcb,
|
|
|
|
|
FAR struct mqueue_inode_s *msgq, int oflags);
|
2014-09-29 14:59:31 -06:00
|
|
|
|
2014-09-29 15:33:34 -06:00
|
|
|
/****************************************************************************
|
2017-10-10 08:43:10 -06:00
|
|
|
* Name: nxmq_close_group
|
2016-04-11 11:14:18 -06:00
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function is used to indicate that all threads in the group are
|
2017-10-10 08:43:10 -06:00
|
|
|
* finished with the specified message queue mqdes. nxmq_close_group()
|
2016-04-11 11:14:18 -06:00
|
|
|
* deallocates any system resources allocated by the system for use by
|
|
|
|
|
* this task for its message queue.
|
|
|
|
|
*
|
|
|
|
|
* Parameters:
|
|
|
|
|
* mqdes - Message queue descriptor.
|
|
|
|
|
* group - Group that has the open descriptor.
|
|
|
|
|
*
|
|
|
|
|
* Return Value:
|
2017-10-10 08:43:10 -06:00
|
|
|
* Zero (OK) if the message queue is closed successfully. Otherwise, a
|
|
|
|
|
* negated errno value is returned.
|
2016-04-11 11:14:18 -06:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2017-10-10 08:43:10 -06:00
|
|
|
int nxmq_close_group(mqd_t mqdes, FAR struct task_group_s *group);
|
2016-04-11 11:14:18 -06:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-10-10 08:43:10 -06:00
|
|
|
* Name: nxmq_desclose_group
|
2014-09-29 15:33:34 -06:00
|
|
|
*
|
|
|
|
|
* Description:
|
2014-09-30 08:03:39 -06:00
|
|
|
* This function performs the portion of the mq_close operation related
|
|
|
|
|
* to freeing resource used by the message queue descriptor itself.
|
2014-09-29 15:33:34 -06:00
|
|
|
*
|
2014-09-30 08:03:39 -06:00
|
|
|
* Parameters:
|
|
|
|
|
* mqdes - Message queue descriptor.
|
2016-04-11 11:14:18 -06:00
|
|
|
* group - Group that has the open descriptor.
|
2014-09-30 08:03:39 -06:00
|
|
|
*
|
|
|
|
|
* Return Value:
|
2016-04-11 11:14:18 -06:00
|
|
|
* None.
|
2014-09-30 08:03:39 -06:00
|
|
|
*
|
|
|
|
|
* Assumptions:
|
|
|
|
|
* - Called only from mq_close() with the scheduler locked.
|
2014-09-29 15:33:34 -06:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2017-10-10 08:43:10 -06:00
|
|
|
void nxmq_desclose_group(mqd_t mqdes, FAR struct task_group_s *group);
|
2014-09-29 15:33:34 -06:00
|
|
|
|
2011-04-02 01:23:08 +00:00
|
|
|
#undef EXTERN
|
|
|
|
|
#ifdef __cplusplus
|
2007-02-17 23:21:28 +00:00
|
|
|
}
|
2011-04-02 01:23:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif /* CONFIG_MQ_MAXMSGSIZE > 0 */
|
|
|
|
|
#endif /* ___INCLUDE_NUTTX_MQUEUE_H */
|
|
|
|
|
|