From 519ab1856fb8c69ff2bb15e512bdb8539c90129c Mon Sep 17 00:00:00 2001 From: patacongo Date: Tue, 15 May 2012 00:45:14 +0000 Subject: [PATCH] Fix several compiler errors that occur when CONFIG_SCHED_ONEXIT is enabled; on_exit is now used in NxWM::NxConsole to close the window with the NSH session exits git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4738 7fd9a85b-ad96-42d3-883c-3090e2eb8679 --- NxWidgets/ChangeLog.txt | 3 + NxWidgets/nxwm/include/cnxconsole.hxx | 15 ++- NxWidgets/nxwm/include/nxwmconfig.hxx | 11 ++ NxWidgets/nxwm/src/cnxconsole.cxx | 119 ++++++++++++++------- nuttx/ChangeLog | 8 +- nuttx/configs/stm3240g-eval/nxwm/defconfig | 12 ++- nuttx/include/nuttx/sched.h | 2 +- nuttx/include/sched.h | 4 +- nuttx/sched/on_exit.c | 2 +- 9 files changed, 125 insertions(+), 51 deletions(-) diff --git a/NxWidgets/ChangeLog.txt b/NxWidgets/ChangeLog.txt index b6d2cf9f8b..7339242487 100755 --- a/NxWidgets/ChangeLog.txt +++ b/NxWidgets/ChangeLog.txt @@ -84,3 +84,6 @@ or a normal application. This is necessary to prevent CTaskbar from displaying a task bar on top of a full-screen window. * NxWM::CTaskbar: Ooops... minimizing the wrong application! +* NxWM::CNxConsole: Add a on_exit() exit handler that will close the + NxConsole window when the NSH thread exits. A correct build now depends + on having CONFIG_SCHED_ONEXIT defined. diff --git a/NxWidgets/nxwm/include/cnxconsole.hxx b/NxWidgets/nxwm/include/cnxconsole.hxx index 426cf165f6..91fb941d81 100644 --- a/NxWidgets/nxwm/include/cnxconsole.hxx +++ b/NxWidgets/nxwm/include/cnxconsole.hxx @@ -83,13 +83,20 @@ namespace NxWM NXCONSOLE m_nxcon; /**< NxConsole handle */ pid_t m_pid; /**< Task ID of the NxConsole thread */ - /** - * This is the NxConsole task. This function first redirects output to the - * console window. - */ + /** + * This is the NxConsole task. This function first redirects output to the + * console window then calls to start the NSH logic. + */ static int nxconsole(int argc, char *argv[]); + /** + * This is the NxConsole task exit handler. It is registered with on_exit() + * and called automatically when the nxconsole task exits. + */ + + static void exitHandler(int code, FAR void *arg); + /** * Called when the window minimize button is pressed. */ diff --git a/NxWidgets/nxwm/include/nxwmconfig.hxx b/NxWidgets/nxwm/include/nxwmconfig.hxx index 88c2ea8db5..34721d7778 100644 --- a/NxWidgets/nxwm/include/nxwmconfig.hxx +++ b/NxWidgets/nxwm/include/nxwmconfig.hxx @@ -58,6 +58,7 @@ * CONFIG_NX : NX must enabled * CONFIG_NX_MULTIUSER=y : NX must be configured in multiuse mode * CONFIG_NXCONSOLE=y : For NxConsole support + * CONFIG_SCHED_ONEXIT : Support for on_exit() * * General settings: * @@ -90,6 +91,16 @@ # warning "NxConsole support may be needed (CONFIG_NXCONSOLE)" #endif +/** + * on_exit() support is (probably) required. on_exit() is the normal + * mechanism used by NxWM applications to clean-up on a application task + * exit. + */ + +#ifndef CONFIG_SCHED_ONEXIT +# warning "on_exit() support may be needed (CONFIG_SCHED_ONEXIT)" +#endif + /** * Default font ID */ diff --git a/NxWidgets/nxwm/src/cnxconsole.cxx b/NxWidgets/nxwm/src/cnxconsole.cxx index 0d0f8e60eb..79baf67d97 100644 --- a/NxWidgets/nxwm/src/cnxconsole.cxx +++ b/NxWidgets/nxwm/src/cnxconsole.cxx @@ -73,12 +73,14 @@ namespace NxWM struct SNxConsole { - sem_t sem; /**< Sem that posted when the task is initialized */ - NXTKWINDOW hwnd; /**< Window handle */ - NXCONSOLE nxcon; /**< NxConsole handle */ - int minor; /**< Next device minor number */ - struct nxcon_window_s wndo; /**< Describes the NxConsole window */ - bool result; /**< True if successfully initialized */ + FAR void *console; /**< The console 'this' pointer use with on_exit() */ + sem_t exclSem; /**< Sem that gives exclusive access to this structure */ + sem_t waitSem; /**< Sem that posted when the task is initialized */ + NXTKWINDOW hwnd; /**< Window handle */ + NXCONSOLE nxcon; /**< NxConsole handle */ + int minor; /**< Next device minor number */ + struct nxcon_window_s wndo; /**< Describes the NxConsole window */ + bool result; /**< True if successfully initialized */ }; /******************************************************************************************** @@ -200,6 +202,15 @@ bool CNxConsole::run(void) return false; } + // Get exclusive access to the global data structure + + if (sem_wait(&g_nxconvars.exclSem) != 0) + { + // This might fail if a signal is received while we are waiting. + + return false; + } + // Recover the NXTK window instance contained in the application window NXWidgets::INxWindow *window = m_window->getWindow(); @@ -224,8 +235,9 @@ bool CNxConsole::run(void) // Start the NxConsole task - g_nxconvars.result = false; - g_nxconvars.nxcon = 0; + g_nxconvars.console = (FAR void *)this; + g_nxconvars.result = false; + g_nxconvars.nxcon = 0; sched_lock(); m_pid = TASK_CREATE("NxConsole", CONFIG_NXWM_NXCONSOLE_PRIO, @@ -234,34 +246,39 @@ bool CNxConsole::run(void) // Did we successfully start the NxConsole task? + bool result = true; if (m_pid < 0) { - return false; - } - - // Wait for up to two second for the task to initialize - - struct timespec abstime; - clock_gettime(CLOCK_REALTIME, &abstime); - abstime.tv_sec += 2; - - int ret = sem_timedwait(&g_nxconvars.sem, &abstime); - sched_unlock(); - - if (ret == OK && g_nxconvars.result) - { - // Save the handle to use in the stop method - - m_nxcon = g_nxconvars.nxcon; - return true; + result = false; } else { - // Stop the application + // Wait for up to two seconds for the task to initialize - stop(); - return false; + struct timespec abstime; + clock_gettime(CLOCK_REALTIME, &abstime); + abstime.tv_sec += 2; + + int ret = sem_timedwait(&g_nxconvars.waitSem, &abstime); + sched_unlock(); + + if (ret == OK && g_nxconvars.result) + { + // Save the handle to use in the stop method + + m_nxcon = g_nxconvars.nxcon; + } + else + { + // Stop the application + + stop(); + result = false; + } } + + sem_post(&g_nxconvars.exclSem); + return result; } /** @@ -270,7 +287,7 @@ bool CNxConsole::run(void) void CNxConsole::stop(void) { - // Delete the NxConsole task if it is still running (this could strand resources) + // Delete the NxConsole task if it is still running (this could strand resources). if (m_pid >= 0) { @@ -341,7 +358,7 @@ bool CNxConsole::isFullScreen(void) const /** * This is the NxConsole task. This function first redirects output to the - * console window. + * console window then calls to start the NSH logic. */ int CNxConsole::nxconsole(int argc, char *argv[]) @@ -351,6 +368,13 @@ int CNxConsole::nxconsole(int argc, char *argv[]) int fd = -1; + // Set up an on_exit() event that will be called when this task exits + + if (on_exit(exitHandler, g_nxconvars.console) != 0) + { + goto errout; + } + // Use the window handle to create the NX console g_nxconvars.nxcon = nxtk_register(g_nxconvars.hwnd, &g_nxconvars.wndo, @@ -401,7 +425,7 @@ int CNxConsole::nxconsole(int argc, char *argv[]) // Inform the parent thread that we successfully initialized g_nxconvars.result = true; - sem_post(&g_nxconvars.sem); + sem_post(&g_nxconvars.waitSem); // Run the NSH console @@ -409,8 +433,10 @@ int CNxConsole::nxconsole(int argc, char *argv[]) (void)nsh_consolemain(argc, argv); #endif - // We get here if console exits -#warning "Missing logic" + // We get here if the NSH console should exits. nsh_consolemain() ALWAYS + // exits by calling nsh_exit() (which is a pointer to nsh_consoleexit()) + // which, in turn, calls exit() + return EXIT_SUCCESS; errout_with_nxcon: @@ -419,10 +445,30 @@ errout_with_nxcon: errout: g_nxconvars.nxcon = 0; g_nxconvars.result = false; - sem_post(&g_nxconvars.sem); + sem_post(&g_nxconvars.waitSem); return EXIT_FAILURE; } +/** + * This is the NxConsole task exit handler. It registered with on_exit() + * and called automatically when the nxconsole task exits. + */ + +void CNxConsole::exitHandler(int code, FAR void *arg) +{ + CNxConsole *This = (CNxConsole *)arg; + + // Set m_pid to -1 to prevent calling detlete_task() in CNxConsole::stop(). + // CNxConsole::stop() is called by the processing initiated by the following + // call to CTaskbar::stopApplication() + + This->m_pid = -1; + + // Remove the NxConsole application from the taskbar + + This->m_taskbar->stopApplication(This); +} + /** * Called when the window minimize button is pressed. */ @@ -452,7 +498,8 @@ bool NxWM::nshlibInitialize(void) { // Initialize the global data structure - sem_init(&g_nxconvars.sem, 0, 0); + sem_init(&g_nxconvars.exclSem, 0, 1); + sem_init(&g_nxconvars.waitSem, 0, 0); // Initialize the NSH library diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 79e746f6bb..e813076a5f 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -2760,10 +2760,14 @@ window to revert to the previous window. Not good behavior. * sched/sched_mergepending.c: Add task switching instrumentation. There is a case here where instrumentation was missing. Contributed by Petri Tanskanen. - CONFIG_STMPE11_THRESHX, CONFIG_STMPE11_THRESHX, and drivers/stmpe11_tsc.c: Add some + * CONFIG_STMPE11_THRESHX, CONFIG_STMPE11_THRESHX, and drivers/stmpe11_tsc.c: Add some threasholding controls to all slow down processing of touchscreen samples. This is a problem with NX in multi-user mode: touchscreen data gets sent via a message and when the message queue gets full the sender blocks and touch events are lost. Basic data overrun. The badly effects touchscreen human factors. - \ No newline at end of file + * include/sched.h: Fix a typo (missing semicolon) in prototype of on_exit(); + * sched/on_exit.c and include/nuttx/sched.h: Fix some old typos that caused + compilation errors when CONFIG_SCHED_ONEXIT is defined. + * configs/stm3240g-eval/nxwm/defconfig: The default NxWM not uses the STMPE11 + touchscreen. diff --git a/nuttx/configs/stm3240g-eval/nxwm/defconfig b/nuttx/configs/stm3240g-eval/nxwm/defconfig index ca7b242ce0..f31b43b98c 100644 --- a/nuttx/configs/stm3240g-eval/nxwm/defconfig +++ b/nuttx/configs/stm3240g-eval/nxwm/defconfig @@ -139,7 +139,7 @@ CONFIG_STM32_JTAG_SW_ENABLE=n # CONFIG_HEAP2_BASE - The base address of the SRAM in the FSMC address space # CONFIG_HEAP2_END - The end (+1) of the SRAM in the FSMC address space # -CONFIG_STM32_FSMC_SRAM=y +CONFIG_STM32_FSMC_SRAM=n CONFIG_HEAP2_BASE=0x64000000 CONFIG_HEAP2_END=(0x64000000+(2*1024*1024)) @@ -512,6 +512,7 @@ CONFIG_HAVE_LIBM=n # the worker thread. Default: 4 # CONFIG_SCHED_WAITPID - Enable the waitpid() API # CONFIG_SCHED_ATEXIT - Enabled the atexit() API +# CONFIG_SCHED_ONEXIT - Enabled the atexit() API # #CONFIG_APPS_DIR= CONFIG_DEBUG=n @@ -531,7 +532,7 @@ CONFIG_DEBUG_INPUT=n CONFIG_HAVE_CXX=y CONFIG_HAVE_CXXINITIALIZE=y -CONFIG_MM_REGIONS=3 +CONFIG_MM_REGIONS=2 CONFIG_ARCH_LOWPUTC=y CONFIG_RR_INTERVAL=200 CONFIG_SCHED_INSTRUMENTATION=n @@ -557,6 +558,7 @@ CONFIG_SCHED_WORKSTACKSIZE=2048 CONFIG_SIG_SIGWORK=4 CONFIG_SCHED_WAITPID=y CONFIG_SCHED_ATEXIT=n +CONFIG_SCHED_ONEXIT=y # # System Logging @@ -950,7 +952,7 @@ CONFIG_RTC_ALARM=n # # Input device configuration # -CONFIG_INPUT=n +CONFIG_INPUT=y CONFIG_INPUT_TSC2007=n # @@ -998,7 +1000,7 @@ CONFIG_INPUT_TSC2007=n # for example, if your display is 320x240, then THRESHX=13 and THRESHY=17 # would correspond to one pixel. Default: 12 # -CONFIG_INPUT_STMPE11=n +CONFIG_INPUT_STMPE11=y CONFIG_STMPE11_SPI=n CONFIG_STMPE11_I2C=y CONFIG_STMPE11_MULTIPLE=y @@ -1713,7 +1715,7 @@ CONFIG_EXAMPLES_NXLINES_EXTERNINIT=n # collected and the program terminates. Default: Samples are collected # indefinitely. # -CONFIG_EXAMPLES_TOUCHSCREEN_BUILTIN=y +CONFIG_EXAMPLES_TOUCHSCREEN_BUILTIN=n CONFIG_EXAMPLES_TOUCHSCREEN_MINOR=0 CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH="/dev/input0" CONFIG_EXAMPLES_TOUCHSCREEN_NSAMPLES=25 diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h index 6459ec02a6..6d5d0bab7f 100644 --- a/nuttx/include/nuttx/sched.h +++ b/nuttx/include/nuttx/sched.h @@ -142,7 +142,7 @@ typedef void (*atexitfunc_t)(void); #endif #ifdef CONFIG_SCHED_ONEXIT -typedef void (*onexitfunc_t)(int, FAR void *) +typedef void (*onexitfunc_t)(int exitcode, FAR void *arg); #endif /* POSIX Message queue */ diff --git a/nuttx/include/sched.h b/nuttx/include/sched.h index aa1103bde5..94f6a12168 100644 --- a/nuttx/include/sched.h +++ b/nuttx/include/sched.h @@ -147,8 +147,8 @@ EXTERN int sched_lockcount(void); #ifdef CONFIG_SCHED_INSTRUMENTATION -EXTERN void sched_note_start(FAR _TCB *tcb ); -EXTERN void sched_note_stop(FAR _TCB *tcb ); +EXTERN void sched_note_start(FAR _TCB *tcb); +EXTERN void sched_note_stop(FAR _TCB *tcb); EXTERN void sched_note_switch(FAR _TCB *pFromTcb, FAR _TCB *pToTcb); #else diff --git a/nuttx/sched/on_exit.c b/nuttx/sched/on_exit.c index 965a3e805f..f91eb2e11c 100644 --- a/nuttx/sched/on_exit.c +++ b/nuttx/sched/on_exit.c @@ -114,7 +114,7 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg) if (func && !tcb->onexitfunc) { tcb->onexitfunc = func; - tdb->onexitarg = arg; + tcb->onexitarg = arg; ret = OK; }