2008-01-10 20:16:50 +01:00
|
|
|
/****************************************************************************
|
2018-11-08 15:19:17 +01:00
|
|
|
* sched/signal/sig_notification.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-11-08 15:19:17 +01:00
|
|
|
* Copyright (C) 2018 Pinecone Inc. All rights reserved.
|
|
|
|
* Author: Xiang Xiao <xiaoxiang@pinecone.net>
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-11-08 16:41:54 +01:00
|
|
|
* Derives from code originally written by:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
|
|
|
* 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-10 20:16:50 +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-10 20:16:50 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-10 20:16:50 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-01-10 20:16:50 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2009-12-14 19:39:29 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <debug.h>
|
2018-11-08 15:19:17 +01:00
|
|
|
#include <signal.h>
|
2017-10-07 18:57:09 +02:00
|
|
|
|
2019-01-28 00:23:01 +01:00
|
|
|
#include <nuttx/signal.h>
|
|
|
|
|
2014-08-09 01:53:55 +02:00
|
|
|
#include "sched/sched.h"
|
2014-08-08 20:44:44 +02:00
|
|
|
#include "signal/signal.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2019-01-27 16:28:59 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_notification_worker
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform the callback from the context of the worker thread.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* arg - Work argument.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SIG_EVTHREAD
|
|
|
|
static void nxsig_notification_worker(FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct sigwork_s *work = (FAR struct sigwork_s *)arg;
|
|
|
|
|
|
|
|
DEBUGASSERT(work != NULL);
|
|
|
|
|
|
|
|
/* Perform the callback */
|
|
|
|
|
|
|
|
#ifdef CONFIG_CAN_PASS_STRUCTS
|
|
|
|
work->func(work->value);
|
|
|
|
#else
|
|
|
|
work->func(work->value.sival_ptr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_SIG_EVTHREAD */
|
|
|
|
|
2008-01-10 20:16:50 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2008-01-10 20:16:50 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-10 20:16:50 +01:00
|
|
|
/****************************************************************************
|
2018-11-08 15:19:17 +01:00
|
|
|
* Name: nxsig_notification
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2018-11-08 15:19:17 +01:00
|
|
|
* Notify a client an event via either a singal or function call
|
|
|
|
* base on the sigev_notify field.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* pid - The task/thread ID a the client thread to be signaled.
|
|
|
|
* event - The instance of struct sigevent that describes how to signal
|
|
|
|
* the client.
|
|
|
|
* code - Source: SI_USER, SI_QUEUE, SI_TIMER, SI_ASYNCIO, or SI_MESGQ
|
2019-01-27 16:28:59 +01:00
|
|
|
* work - The work structure to queue
|
2018-11-08 15:19:17 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-01-10 20:16:50 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2019-01-27 16:28:59 +01:00
|
|
|
int nxsig_notification(pid_t pid, FAR struct sigevent *event,
|
|
|
|
int code, FAR struct sigwork_s *work)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2018-11-08 15:19:17 +01:00
|
|
|
sinfo("pid=%p signo=%d code=%d sival_ptr=%p\n",
|
2018-11-24 22:07:12 +01:00
|
|
|
pid, event->sigev_signo, code, event->sigev_value.sival_ptr);
|
2018-11-08 15:19:17 +01:00
|
|
|
|
|
|
|
/* Notify client via a signal? */
|
|
|
|
|
|
|
|
if (event->sigev_notify == SIGEV_SIGNAL)
|
|
|
|
{
|
2013-01-12 20:58:45 +01:00
|
|
|
#ifdef CONFIG_SCHED_HAVE_PARENT
|
2018-11-08 15:19:17 +01:00
|
|
|
FAR struct tcb_s *rtcb = this_task();
|
2013-01-12 20:58:45 +01:00
|
|
|
#endif
|
2018-11-08 15:19:17 +01:00
|
|
|
siginfo_t info;
|
|
|
|
|
|
|
|
/* Yes.. Create the siginfo structure */
|
2007-02-21 22:55:16 +01:00
|
|
|
|
2018-11-08 15:19:17 +01:00
|
|
|
info.si_signo = event->sigev_signo;
|
|
|
|
info.si_code = code;
|
|
|
|
info.si_errno = OK;
|
|
|
|
info.si_value = event->sigev_value;
|
|
|
|
#ifdef CONFIG_SCHED_HAVE_PARENT
|
|
|
|
info.si_pid = rtcb->pid;
|
|
|
|
info.si_status = OK;
|
2007-02-21 22:55:16 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-11-08 15:19:17 +01:00
|
|
|
/* Send the signal */
|
2013-02-05 20:50:37 +01:00
|
|
|
|
2018-11-08 15:19:17 +01:00
|
|
|
return nxsig_dispatch(pid, &info);
|
2013-02-05 20:50:37 +01:00
|
|
|
}
|
|
|
|
|
2018-11-08 15:19:17 +01:00
|
|
|
#ifdef CONFIG_SIG_EVTHREAD
|
|
|
|
/* Notify the client via a function call */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-11-08 15:19:17 +01:00
|
|
|
else if (event->sigev_notify == SIGEV_THREAD)
|
|
|
|
{
|
2019-01-27 16:28:59 +01:00
|
|
|
/* Initialize the work information */
|
|
|
|
|
|
|
|
#ifdef CONFIG_CAN_PASS_STRUCTS
|
|
|
|
work->value = event->sigev_value;
|
|
|
|
#else
|
|
|
|
work->value.sival_ptr = event->sigev_value.sival_ptr;
|
|
|
|
#endif
|
|
|
|
work->func = event->sigev_notify_function;
|
|
|
|
|
|
|
|
/* Then queue the work */
|
|
|
|
|
|
|
|
return work_queue(LPWORK, &work->work,
|
|
|
|
nxsig_notification_worker, work, 0);
|
2018-11-08 15:19:17 +01:00
|
|
|
}
|
2013-01-12 20:58:45 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-11-08 15:19:17 +01:00
|
|
|
return event->sigev_notify == SIGEV_NONE ? OK : -ENOSYS;
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2018-11-08 15:19:17 +01:00
|
|
|
|
2019-01-27 16:28:59 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_cancel_notification
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Cancel the notification if it doesn't send yet.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* work - The work structure to cancel
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SIG_EVTHREAD
|
|
|
|
void nxsig_cancel_notification(FAR struct sigwork_s *work)
|
|
|
|
{
|
|
|
|
work_cancel(LPWORK, &work->work);
|
|
|
|
}
|
|
|
|
#endif
|