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
|
|
|
*
|
2020-08-22 18:36:57 +02: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-02-18 00:21:28 +01:00
|
|
|
*
|
2020-08-22 18:36:57 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-11-08 16:41:54 +01:00
|
|
|
*
|
2020-08-22 18:36:57 +02: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-02-18 00:21:28 +01:00
|
|
|
*
|
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>
|
|
|
|
|
2019-06-04 00:53:11 +02:00
|
|
|
#include <string.h>
|
2018-11-08 15:19:17 +01:00
|
|
|
#include <signal.h>
|
2019-06-04 00:53:11 +02:00
|
|
|
#include <debug.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
|
|
|
|
2020-01-13 19:08:45 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-08-26 18:54:49 +02:00
|
|
|
#ifdef CONFIG_SIG_EVTHREAD_HPWORK
|
|
|
|
# define SIG_EVTHREAD_WORK HPWORK
|
|
|
|
#else
|
|
|
|
# define SIG_EVTHREAD_WORK LPWORK
|
|
|
|
#endif
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
work->func(work->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
#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:
|
2019-06-03 16:12:20 +02:00
|
|
|
* Notify a client an event via either a signal or function call
|
2018-11-08 15:19:17 +01:00
|
|
|
* 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-06-03 16:12:20 +02:00
|
|
|
* work - The work structure to queue. Must be non-NULL if
|
2019-06-03 16:20:21 +02:00
|
|
|
* event->sigev_notify == SIGEV_THREAD. Ignored if
|
|
|
|
* CONFIG_SIG_EVTHREAD is not defined.
|
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;
|
|
|
|
#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
|
|
|
|
2019-06-04 00:53:11 +02:00
|
|
|
/* Some compilers (e.g., SDCC), do not permit assignment of aggregates.
|
|
|
|
* Use of memcpy() is overkill; We could just copy the larger of the
|
|
|
|
* nt and FAR void * members in the union. memcpy(), however, does
|
|
|
|
* not require that we know which is larger.
|
|
|
|
*/
|
|
|
|
|
|
|
|
memcpy(&info.si_value, &event->sigev_value, sizeof(union sigval));
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
work->value = event->sigev_value;
|
2020-04-11 19:17:55 +02:00
|
|
|
work->func = event->sigev_notify_function;
|
2019-01-27 16:28:59 +01:00
|
|
|
|
|
|
|
/* Then queue the work */
|
|
|
|
|
2019-08-26 18:54:49 +02:00
|
|
|
return work_queue(SIG_EVTHREAD_WORK, &work->work,
|
2019-01-27 16:28:59 +01:00
|
|
|
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)
|
|
|
|
{
|
2019-08-26 18:54:49 +02:00
|
|
|
work_cancel(SIG_EVTHREAD_WORK, &work->work);
|
2019-01-27 16:28:59 +01:00
|
|
|
}
|
|
|
|
#endif
|