Add a start hook that can be setup to call a function in the context of a new thread before the new threads main() has been called.

git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5571 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2013-01-27 15:52:58 +00:00
parent 47b94bafa5
commit e96d8f046b
17 changed files with 239 additions and 57 deletions
+10
View File
@@ -296,6 +296,16 @@ config SCHED_WAITPID
compliant) and will enable the waitid() and wait() interfaces as
well.
config SCHED_STARTHOOK
bool "Enable startup hook"
default n
---help---
Enable a non-standard, internal OS API call task_starthook().
task_starthook() registers a function that will be called on task
startup before that actual task entry point is called. The
starthook is useful, for example, for setting up automatic
configuration of C++ constructors.
config SCHED_ATEXIT
bool "Enable atexit() API"
default n
+4
View File
@@ -54,6 +54,10 @@ TSK_SRCS += task_posixspawn.c
endif
endif
ifeq ($(CONFIG_SCHED_STARTHOOK),y)
TSK_SRCS += task_starthook.c
endif
SCHED_SRCS = sched_setparam.c sched_setpriority.c sched_getparam.c
SCHED_SRCS += sched_setscheduler.c sched_getscheduler.c
SCHED_SRCS += sched_yield.c sched_rrgetinterval.c sched_foreach.c
+1
View File
@@ -50,6 +50,7 @@
#include <nuttx/net/net.h>
#include "os_internal.h"
#include "group_internal.h"
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0
+2
View File
@@ -46,6 +46,8 @@
#include <nuttx/net/net.h>
#include <nuttx/lib.h>
#include "group_internal.h"
/* Make sure that there are file or socket descriptors in the system and
* that some number of streams have been configured.
*/
+3 -2
View File
@@ -46,6 +46,7 @@
#include <nuttx/net/net.h>
#include "os_internal.h"
#include "group_internal.h"
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0
@@ -159,8 +160,8 @@ static inline void sched_dupsockets(FAR _TCB *tcb)
/* Get pointers to the parent and child task socket lists */
parent = rtcb->group->tg_sockets->sl_sockets;
child = tcb->group->tg_sockets->sl_sockets;
parent = rtcb->group->tg_socketlist.sl_sockets;
child = tcb->group->tg_socketlist.sl_sockets;
/* Check each socket in the parent socket list */
+9
View File
@@ -94,6 +94,15 @@ void task_start(void)
FAR _TCB *tcb = (FAR _TCB*)g_readytorun.head;
int argc;
/* Execute the start hook if one has been registered */
#ifdef CONFIG_SCHED_STARTHOOK
if (tcb->starthook)
{
tcb->starthook(tcb->starthookarg);
}
#endif
/* Count how many non-null arguments we are passing */
for (argc = 1; argc <= CONFIG_MAX_TASK_ARGS; argc++)
+100
View File
@@ -0,0 +1,100 @@
/****************************************************************************
* sched/task_start.c
*
* Copyright (C) 2007-2010 Gregory Nutt. All rights reserved.
* 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 <nuttx/sched.h>
#ifdef CONFIG_SCHED_STARTHOOK
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Private Type Declarations
****************************************************************************/
/****************************************************************************
* Global Variables
****************************************************************************/
/****************************************************************************
* Private Variables
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: task_starthook
*
* Description:
* Configure a start hook... a function that will be called on the thread
* of the new task before the new task's main entry point is called.
* The start hook is useful, for example, for setting up automatic
* configuration of C++ constructors.
*
* Inputs:
* tcb - The new, unstarted task task that needs the start hook
* starthook - The pointer to the start hook function
* arg - The argument to pass to the start hook function.
*
* Return:
* None
*
****************************************************************************/
void task_starthook(FAR _TCB *tcb, starthook_t starthook, FAR void *arg)
{
DEBUGASSERT(tcb);
tcb->starthook = starthook;
tcb->starthookarg = arg;
}
#endif /* CONFIG_SCHED_STARTHOOK */