2012-09-04 08:54:09 +08:00
|
|
|
/****************************************************************************
|
2013-03-06 02:57:51 +08:00
|
|
|
* libc/wqueue/work_signal.c
|
2012-09-04 08:54:09 +08:00
|
|
|
*
|
2014-10-10 22:35:58 +08:00
|
|
|
* Copyright (C) 2009-2014 Gregory Nutt. All rights reserved.
|
2012-09-04 08:54:09 +08:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <signal.h>
|
2014-10-11 04:52:04 +08:00
|
|
|
#include <errno.h>
|
2012-09-04 08:54:09 +08:00
|
|
|
|
|
|
|
#include <nuttx/wqueue.h>
|
|
|
|
|
2014-10-10 22:35:58 +08:00
|
|
|
#include "wqueue/wqueue.h"
|
|
|
|
|
2014-10-12 05:59:40 +08:00
|
|
|
#if defined(CONFIG_LIB_USRWORK) && !defined(__KERNEL__)
|
2012-09-04 08:54:09 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Type Declarations
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-10-03 06:30:35 +08:00
|
|
|
* Public Data
|
2012-09-04 08:54:09 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-02-22 08:08:58 +08:00
|
|
|
* Private Data
|
2012-09-04 08:54:09 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: work_signal
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Signal the worker thread to process the work queue now. This function
|
|
|
|
* is used internally by the work logic but could also be used by the
|
|
|
|
* user to force an immediate re-assessment of pending work.
|
|
|
|
*
|
|
|
|
* Input parameters:
|
|
|
|
* qid - The work queue ID
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero on success, a negated errno on failure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int work_signal(int qid)
|
|
|
|
{
|
2014-10-10 22:35:58 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (qid == USRWORK)
|
|
|
|
{
|
|
|
|
/* Signal the worker thread */
|
|
|
|
|
2014-10-11 06:24:50 +08:00
|
|
|
ret = kill(g_usrwork.pid, SIGWORK);
|
2014-10-10 22:35:58 +08:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
2014-10-11 04:52:04 +08:00
|
|
|
ret = -errcode;
|
2014-10-10 22:35:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-11 04:52:04 +08:00
|
|
|
ret = -EINVAL;
|
2014-10-10 22:35:58 +08:00
|
|
|
}
|
2014-10-11 04:52:04 +08:00
|
|
|
|
|
|
|
return ret;
|
2012-09-04 08:54:09 +08:00
|
|
|
}
|
|
|
|
|
2014-10-12 05:59:40 +08:00
|
|
|
#endif /* CONFIG_LIB_USRWORK && !__KERNEL__ */
|