diff --git a/ChangeLog b/ChangeLog index d0ff108d9e9..de3a448d1b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6349,3 +6349,6 @@ which allocator is used in the different configurations. Always uses the user-space allocator because that one is required in certain configurations (2013-12-30). + * include/nuttx/kthread.h: Move kernel thread definitions out of + os_internal.h so that the rest of the OS can start kernel threads as + well (2013-12-30). diff --git a/graphics/nxmu/nx_start.c b/graphics/nxmu/nx_start.c index a15316d04c3..3b26cc0c56b 100644 --- a/graphics/nxmu/nx_start.c +++ b/graphics/nxmu/nx_start.c @@ -45,6 +45,7 @@ #include #include +#include #include #include "nxfe.h" @@ -72,11 +73,11 @@ ****************************************************************************/ /**************************************************************************** - * Name: nx_servertask + * Name: nx_server * * Description: - * NX server thread. This is the entry point into the server thread that - * serializes the multi-threaded accesses to the display. + * NX server thread. This is the entry point into the server kernel + * thread that serializes the multi-threaded accesses to the display. * * Input Parameters: * Standard task start-up parameters (none of which are used) @@ -87,7 +88,7 @@ * ****************************************************************************/ -int nx_servertask(int argc, char *argv[]) +int nx_server(int argc, char *argv[]) { FAR NX_DRIVERTYPE *dev; int ret; @@ -144,7 +145,7 @@ int nx_servertask(int argc, char *argv[]) #endif /* CONFIG_NX_LCDDRIVER */ - /* Then start the server (nx_run does not normally retun) */ + /* Then start the server (nx_run does not normally return) */ ret = nx_run(dev); gvdbg("nx_run returned: %d\n", errno); @@ -184,24 +185,27 @@ int nx_start(void) { pid_t server; - /* Start the server task */ + /* Start the server kernel thread */ gvdbg("Starting server task\n"); - server = TASK_CREATE("NX Server", CONFIG_NXSTART_SERVERPRIO, - CONFIG_NXSTART_SERVERSTACK, nx_servertask, - (FAR char * const *)0); + server = KERNEL_THREAD("NX Server", CONFIG_NXSTART_SERVERPRIO, + CONFIG_NXSTART_SERVERSTACK, nx_server, + (FAR char * const *)0); if (server < 0) { int errcode = errno; DEBUGASSERT(errcode > 0); - gdbg("ERROR: Failed to create nx_servertask task: %d\n", errcode); + gdbg("ERROR: Failed to create nx_server kernel thread: %d\n", errcode); return -errcode; } - /* Wait a bit to let the server get started */ +#if 0 /* Can't do this on the IDLE thread */ + /* Wait a bit to make sure that the server get started */ usleep(50*1000); +#endif + return OK; } diff --git a/include/nuttx/kthread.h b/include/nuttx/kthread.h new file mode 100644 index 00000000000..7d840915c4f --- /dev/null +++ b/include/nuttx/kthread.h @@ -0,0 +1,108 @@ +/**************************************************************************** + * include/nuttx/kthread.h + * Non-standard, NuttX-specific kernel thread-related declarations. + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_KTHREAD_H +#define __INCLUDE_NUTTX_KTHREAD_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/* One processor family supported by NuttX has a single, fixed hardware stack. + * That is the 8051 family. So for that family only, there is a variant form + * of kernel_thread() that does not take a stack size parameter. The following + * helper macro is provided to work around the ugliness of that exception. + */ + +#ifndef CONFIG_CUSTOM_STACK +# define KERNEL_THREAD(n,p,s,e,a) kernel_thread(n,p,s,e,a) +#else +# define KERNEL_THREAD(n,p,s,e,a) kernel_thread(n,p,e,a) +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/******************************************************************************** + * Name: kernel_thread + * + * Description: + * This function creates and activates a kernel thread task with kernel-mode + * privileges. It is identical to task_create() except that it configures the + * newly started thread to run in kernel model. + * + * Input Parameters: + * (same as task_create()) + * + * Return Value: + * (same as task_create()) + * + ********************************************************************************/ + +#ifndef CONFIG_CUSTOM_STACK +int kernel_thread(FAR const char *name, int priority, int stack_size, + main_t entry, FAR char * const argv[]); +#else +int kernel_thread(FAR const char *name, int priority, main_t entry, + FAR char * const argv[]); +#endif + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_KTHREAD_H */ diff --git a/sched/os_bringup.c b/sched/os_bringup.c index bdaa0e86a31..6a41b4248b2 100644 --- a/sched/os_bringup.c +++ b/sched/os_bringup.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include "os_internal.h" diff --git a/sched/os_internal.h b/sched/os_internal.h index ed5014cdcc1..6073bb39f0b 100644 --- a/sched/os_internal.h +++ b/sched/os_internal.h @@ -69,18 +69,6 @@ #define MAX_TASKS_MASK (CONFIG_MAX_TASKS-1) #define PIDHASH(pid) ((pid) & MAX_TASKS_MASK) -/* One processor family supported by NuttX has a single, fixed hardware stack. - * That is the 8051 family. So for that family only, there is a variant form - * of kernel_thread() that does not take a stack size parameter. The following - * helper macro is provided to work around the ugliness of that exception. - */ - -#ifndef CONFIG_CUSTOM_STACK -# define KERNEL_THREAD(n,p,s,e,a) kernel_thread(n,p,s,e,a) -#else -# define KERNEL_THREAD(n,p,s,e,a) kernel_thread(n,p,e,a) -#endif - /* A more efficient ways to access the errno */ #define SET_ERRNO(e) \ @@ -238,14 +226,6 @@ int task_exit(void); int task_terminate(pid_t pid, bool nonblocking); void task_exithook(FAR struct tcb_s *tcb, int status, bool nonblocking); void task_recover(FAR struct tcb_s *tcb); - -#ifndef CONFIG_CUSTOM_STACK -int kernel_thread(FAR const char *name, int priority, int stack_size, - main_t entry, FAR char * const argv[]); -#else -int kernel_thread(FAR const char *name, int priority, main_t entry, - FAR char * const argv[]); -#endif bool sched_addreadytorun(FAR struct tcb_s *rtrtcb); bool sched_removereadytorun(FAR struct tcb_s *rtrtcb); bool sched_addprioritized(FAR struct tcb_s *newTcb, DSEG dq_queue_t *list); diff --git a/sched/task_create.c b/sched/task_create.c index a2221c5279c..a64b4e21bcb 100644 --- a/sched/task_create.c +++ b/sched/task_create.c @@ -46,6 +46,7 @@ #include #include +#include #include "os_internal.h" #include "group_internal.h"