diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 1c1c257c3..0eb1ede42 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -2981,7 +2981,12 @@ * configs/lpc4330-xplorer/up_nsh.c: Add support for a basic SPIFI block driver for use by NSH. Does not work! Crashes on first SPIFI write. - * configs/lpc4330-xplorer/*/defconfig: Calibrate delay loops (this is - based on the current "slow" 72MHz M4 clock and will need to be - re-calibrated when this is increased). - + * configs/stm3220g-eval/include/board.h and configs/stm3240g-eval/include/board.h: + The SDIOCLK frequency in the F2 and F4 derives for PLL48CLK and not HCLK + so that the SDIOCLK input frequency should always be 48MHz. + * sched/os_internal.h, sched_setupidlefiles.c, sched_setuptaskfiles.c, and + sched_setupidlefiles.c: Detangle some conditional compilation. Allow for + a perverse configuration that has socket descriptors and streams but no file + descriptors (sure, why not?). + * sched/: Stylistic clean-up of all files. Some of these files are pretty old + and do not follow current NuttX coding standards in detail. diff --git a/nuttx/configs/stm3220g-eval/include/board.h b/nuttx/configs/stm3220g-eval/include/board.h index bd0a059f7..be9bb886d 100644 --- a/nuttx/configs/stm3220g-eval/include/board.h +++ b/nuttx/configs/stm3220g-eval/include/board.h @@ -34,17 +34,19 @@ * ************************************************************************************/ -#ifndef __ARCH_BOARD_BOARD_H -#define __ARCH_BOARD_BOARD_H +#ifndef __CONFIGS_STM3220G_EVAL_INCLUDE_BOARD_H +#define __CONFIGS_STM3220G_EVAL_INCLUDE_BOARD_H /************************************************************************************ * Included Files ************************************************************************************/ #include + #ifndef __ASSEMBLY__ # include #endif + #include "stm32_rcc.h" #include "stm32_sdio.h" #include "stm32_internal.h" @@ -168,29 +170,29 @@ * to service FIFOs in interrupt driven mode. These values have not been * tuned!!! * - * HCLK=72MHz, SDIOCLK=72MHz, SDIO_CK=HCLK/(178+2)=400 KHz + * SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(118+2)=400 KHz */ -#define SDIO_INIT_CLKDIV (178 << SDIO_CLKCR_CLKDIV_SHIFT) +#define SDIO_INIT_CLKDIV (118 << SDIO_CLKCR_CLKDIV_SHIFT) -/* DMA ON: HCLK=72 MHz, SDIOCLK=72MHz, SDIO_CK=HCLK/(2+2)=18 MHz - * DMA OFF: HCLK=72 MHz, SDIOCLK=72MHz, SDIO_CK=HCLK/(3+2)=14.4 MHz +/* DMA ON: SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(1+2)=16 MHz + * DMA OFF: SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(2+2)=12 MHz */ #ifdef CONFIG_SDIO_DMA -# define SDIO_MMCXFR_CLKDIV (2 << SDIO_CLKCR_CLKDIV_SHIFT) +# define SDIO_MMCXFR_CLKDIV (1 << SDIO_CLKCR_CLKDIV_SHIFT) #else -# define SDIO_MMCXFR_CLKDIV (3 << SDIO_CLKCR_CLKDIV_SHIFT) +# define SDIO_MMCXFR_CLKDIV (2 << SDIO_CLKCR_CLKDIV_SHIFT) #endif -/* DMA ON: HCLK=72 MHz, SDIOCLK=72MHz, SDIO_CK=HCLK/(1+2)=24 MHz - * DMA OFF: HCLK=72 MHz, SDIOCLK=72MHz, SDIO_CK=HCLK/(3+2)=14.4 MHz +/* DMA ON: SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(0+2)= 24 MHz + * DMA OFF: SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(2+2)= 12 MHz */ #ifdef CONFIG_SDIO_DMA -# define SDIO_SDXFR_CLKDIV (1 << SDIO_CLKCR_CLKDIV_SHIFT) +# define SDIO_SDXFR_CLKDIV (0 << SDIO_CLKCR_CLKDIV_SHIFT) #else -# define SDIO_SDXFR_CLKDIV (3 << SDIO_CLKCR_CLKDIV_SHIFT) +# define SDIO_SDXFR_CLKDIV (2 << SDIO_CLKCR_CLKDIV_SHIFT) #endif /* Ethernet *************************************************************************/ @@ -531,4 +533,4 @@ EXTERN void stm3220g_lcdclear(uint16_t color); #endif #endif /* __ASSEMBLY__ */ -#endif /* __ARCH_BOARD_BOARD_H */ +#endif /* __CONFIGS_STM3220G_EVAL_INCLUDE_BOARD_H */ diff --git a/nuttx/configs/stm3220g-eval/nsh/defconfig b/nuttx/configs/stm3220g-eval/nsh/defconfig index 6643057d7..6513d2ca1 100644 --- a/nuttx/configs/stm3220g-eval/nsh/defconfig +++ b/nuttx/configs/stm3220g-eval/nsh/defconfig @@ -518,8 +518,8 @@ CONFIG_DEBUG_I2C=n CONFIG_DEBUG_INPUT=n CONFIG_DEBUG_DMA=n -CONFIG_HAVE_CXX=n -CONFIG_HAVE_CXXINITIALIZE=n +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y CONFIG_MM_REGIONS=1 CONFIG_ARCH_LOWPUTC=y CONFIG_RR_INTERVAL=200 @@ -813,7 +813,6 @@ CONFIG_MMCSD_MULTIBLOCK_DISABLE=y CONFIG_MMCSD_MMCSUPPORT=n CONFIG_MMCSD_HAVECARDDETECT=n - # # TCP/IP and UDP support via uIP # @@ -1342,8 +1341,8 @@ CONFIG_STM32_ILI9325_DISABLE=n # # Settings for examples/uip # -CONFIG_EXAMPLE_UIP_IPADDR==(192<<24|168<<16|21<<8|15) -CONFIG_EXAMPLE_UIP_DRIPADDR=(192<<24|168<<16|21<<8|10) +CONFIG_EXAMPLE_UIP_IPADDR=(10<<24|0<<16|0<<8|2) +CONFIG_EXAMPLE_UIP_DRIPADDR=(10<<24|0<<16|0<<8|1) CONFIG_EXAMPLE_UIP_NETMASK=(255<<24|255<<16|255<<8|0) CONFIG_EXAMPLE_UIP_DHCPC=n @@ -1352,10 +1351,10 @@ CONFIG_EXAMPLE_UIP_DHCPC=n CONFIG_EXAMPLE_NETTEST_SERVER=n CONFIG_EXAMPLE_NETTEST_PERFORMANCE=n CONFIG_EXAMPLE_NETTEST_NOMAC=y -CONFIG_EXAMPLE_NETTEST_IPADDR==(192<<24|168<<16|21<<8|15) -CONFIG_EXAMPLE_NETTEST_DRIPADDR=(192<<24|168<<16|21<<8|10) +CONFIG_EXAMPLE_NETTEST_IPADDR=(10<<24|0<<16|0<<8|2) +CONFIG_EXAMPLE_NETTEST_DRIPADDR=(10<<24|0<<16|0<<8|1) CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0) -CONFIG_EXAMPLE_NETTEST_CLIENTIP=(192<<24|168<<16|21<<8|10) +CONFIG_EXAMPLE_NETTEST_CLIENTIP=(10<<24|0<<16|0<<8|1) # # Settings for examples/ostest @@ -1410,12 +1409,12 @@ CONFIG_NSH_DISABLEBG=n CONFIG_NSH_ROMFSETC=n CONFIG_NSH_CONSOLE=y CONFIG_NSH_TELNET=y -CONFIG_NSH_ARCHINIT=n +CONFIG_NSH_ARCHINIT=y CONFIG_NSH_IOBUFFER_SIZE=512 CONFIG_NSH_DHCPC=n CONFIG_NSH_NOMAC=y -CONFIG_NSH_IPADDR=(192<<24|168<<16|13<<8|161) -CONFIG_NSH_DRIPADDR=(192<<24|168<<16|13<<8|1) +CONFIG_NSH_IPADDR=(10<<24|0<<16|0<<8|2) +CONFIG_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1) CONFIG_NSH_NETMASK=(255<<24|255<<16|255<<8|0) CONFIG_NSH_ROMFSMOUNTPT="/etc" CONFIG_NSH_INITSCRIPT="init.d/rcS" diff --git a/nuttx/configs/stm3220g-eval/nsh2/appconfig b/nuttx/configs/stm3220g-eval/nsh2/appconfig index 35d687884..23d9167fa 100644 --- a/nuttx/configs/stm3220g-eval/nsh2/appconfig +++ b/nuttx/configs/stm3220g-eval/nsh2/appconfig @@ -80,6 +80,10 @@ ifeq ($(CONFIG_WATCHDOG),y) CONFIGURED_APPS += examples/watchdog endif +ifeq ($(CONFIG_INPUT_STMPE811),y) +CONFIGURED_APPS += examples/touchscreen +endif + # Uncomment examples/ftpc to include the FTP client example # Uncomment examples/ftpd to include the FTP daemon example @@ -87,3 +91,12 @@ ifeq ($(CONFIG_NET),y) #CONFIGURED_APPS += examples/ftpc #CONFIGURED_APPS += examples/ftpd endif + +# Uncomment to select a graphics example + +ifeq ($(CONFIG_NX),y) +#CONFIGURED_APPS += examples/nx +#CONFIGURED_APPS += examples/nxhello +#CONFIGURED_APPS += examples/nximage +#CONFIGURED_APPS += examples/nxlines +endif diff --git a/nuttx/configs/stm3220g-eval/nsh2/defconfig b/nuttx/configs/stm3220g-eval/nsh2/defconfig index 6ea3f18a0..11233ffb4 100644 --- a/nuttx/configs/stm3220g-eval/nsh2/defconfig +++ b/nuttx/configs/stm3220g-eval/nsh2/defconfig @@ -334,7 +334,7 @@ CONFIG_STM32_MII_MCO2=n CONFIG_STM32_RMII=n CONFIG_STM32_AUTONEG=y #CONFIG_STM32_ETHFD -#CONFIG_STM32_ETH100MB +#CONFIG_STM32_ETH100MBPS CONFIG_STM32_PHYSR=16 CONFIG_STM32_PHYSR_SPEED=0x0002 CONFIG_STM32_PHYSR_100MBPS=0x0000 @@ -517,6 +517,7 @@ CONFIG_DEBUG_PWM=n CONFIG_DEBUG_CAN=n CONFIG_DEBUG_I2C=n CONFIG_DEBUG_DMA=n + CONFIG_HAVE_CXX=y CONFIG_HAVE_CXXINITIALIZE=y CONFIG_MM_REGIONS=1 @@ -529,7 +530,7 @@ CONFIG_START_MONTH=12 CONFIG_START_DAY=6 CONFIG_GREGORIAN_TIME=n CONFIG_JULIAN_TIME=n -CONFIG_DEV_CONSOLE=y +CONFIG_DEV_CONSOLE=n CONFIG_DEV_LOWCONSOLE=n CONFIG_MUTEX_TYPES=n CONFIG_PRIORITY_INHERITANCE=n @@ -541,7 +542,7 @@ CONFIG_SDCLONE_DISABLE=y CONFIG_SCHED_WORKQUEUE=y CONFIG_SCHED_WORKPRIORITY=192 CONFIG_SCHED_WORKPERIOD=(50*1000) -CONFIG_SCHED_WORKSTACKSIZE=1024 +CONFIG_SCHED_WORKSTACKSIZE=2048 CONFIG_SIG_SIGWORK=4 CONFIG_SCHED_WAITPID=y CONFIG_SCHED_ATEXIT=n @@ -935,6 +936,74 @@ CONFIG_RTC_HIRES=n CONFIG_RTC_FREQUENCY=n CONFIG_RTC_ALARM=n +# +# Input device configuration +# +CONFIG_INPUT=n +CONFIG_INPUT_TSC2007=n + +# +# STMPE811 input device configuration +# +# Prerequisites: CONFIG_INPUT=y +# Other settings that effect the driver: CONFIG_DISABLE_POLL +# +# CONFIG_INPUT_STMPE811 +# Enables support for the STMPE811 driver (Needs CONFIG_INPUT) +# CONFIG_STMPE811_SPI +# Enables support for the SPI interface (not currenly supported) +# CONFIG_STMPE811_I2C +# Enables support for the I2C interface +# CONFIG_STMPE811_MULTIPLE +# Can be defined to support multiple STMPE811 devices on board. +# CONFIG_STMPE811_ACTIVELOW +# Interrupt is generated by an active low signal (or falling edge). +# CONFIG_STMPE811_EDGE +# Interrupt is generated on an edge (vs. on the active level) +# CONFIG_STMPE811_NPOLLWAITERS +# Maximum number of threads that can be waiting on poll() (ignored if +# CONFIG_DISABLE_POLL is set). +# CONFIG_STMPE811_TSC_DISABLE +# Disable driver touchscreen functionality. +# CONFIG_STMPE811_ADC_DISABLE +# Disable driver ADC functionality. +# CONFIG_STMPE811_GPIO_DISABLE +# Disable driver GPIO functionality. +# CONFIG_STMPE811_GPIOINT_DISABLE +# Disable driver GPIO interrupt functionality (ignored if GPIO functionality is +# disabled). +# CONFIG_STMPE811_SWAPXY +# Reverse the meaning of X and Y to handle different LCD orientations. +# For the STM3220G-EVAL, X and Y should be swapped in PORTRAIT modes +# CONFIG_STMPE811_TEMP_DISABLE +# Disable driver temperature sensor functionality. +# CONFIG_STMPE811_REGDBUG +# Enabled very low register-level debug output. Requires CONFIG_DEBUG. +# CONFIG_STMPE811_THRESHX and CONFIG_STMPE811_THRESHY +# STMPE811 touchscreen data comes in a a very high rate. New touch positions +# will only be reported when the X or Y data changes by these thresholds. +# This trades reduces data rate for some loss in dragging accuracy. The +# STMPE811 is configure for 12-bit values so the raw ranges are 0-4095. So +# for example, if your display is 320x240, then THRESHX=13 and THRESHY=17 +# would correspond to one pixel. Default: 12 +# +CONFIG_INPUT_STMPE811=n +CONFIG_STMPE811_SPI=n +CONFIG_STMPE811_I2C=y +CONFIG_STMPE811_MULTIPLE=y +CONFIG_STMPE811_ACTIVELOW=y +CONFIG_STMPE811_EDGE=y +#CONFIG_STMPE811_NPOLLWAITERS +CONFIG_STMPE811_TSC_DISABLE=n +CONFIG_STMPE811_ADC_DISABLE=y +CONFIG_STMPE811_GPIO_DISABLE=y +CONFIG_STMPE811_GPIOINT_DISABLE=y +CONFIG_STMPE811_SWAPXY=y +CONFIG_STMPE811_TEMP_DISABLE=y +CONFIG_STMPE811_REGDEBUG=n +CONFIG_STMPE811_THRESHX=26 +CONFIG_STMPE811_THRESHY=34 + # # USB Device Configuration # @@ -1082,11 +1151,11 @@ CONFIG_WATCHDOG=n # CONFIG_NXTK_BORDERWIDTH # Specifies with with of the border (in pixels) used with # framed windows. The default is 4. -# CONFIG_NXTK_BORDERCOLOR1 and CONFIG_NXTK_BORDERCOLOR2 +# CONFIG_NXTK_BORDERCOLOR1, CONFIG_NXTK_BORDERCOLOR2, CONFIG_NXTK_BORDERCOLOR3 # Specify the colors of the border used with framed windows. -# CONFIG_NXTK_BORDERCOLOR2 is the shadow side color and so -# is normally darker. The default is medium and dark grey, -# respectively +# CONFIG_NXTK_BORDERCOLOR2 is the shadow side color and so is normally darker. +# CONFIG_NXTK_BORDERCOLOR3 is the shiny side color and so is normally brighter. +# The default is mediumdark grey, and light grey, respectively # CONFIG_NXTK_AUTORAISE # If set, a window will be raised to the top if the mouse position # is over a visible portion of the window. Default: A mouse @@ -1199,11 +1268,81 @@ CONFIG_NX_BLOCKING=y CONFIG_NX_MXSERVERMSGS=32 CONFIG_NX_MXCLIENTMSGS=16 +# +# NxConsole Configuration Settings: +# +# CONFIG_NXCONSOLE +# Enables building of the NxConsole driver. +# CONFIG_NXCONSOLE_BPP +# Currently, NxConsole supports only a single pixel depth. This +# configuration setting must be provided to support that single pixel depth. +# Default: The smallest enabled pixel depth. (see CONFIG_NX_DISABLE_*BPP) +# CONFIG_NXCONSOLE_MXCHARS +# NxConsole needs to remember every character written to the console so +# that it can redraw the window. This setting determines the size of some +# internal memory allocations used to hold the character data. Default: 128. +# CONFIG_NXCONSOLE_CACHESIZE +# NxConsole supports caching of rendered fonts. This font caching is required +# for two reasons: (1) First, it improves text performance, but more +# importantly (2) it preserves the font memory. Since the NX server runs on +# a separate server thread, it requires that the rendered font memory persist +# until the server has a chance to render the font. (NOTE: There is still +# inherently a race condition in this!). Unfortunately, the font cache would +# be quite large if all fonts were saved. The CONFIG_NXCONSOLE_CACHESIZE setting +# will control the size of the font cache (in number of glyphs). Only that +# number of the most recently used glyphs will be retained. Default: 16. +# CONFIG_NXCONSOLE_LINESEPARATION +# This the space (in rows) between each row of test. Default: 2 +# CONFIG_NXCONSOLE_NOWRAP +# By default, lines will wrap when the test reaches the right hand side +# of the window. This setting can be defining to change this behavior so +# that the text is simply truncated until a new line is encountered. +# +CONFIG_NXCONSOLE=n +CONFIG_NXCONSOLE_BPP=16 +CONFIG_NXCONSOLE_MXCHARS=256 +CONFIG_NXCONSOLE_CACHESIZE=32 +# CONFIG_NXCONSOLE_LINESEPARATION +# CONFIG_NXCONSOLE_NOWRAP + +# +# STM3220G-EVAL LCD Hardware Configuration +# +# CONFIG_LCD_NOGETRUN +# NX components need to know if it can read from the LCD or not. If reading +# from the LCD is supported, then NxConsole can do more efficient +# scrolling. Default: Supported +# CONFIG_LCD_LANDSCAPE - Define for 320x240 display "landscape" +# support. Default is this 320x240 "landscape" orientation +# CONFIG_LCD_RLANDSCAPE - Define for 320x240 display "reverse +# landscape" support. Default is this 320x240 "landscape" +# orientation +# CONFIG_LCD_PORTRAIT - Define for 240x320 display "portrait" +# orientation support. In this orientation, the STM3220G-EVAL's +# LCD ribbon cable is at the bottom of the display. Default is +# 320x240 "landscape" orientation. +# CONFIG_LCD_RPORTRAIT - Define for 240x320 display "reverse +# portrait" orientation support. In this orientation, the +# STM3220G-EVAL's LCD ribbon cable is at the top of the display. +# Default is 320x240 "landscape" orientation. +# +CONFIG_LCD_NOGETRUN=y +CONFIG_LCD_LANDSCAPE=n +CONFIG_LCD_RLANDSCAPE=n +CONFIG_LCD_PORTRAIT=n +CONFIG_LCD_RPORTRAIT=y + +# +# STM3220G-EVAL specific LCD settings +# +CONFIG_STM32_ILI9320_DISABLE=n +CONFIG_STM32_ILI9325_DISABLE=n + # # Settings for examples/uip # -CONFIG_EXAMPLE_UIP_IPADDR==(192<<24|168<<16|21<<8|15) -CONFIG_EXAMPLE_UIP_DRIPADDR=(192<<24|168<<16|21<<8|10) +CONFIG_EXAMPLE_UIP_IPADDR=(10<<24|0<<16|0<<8|2) +CONFIG_EXAMPLE_UIP_DRIPADDR=(10<<24|0<<16|0<<8|1) CONFIG_EXAMPLE_UIP_NETMASK=(255<<24|255<<16|255<<8|0) CONFIG_EXAMPLE_UIP_DHCPC=n @@ -1212,10 +1351,10 @@ CONFIG_EXAMPLE_UIP_DHCPC=n CONFIG_EXAMPLE_NETTEST_SERVER=n CONFIG_EXAMPLE_NETTEST_PERFORMANCE=n CONFIG_EXAMPLE_NETTEST_NOMAC=y -CONFIG_EXAMPLE_NETTEST_IPADDR==(192<<24|168<<16|21<<8|15) -CONFIG_EXAMPLE_NETTEST_DRIPADDR=(192<<24|168<<16|21<<8|10) +CONFIG_EXAMPLE_NETTEST_IPADDR=(10<<24|0<<16|0<<8|2) +CONFIG_EXAMPLE_NETTEST_DRIPADDR=((10<<24|0<<16|0<<8|1) CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0) -CONFIG_EXAMPLE_NETTEST_CLIENTIP=(192<<24|168<<16|21<<8|10) +CONFIG_EXAMPLE_NETTEST_CLIENTIP=(10<<24|0<<16|0<<8|1) # # Settings for examples/ostest @@ -1268,14 +1407,14 @@ CONFIG_NSH_NESTDEPTH=3 CONFIG_NSH_DISABLESCRIPT=n CONFIG_NSH_DISABLEBG=n CONFIG_NSH_ROMFSETC=n -CONFIG_NSH_CONSOLE=y +CONFIG_NSH_CONSOLE=n CONFIG_NSH_TELNET=y CONFIG_NSH_ARCHINIT=y CONFIG_NSH_IOBUFFER_SIZE=512 CONFIG_NSH_DHCPC=n CONFIG_NSH_NOMAC=y -CONFIG_NSH_IPADDR=(192<<24|168<<16|13<<8|161) -CONFIG_NSH_DRIPADDR=(192<<24|168<<16|13<<8|1) +CONFIG_NSH_IPADDR=(10<<24|0<<16|0<<8|2) +CONFIG_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1) CONFIG_NSH_NETMASK=(255<<24|255<<16|255<<8|0) CONFIG_NSH_ROMFSMOUNTPT="/etc" CONFIG_NSH_INITSCRIPT="init.d/rcS" @@ -1368,6 +1507,276 @@ CONFIG_EXAMPLES_USBSERIAL_TRACEINTERRUPTS=n # built-in, the default is 32. Otherwise messages are sent and received # indefinitely. +# +# Settings for examples/nx +# +# CONFIG_EXAMPLES_NX_BUILTIN -- Build the NX example as a "built-in" +# that can be executed from the NSH command line +# CONFIG_EXAMPLES_NX_VPLANE -- The plane to select from the frame- +# buffer driver for use in the test. Default: 0 +# CONFIG_EXAMPLES_NX_DEVNO - The LCD device to select from the LCD +# driver for use in the test: Default: 0 +# CONFIG_EXAMPLES_NX_BGCOLOR -- The color of the background. Default depends on +# CONFIG_EXAMPLES_NX_BPP. +# CONFIG_EXAMPLES_NX_COLOR1 -- The color of window 1. Default depends on +# CONFIG_EXAMPLES_NX_BPP. +# CONFIG_EXAMPLES_NX_COLOR2 -- The color of window 2. Default depends on +# CONFIG_EXAMPLES_NX_BPP. +# CONFIG_EXAMPLES_NX_TBCOLOR -- The color of the toolbar. Default depends on +# CONFIG_EXAMPLES_NX_BPP. +# CONFIG_EXAMPLES_NX_FONTID - Selects the font (see font ID numbers in +# include/nuttx/nx/nxfonts.h) +# CONFIG_EXAMPLES_NX_FONTCOLOR -- The color of the toolbar. Default depends on +# CONFIG_EXAMPLES_NX_BPP. +# CONFIG_EXAMPLES_NX_BPP -- Pixels per pixel to use. Valid options +# include 2, 4, 8, 16, 24, and 32. Default is 32. +# CONFIG_EXAMPLES_NX_RAWWINDOWS -- Use raw windows; Default is to +# use pretty, framed NXTK windows with toolbars. +# CONFIG_EXAMPLES_NX_STACKSIZE -- The stacksize to use when creating +# the NX server. Default 2048 +# CONFIG_EXAMPLES_NX_CLIENTPRIO -- The client priority. Default: 80 +# CONFIG_EXAMPLES_NX_SERVERPRIO -- The server priority. Default: 120 +# CONFIG_EXAMPLES_NX_NOTIFYSIGNO -- The signal number to use with +# nx_eventnotify(). Default: 4 +# +CONFIG_EXAMPLES_NX_BUILTIN=y +CONFIG_EXAMPLES_NX_VPLANE=0 +CONFIG_EXAMPLES_NX_DEVNO=0 +CONFIG_EXAMPLES_NX_BGCOLOR=0x0011 +CONFIG_EXAMPLES_NX_COLOR1=0xaedc +CONFIG_EXAMPLES_NX_COLOR2=0xe7ff +CONFIG_EXAMPLES_NX_TBCOLOR=0xd69a +CONFIG_EXAMPLES_NX_FONTID=0 +CONFIG_EXAMPLES_NX_FONTCOLOR=0x0000 +CONFIG_EXAMPLES_NX_BPP=16 +CONFIG_EXAMPLES_NX_RAWWINDOWS=n +CONFIG_EXAMPLES_NX_STACKSIZE=2048 +CONFIG_EXAMPLES_NX_CLIENTPRIO=80 +CONFIG_EXAMPLES_NX_SERVERPRIO=120 +CONFIG_EXAMPLES_NX_NOTIFYSIGNO=4 +CONFIG_EXAMPLES_NX_EXTERNINIT=n + +# +# Settings for examples/nxhello +# +# CONFIG_EXAMPLES_NXHELLO_BUILTIN -- Build the NXHELLO example as a "built-in" +# that can be executed from the NSH command line +# CONFIG_EXAMPLES_NXHELLO_VPLANE -- The plane to select from the frame- +# buffer driver for use in the test. Default: 0 +# CONFIG_EXAMPLES_NXHELLO_DEVNO - The LCD device to select from the LCD +# driver for use in the test: Default: 0 +# CONFIG_EXAMPLES_NXHELLO_BGCOLOR -- The color of the background. Default +# depends on CONFIG_EXAMPLES_NXHELLO_BPP. +# CONFIG_EXAMPLES_NXHELLO_FONTID - Selects the font (see font ID numbers in +# include/nuttx/nx/nxfonts.h) +# CONFIG_EXAMPLES_NXHELLO_FONTCOLOR -- The color of the fonts used in the +# background window. Default depends on CONFIG_EXAMPLES_NXHELLO_BPP. +# CONFIG_EXAMPLES_NXHELLO_BPP -- Pixels per pixel to use. Valid options +# include 2, 4, 8, 16, 24, and 32. Default is 32. +# CONFIG_EXAMPLES_NXHELLO_EXTERNINIT - The driver for the graphics device on +# this platform requires some unusual initialization. This is the +# for, for example, SPI LCD/OLED devices. If this configuration is +# selected, then the platform code must provide an LCD initialization +# function. +# +CONFIG_EXAMPLES_NXHELLO_BUILTIN=y +CONFIG_EXAMPLES_NXHELLO_VPLANE=0 +CONFIG_EXAMPLES_NXHELLO_DEVNO=0 +CONFIG_EXAMPLES_NXHELLO_BGCOLOR=0x0011 +CONFIG_EXAMPLES_NXHELLO_FONTID=6 +CONFIG_EXAMPLES_NXHELLO_FONTCOLOR=0xffdf +CONFIG_EXAMPLES_NXHELLO_BPP=16 +CONFIG_EXAMPLES_NXHELLO_EXTERNINIT=n + +# +# Settings for examples/nximage +# +# CONFIG_EXAMPLES_NXIMAGE_BUILTIN -- Build the NXIMAGE example as a "built-in" +# that can be executed from the NSH command line +# CONFIG_EXAMPLES_NXIMAGE_VPLANE -- The plane to select from the frame- +# buffer driver for use in the test. Default: 0 +# CONFIG_EXAMPLES_NXIMAGE_DEVNO - The LCD device to select from the LCD +# driver for use in the test: Default: 0 +# CONFIG_EXAMPLES_NXIMAGE_BPP -- Pixels per pixel to use. Valid options +# include 8, 16, and 24. Default is 16. +# CONFIG_EXAMPLES_NXIMAGE_XSCALEp5, CONFIG_EXAMPLES_NXIMAGE_XSCALE1p5, +# CONFIG_EXAMPLES_NXIMAGE_XSCALE2p0 -- The logo image width is 160 columns. +# One of these may be defined to rescale the image horizontally by .5, 1.5, +# or 2.0. +# CONFIG_EXAMPLES_NXIMAGE_YSCALEp5, CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5, +# CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0 -- The logo image height is 160 rows. +# One of these may be defined to rescale the image vertically by .5, 1.5, +# or 2.0. +# CONFIG_EXAMPLES_NXIMAGE_EXTERNINIT - The driver for the graphics device on +# this platform requires some unusual initialization. This is the +# for, for example, SPI LCD/OLED devices. If this configuration is +# selected, then the platform code must provide an LCD initialization +# function. +# +CONFIG_EXAMPLES_NXIMAGE_BUILTIN=y +CONFIG_EXAMPLES_NXIMAGE_VPLANE=0 +CONFIG_EXAMPLES_NXIMAGE_DEVNO=0 +CONFIG_EXAMPLES_NXIMAGE_BPP=16 +CONFIG_EXAMPLES_NXIMAGE_XSCALEp5=n +CONFIG_EXAMPLES_NXIMAGE_XSCALE1p5=y +CONFIG_EXAMPLES_NXIMAGE_XSCALE2p0=n +CONFIG_EXAMPLES_NXIMAGE_YSCALEp5=n +CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5=y +CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0=n +CONFIG_EXAMPLES_NXIMAGE_EXTERNINIT=n + +# +# Settings for examples/nxlines +# +# CONFIG_EXAMPLES_NXLINES_BUILTIN -- Build the NXLINES example as a "built-in" +# that can be executed from the NSH command line +# CONFIG_EXAMPLES_NXLINES_VPLANE -- The plane to select from the frame- +# buffer driver for use in the test. Default: 0 +# CONFIG_EXAMPLES_NXLINES_DEVNO - The LCD device to select from the LCD +# driver for use in the test: Default: 0 +# CONFIG_EXAMPLES_NXLINES_BGCOLOR -- The color of the background. Default +# depends on CONFIG_EXAMPLES_NXLINES_BPP. +# CONFIG_EXAMPLES_NXLINES_LINEWIDTH - Selects the width of the lines in +# pixels (default: 16) +# CONFIG_EXAMPLES_NXLINES_LINECOLOR -- The color of the central lines drawn +# in the background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP +# (there really is no meaningful default). +# CONFIG_EXAMPLES_NXLINES_BORDERWIDTH -- The width of the circular border +# drawn in the background window. (default: 4). +# CONFIG_EXAMPLES_NXLINES_BORDERCOLOR -- The color of the circular border +# drawn in the background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP +# (there really is no meaningful default). +# CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR -- The color of the circular region +# filled in the background window. Default depends on CONFIG_EXAMPLES_NXLINES_BPP +# (there really is no meaningful default). +# CONFIG_EXAMPLES_NXLINES_BPP -- Pixels per pixel to use. Valid options +# include 2, 4, 8, 16, 24, and 32. Default is 16. +# CONFIG_EXAMPLES_NXLINES_EXTERNINIT - The driver for the graphics device on +# this platform requires some unusual initialization. This is the +# for, for example, SPI LCD/OLED devices. If this configuration is +# selected, then the platform code must provide an LCD initialization +# function. +# +CONFIG_EXAMPLES_NXLINES_BUILTIN=n +CONFIG_EXAMPLES_NXLINES_VPLANE=0 +CONFIG_EXAMPLES_NXLINES_DEVNO=0 +CONFIG_EXAMPLES_NXLINES_BGCOLOR=0x0320 +CONFIG_EXAMPLES_NXLINES_LINEWIDTH=16 +CONFIG_EXAMPLES_NXLINES_LINECOLOR=0xffe0 +CONFIG_EXAMPLES_NXLINES_BORDERWIDTH=4 +CONFIG_EXAMPLES_NXLINES_BORDERCOLOR=0xffe0 +CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR=0xf7bb +CONFIG_EXAMPLES_NXLINES_BPP=16 +CONFIG_EXAMPLES_NXLINES_EXTERNINIT=n + +# +# Settings for examples/touchscreen +# +# CONFIG_EXAMPLES_TOUCHSCREEN_BUILTIN - Build the touchscreen test as +# an NSH built-in function. Default: Built as a standalone problem +# CONFIG_EXAMPLES_TOUCHSCREEN_MINOR - The minor device number. Minor=N +# correspnds to touchscreen device /dev/input0. Note this value must +# with CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH. Default 0. +# CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH - The path to the touchscreen +# device. This must be consistent with CONFIG_EXAMPLES_TOUCHSCREEN_MINOR. +# Default: "/dev/input0" +# CONFIG_EXAMPLES_TOUCHSCREEN_NSAMPLES - If CONFIG_EXAMPLES_TOUCHSCREEN_BUILTIN +# is defined, then the number of samples is provided on the command line +# and this value is ignored. Otherwise, this number of samples is +# collected and the program terminates. Default: Samples are collected +# indefinitely. +# +CONFIG_EXAMPLES_TOUCHSCREEN_BUILTIN=y +CONFIG_EXAMPLES_TOUCHSCREEN_MINOR=0 +CONFIG_EXAMPLES_TOUCHSCREEN_DEVPATH="/dev/input0" +CONFIG_EXAMPLES_TOUCHSCREEN_NSAMPLES=25 + +# +# Settings for examples/usbstorage +# +# CONFIG_EXAMPLES_USBMSC_BUILTIN +# This example can be built as two NSH "built-in" commands if this option +# is selection: 'msconn' will connect the USB mass storage device; 'msdis' +# will disconnect the USB storage device. +# CONFIG_EXAMPLES_USBMSC_NLUNS +# Defines the number of logical units (LUNs) exported by the USB storage +# driver. Each LUN corresponds to one exported block driver (or partition +# of a block driver). May be 1, 2, or 3. Default is 1. +# CONFIG_EXAMPLES_USBMSC_DEVMINOR1 +# The minor device number of the block driver for the first LUN. For +# example, N in /dev/mmcsdN. Used for registering the block driver. Default +# is zero. +# CONFIG_EXAMPLES_USBMSC_DEVPATH1 +# The full path to the registered block driver. Default is "/dev/mmcsd0" +# CONFIG_EXAMPLES_USBMSC_DEVMINOR2 and CONFIG_EXAMPLES_USBMSC_DEVPATH2 +# Similar parameters that would have to be provided if CONFIG_EXAMPLES_USBMSC_NLUNS +# is 2 or 3. No defaults. +# CONFIG_EXAMPLES_USBMSC_DEVMINOR3 and CONFIG_EXAMPLES_USBMSC_DEVPATH3 +# Similar parameters that would have to be provided if CONFIG_EXAMPLES_USBMSC_NLUNS +# is 3. No defaults. +# CONFIG_EXAMPLES_USBMSC_DEBUGMM +# Enables some debug tests to check for memory usage and memory leaks. +# +# If CONFIG_USBDEV_TRACE is enabled (or CONFIG_DEBUG and CONFIG_DEBUG_USB), then +# the example code will also manage the USB trace output. The amount of trace output +# can be controlled using: +# +# CONFIG_EXAMPLES_USBMSC_TRACEINIT +# Show initialization events +# CONFIG_EXAMPLES_USBMSC_TRACECLASS +# Show class driver events +# CONFIG_EXAMPLES_USBMSC_TRACETRANSFERS +# Show data transfer events +# CONFIG_EXAMPLES_USBMSC_TRACECONTROLLER +# Show controller events +# CONFIG_EXAMPLES_USBMSC_TRACEINTERRUPTS +# Show interrupt-related events. +# +CONFIG_EXAMPLES_USBMSC_BUILTIN=y +CONFIG_EXAMPLES_USBMSC_NLUNS=1 +CONFIG_EXAMPLES_USBMSC_DEVMINOR1=0 +CONFIG_EXAMPLES_USBMSC_DEVPATH1="/dev/mmcsd0" +CONFIG_EXAMPLES_USBMSC_DEBUGMM=n +CONFIG_EXAMPLES_USBMSC_TRACEINIT=n +CONFIG_EXAMPLES_USBMSC_TRACECLASS=n +CONFIG_EXAMPLES_USBMSC_TRACETRANSFERS=n +CONFIG_EXAMPLES_USBMSC_TRACECONTROLLER=n +CONFIG_EXAMPLES_USBMSC_TRACEINTERRUPTS=n + +# +# Settings for examples/watchdog +# +# This test depends on these specific Watchdog/NSH configurations settings (your +# specific watchdog hardware settings might require additional settings). +# +# CONFIG_WATCHDOG- Enables watchdog timer support support. +# CONFIG_NSH_BUILTIN_APPS - Build the watchdog time test as an NSH +# built-in function. Default: Not built! The example can only be used +# as an NSH built-in application +# +# The STM32 also needs one of the following enabled: +# +# CONFIG_STM32_WWDG=y, OR +# CONFIG_STM32_IWDG=y (but not both) +# +# Specific configuration options for this example include: +# +# CONFIG_EXAMPLES_WATCHDOG_DEVPATH - The path to the Watchdog device. +# Default: /dev/watchdog0 +# CONFIG_EXAMPLES_WATCHDOG_PINGTIME - Time in milliseconds that the example +# will ping the watchdog before letting the watchdog expire. Default: 5000 +# milliseconds +# CONFIG_EXAMPLES_WATCHDOG_PINGDELAY - Time delay between pings in +# milliseconds. Default: 500 milliseconds. +# CONFIG_EXAMPLES_WATCHDOG_TIMEOUT - The watchdog timeout value in +# milliseconds before the watchdog timer expires. Default: 2000 +# milliseconds. +# +# CONFIG_EXAMPLES_WATCHDOG_DEVPATH +# CONFIG_EXAMPLES_WATCHDOG_PINGTIME +# CONFIG_EXAMPLES_WATCHDOG_PINGDELAY +# CONFIG_EXAMPLES_WATCHDOG_TIMEOUT + # # Settings for examples/pwm # diff --git a/nuttx/configs/stm3240g-eval/include/board.h b/nuttx/configs/stm3240g-eval/include/board.h index abbc3380b..a438dcc1b 100755 --- a/nuttx/configs/stm3240g-eval/include/board.h +++ b/nuttx/configs/stm3240g-eval/include/board.h @@ -167,29 +167,29 @@ * to service FIFOs in interrupt driven mode. These values have not been * tuned!!! * - * HCLK=72MHz, SDIOCLK=72MHz, SDIO_CK=HCLK/(178+2)=400 KHz + * SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(118+2)=400 KHz */ -#define SDIO_INIT_CLKDIV (178 << SDIO_CLKCR_CLKDIV_SHIFT) +#define SDIO_INIT_CLKDIV (118 << SDIO_CLKCR_CLKDIV_SHIFT) -/* DMA ON: HCLK=72 MHz, SDIOCLK=72MHz, SDIO_CK=HCLK/(2+2)=18 MHz - * DMA OFF: HCLK=72 MHz, SDIOCLK=72MHz, SDIO_CK=HCLK/(3+2)=14.4 MHz +/* DMA ON: SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(1+2)=16 MHz + * DMA OFF: SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(2+2)=12 MHz */ #ifdef CONFIG_SDIO_DMA -# define SDIO_MMCXFR_CLKDIV (2 << SDIO_CLKCR_CLKDIV_SHIFT) +# define SDIO_MMCXFR_CLKDIV (1 << SDIO_CLKCR_CLKDIV_SHIFT) #else -# define SDIO_MMCXFR_CLKDIV (3 << SDIO_CLKCR_CLKDIV_SHIFT) +# define SDIO_MMCXFR_CLKDIV (2 << SDIO_CLKCR_CLKDIV_SHIFT) #endif -/* DMA ON: HCLK=72 MHz, SDIOCLK=72MHz, SDIO_CK=HCLK/(1+2)=24 MHz - * DMA OFF: HCLK=72 MHz, SDIOCLK=72MHz, SDIO_CK=HCLK/(3+2)=14.4 MHz +/* DMA ON: HSDIOCLK=48MHz, SDIO_CK=SDIOCLK/(0+2)=24 MHz + * DMA OFF: SDIOCLK=48MHz, SDIO_CK=SDIOCLK/(2+2)=12 MHz */ #ifdef CONFIG_SDIO_DMA -# define SDIO_SDXFR_CLKDIV (1 << SDIO_CLKCR_CLKDIV_SHIFT) +# define SDIO_SDXFR_CLKDIV (0 << SDIO_CLKCR_CLKDIV_SHIFT) #else -# define SDIO_SDXFR_CLKDIV (3 << SDIO_CLKCR_CLKDIV_SHIFT) +# define SDIO_SDXFR_CLKDIV (2 << SDIO_CLKCR_CLKDIV_SHIFT) #endif /* Ethernet *************************************************************************/ diff --git a/nuttx/configs/stm3240g-eval/nsh2/defconfig b/nuttx/configs/stm3240g-eval/nsh2/defconfig index 1ffc6ecd6..5c3d7b540 100644 --- a/nuttx/configs/stm3240g-eval/nsh2/defconfig +++ b/nuttx/configs/stm3240g-eval/nsh2/defconfig @@ -541,7 +541,7 @@ CONFIG_START_MONTH=12 CONFIG_START_DAY=6 CONFIG_GREGORIAN_TIME=n CONFIG_JULIAN_TIME=n -CONFIG_DEV_CONSOLE=y +CONFIG_DEV_CONSOLE=n CONFIG_DEV_LOWCONSOLE=n CONFIG_MUTEX_TYPES=n CONFIG_PRIORITY_INHERITANCE=n @@ -1268,7 +1268,7 @@ CONFIG_NSH_NESTDEPTH=3 CONFIG_NSH_DISABLESCRIPT=n CONFIG_NSH_DISABLEBG=n CONFIG_NSH_ROMFSETC=n -CONFIG_NSH_CONSOLE=y +CONFIG_NSH_CONSOLE=n CONFIG_NSH_TELNET=y CONFIG_NSH_ARCHINIT=y CONFIG_NSH_IOBUFFER_SIZE=512 diff --git a/nuttx/sched/atexit.c b/nuttx/sched/atexit.c index 8a491aa14..2c9b89d92 100644 --- a/nuttx/sched/atexit.c +++ b/nuttx/sched/atexit.c @@ -80,7 +80,7 @@ ************************************************************************/ /************************************************************************ - * Function: atexit + * Name: atexit * * Description: * Registers a function to be called at program exit. diff --git a/nuttx/sched/clock_abstime2ticks.c b/nuttx/sched/clock_abstime2ticks.c index c8be4b1b1..2d7f7f480 100644 --- a/nuttx/sched/clock_abstime2ticks.c +++ b/nuttx/sched/clock_abstime2ticks.c @@ -2,7 +2,7 @@ * clock_abstime2ticks.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -69,7 +69,7 @@ ********************************************************************************/ /******************************************************************************** - * Function: clock_abstime2ticks + * Name: clock_abstime2ticks * * Description: * Convert an absolute timespec delay to system timer ticks. @@ -95,8 +95,8 @@ int clock_abstime2ticks(clockid_t clockid, FAR const struct timespec *abstime, struct timespec reltime; int ret; - /* Convert the timespec to clock ticks. NOTE: Here we use - * internal knowledge that CLOCK_REALTIME is defined to be zero! + /* Convert the timespec to clock ticks. NOTE: Here we use internal knowledge + * that CLOCK_REALTIME is defined to be zero! */ ret = clock_gettime(clockid, &currtime); @@ -105,15 +105,13 @@ int clock_abstime2ticks(clockid_t clockid, FAR const struct timespec *abstime, return EINVAL; } - /* The relative time to wait is the absolute time minus the - * current time. - */ + /* The relative time to wait is the absolute time minus the current time. */ reltime.tv_nsec = (abstime->tv_nsec - currtime.tv_nsec); reltime.tv_sec = (abstime->tv_sec - currtime.tv_sec); - /* Check if we were supposed to borrow from the seconds to - * borrow from the seconds + /* Check if we were supposed to borrow from the seconds to borrow from the + * seconds */ if (reltime.tv_nsec < 0) diff --git a/nuttx/sched/clock_getres.c b/nuttx/sched/clock_getres.c index 467802f27..a76b14ab6 100644 --- a/nuttx/sched/clock_getres.c +++ b/nuttx/sched/clock_getres.c @@ -2,7 +2,7 @@ * sched/clock_getres.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -79,7 +79,7 @@ ************************************************************************/ /************************************************************************ - * Function: clock_getres + * Name: clock_getres * * Description: * Clock Functions based on POSIX APIs @@ -98,7 +98,7 @@ int clock_getres(clockid_t clock_id, struct timespec *res) if (clock_id != CLOCK_REALTIME) { sdbg("Returning ERROR\n"); - *get_errno_ptr() = EINVAL; + set_errno(EINVAL); ret = ERROR; } else diff --git a/nuttx/sched/clock_gettime.c b/nuttx/sched/clock_gettime.c index 341b4bed9..d6772dada 100644 --- a/nuttx/sched/clock_gettime.c +++ b/nuttx/sched/clock_gettime.c @@ -83,7 +83,7 @@ ************************************************************************/ /************************************************************************ - * Function: clock_gettime + * Name: clock_gettime * * Description: * Clock Functions based on POSIX APIs diff --git a/nuttx/sched/clock_gettimeofday.c b/nuttx/sched/clock_gettimeofday.c index 54c44f753..6437ef955 100644 --- a/nuttx/sched/clock_gettimeofday.c +++ b/nuttx/sched/clock_gettimeofday.c @@ -2,7 +2,7 @@ * sched/clock_gettimeofday.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,10 +38,11 @@ ****************************************************************************/ #include -#include +#include #include #include + #include "clock_internal.h" /**************************************************************************** @@ -77,7 +78,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: gettimeofday + * Name: gettimeofday * * Description: * Get the current time @@ -107,5 +108,6 @@ int gettimeofday(struct timeval *tp, void *tzp) tp->tv_sec = ts.tv_sec; tp->tv_usec = ts.tv_nsec / NSEC_PER_USEC; } + return ret; } diff --git a/nuttx/sched/clock_initialize.c b/nuttx/sched/clock_initialize.c index beea4d456..2e146bb47 100644 --- a/nuttx/sched/clock_initialize.c +++ b/nuttx/sched/clock_initialize.c @@ -99,7 +99,7 @@ struct timespec g_basetime; **************************************************************************/ /**************************************************************************** - * Function: clock_basetime + * Name: clock_basetime * * Description: * Get the initial time value from the best source available. @@ -170,7 +170,7 @@ static inline void clock_basetime(FAR struct timespec *tp) #endif /* CONFIG_RTC */ /**************************************************************************** - * Function: clock_inittime + * Name: clock_inittime * * Description: * Get the initial time value from the best source available. @@ -191,7 +191,7 @@ static void clock_inittime(void) ****************************************************************************/ /**************************************************************************** - * Function: clock_initialize + * Name: clock_initialize * * Description: * Perform one-time initialization of the timing facilities. @@ -212,7 +212,7 @@ void clock_initialize(void) } /**************************************************************************** - * Function: clock_synchronize + * Name: clock_synchronize * * Description: * Synchronize the system timer to a hardware RTC. This operation is @@ -253,12 +253,12 @@ void clock_synchronize(void) #endif /**************************************************************************** - * Function: clock_timer + * Name: clock_timer * * Description: - * This function must be called once every time the real - * time clock interrupt occurs. The interval of this - * clock interrupt must be MSEC_PER_TICK + * This function must be called once every time the real time clock + * interrupt occurs. The interval of this clock interrupt must be + * MSEC_PER_TICK * ****************************************************************************/ diff --git a/nuttx/sched/clock_internal.h b/nuttx/sched/clock_internal.h index dadf5d66a..aba9723b6 100644 --- a/nuttx/sched/clock_internal.h +++ b/nuttx/sched/clock_internal.h @@ -1,8 +1,8 @@ /******************************************************************************** - * clock_internal.h + * sched/clock_internal.h * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,8 +33,8 @@ * ********************************************************************************/ -#ifndef __CLOCK_INTERNAL_H -#define __CLOCK_INTERNAL_H +#ifndef __SCHED_CLOCK_INTERNAL_H +#define __SCHED_CLOCK_INTERNAL_H /******************************************************************************** * Included Files @@ -79,13 +79,13 @@ extern struct timespec g_basetime; * Public Function Prototypes ********************************************************************************/ -extern void weak_function clock_initialize(void); -extern void weak_function clock_timer(void); +void weak_function clock_initialize(void); +void weak_function clock_timer(void); -extern int clock_abstime2ticks(clockid_t clockid, - FAR const struct timespec *abstime, - FAR int *ticks); -extern int clock_time2ticks(FAR const struct timespec *reltime, FAR int *ticks); -extern int clock_ticks2time(int ticks, FAR struct timespec *reltime); +int clock_abstime2ticks(clockid_t clockid, + FAR const struct timespec *abstime, + FAR int *ticks); +int clock_time2ticks(FAR const struct timespec *reltime, FAR int *ticks); +int clock_ticks2time(int ticks, FAR struct timespec *reltime); -#endif /* __CLOCK_INTERNAL_H */ +#endif /* __SCHED_CLOCK_INTERNAL_H */ diff --git a/nuttx/sched/clock_settime.c b/nuttx/sched/clock_settime.c index aa48b4592..ce809aa11 100644 --- a/nuttx/sched/clock_settime.c +++ b/nuttx/sched/clock_settime.c @@ -81,7 +81,7 @@ ************************************************************************/ /************************************************************************ - * Function: clock_settime + * Name: clock_settime * * Description: * Clock Functions based on POSIX APIs diff --git a/nuttx/sched/clock_systimer.c b/nuttx/sched/clock_systimer.c index 6a2a9e24e..33c16db94 100644 --- a/nuttx/sched/clock_systimer.c +++ b/nuttx/sched/clock_systimer.c @@ -2,7 +2,7 @@ * sched/clock_systimer.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: clock_systimer + * Name: clock_systimer * * Description: * Return the current value of the 32-bit system timer counter @@ -85,7 +85,7 @@ uint32_t clock_systimer(void) #endif /**************************************************************************** - * Function: clock_systimer64 + * Name: clock_systimer64 * * Description: * Return the current value of the 64-bit system timer counter diff --git a/nuttx/sched/clock_ticks2time.c b/nuttx/sched/clock_ticks2time.c index fe2165d68..fd300692d 100644 --- a/nuttx/sched/clock_ticks2time.c +++ b/nuttx/sched/clock_ticks2time.c @@ -2,7 +2,7 @@ * clock_ticks2time.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -67,7 +67,7 @@ ********************************************************************************/ /******************************************************************************** - * Function: clock_ticks2time + * Name: clock_ticks2time * * Description: * Convert the system time tick value to a relative time. diff --git a/nuttx/sched/clock_time2ticks.c b/nuttx/sched/clock_time2ticks.c index beba5014c..383264d51 100644 --- a/nuttx/sched/clock_time2ticks.c +++ b/nuttx/sched/clock_time2ticks.c @@ -2,7 +2,7 @@ * sched/clock_time2ticks.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -69,7 +69,7 @@ ********************************************************************************/ /******************************************************************************** - * Function: clock_time2ticks + * Name: clock_time2ticks * * Description: * Convert a timespec delay to system timer ticks. This function is suitable diff --git a/nuttx/sched/env_clearenv.c b/nuttx/sched/env_clearenv.c index fa777bbf7..7fe97a911 100644 --- a/nuttx/sched/env_clearenv.c +++ b/nuttx/sched/env_clearenv.c @@ -2,7 +2,7 @@ * sched/env_clearenv.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: clearenv + * Name: clearenv * * Description: * The clearenv() function clears the environment of all name-value pairs diff --git a/nuttx/sched/env_dup.c b/nuttx/sched/env_dup.c index cbde5251d..033348411 100644 --- a/nuttx/sched/env_dup.c +++ b/nuttx/sched/env_dup.c @@ -2,7 +2,7 @@ * sched/env_dup.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -60,7 +60,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: env_dup + * Name: env_dup * * Description: * Copy the internal environment structure of a task. This is the action @@ -122,6 +122,7 @@ int env_dup(FAR _TCB *ptcb) ptcb->envp = envp; sched_unlock(); } + return ret; } diff --git a/nuttx/sched/env_dupenv.c b/nuttx/sched/env_dupenv.c index fd3ccd7b7..32bf6a433 100644 --- a/nuttx/sched/env_dupenv.c +++ b/nuttx/sched/env_dupenv.c @@ -2,7 +2,7 @@ * eched/env_dupenv.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: dupenv + * Name: dupenv * * Description: * Copy the internal environment structure of a task. This is the action diff --git a/nuttx/sched/env_findvar.c b/nuttx/sched/env_findvar.c index b789a101d..a8e94180c 100644 --- a/nuttx/sched/env_findvar.c +++ b/nuttx/sched/env_findvar.c @@ -2,7 +2,7 @@ * sched/env_findvar.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -54,7 +54,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: env_cmpname + * Name: env_cmpname ****************************************************************************/ static bool env_cmpname(const char *pszname, const char *peqname) @@ -69,6 +69,7 @@ static bool env_cmpname(const char *pszname, const char *peqname) { return true; } + return false; } @@ -77,7 +78,7 @@ static bool env_cmpname(const char *pszname, const char *peqname) ****************************************************************************/ /**************************************************************************** - * Function: env_findvar + * Name: env_findvar * * Description: * Search the provided environment structure for the variable of the @@ -109,7 +110,9 @@ FAR char *env_findvar(environ_t *envp, const char *pname) /* Search for a name=value string with matching name */ - for (ptr = envp->ev_env; ptr < end && !env_cmpname( pname, ptr); ptr += (strlen(ptr) + 1)); + for (ptr = envp->ev_env; + ptr < end && !env_cmpname( pname, ptr); + ptr += (strlen(ptr) + 1)); /* Check for success */ @@ -118,6 +121,7 @@ FAR char *env_findvar(environ_t *envp, const char *pname) ret = ptr; } } + return ret; } diff --git a/nuttx/sched/env_getenv.c b/nuttx/sched/env_getenv.c index be0a83d2e..ee8d798b1 100644 --- a/nuttx/sched/env_getenv.c +++ b/nuttx/sched/env_getenv.c @@ -2,7 +2,7 @@ * env_getenv.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: getenv + * Name: getenv * * Description: * The getenv() function searches the environment list for a string that @@ -91,7 +91,6 @@ FAR char *getenv(const char *name) goto errout; } - /* Get a reference to the thread-private environ in the TCB.*/ sched_lock(); @@ -126,7 +125,7 @@ FAR char *getenv(const char *name) errout_with_lock: sched_unlock(); errout: - *get_errno_ptr() = ret; + set_errno(ret); return NULL; } diff --git a/nuttx/sched/env_getenvironptr.c b/nuttx/sched/env_getenvironptr.c index 8fad450cd..25b09755b 100644 --- a/nuttx/sched/env_getenvironptr.c +++ b/nuttx/sched/env_getenvironptr.c @@ -2,7 +2,7 @@ * env_getenvironptr.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: get_environ_ptr + * Name: get_environ_ptr * * Description: * Return a pointer to the thread specific environ variable. @@ -75,9 +75,9 @@ FAR char **get_environ_ptr( void ) { #if 1 - /* Type of internal representation of environment is incompatible with - * char ** return value. - */ + /* Type of internal representation of environment is incompatible with + * char ** return value. + */ return NULL; diff --git a/nuttx/sched/env_internal.h b/nuttx/sched/env_internal.h index c96f3f708..a6205d658 100644 --- a/nuttx/sched/env_internal.h +++ b/nuttx/sched/env_internal.h @@ -2,7 +2,7 @@ * sched/env_internal.h * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/sched/env_putenv.c b/nuttx/sched/env_putenv.c index 68674023a..ad00dd13d 100644 --- a/nuttx/sched/env_putenv.c +++ b/nuttx/sched/env_putenv.c @@ -2,7 +2,7 @@ * sched/env_putenv.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: putenv + * Name: putenv * * Description: * The putenv() function adds or changes the value of environment variables. diff --git a/nuttx/sched/env_release.c b/nuttx/sched/env_release.c index d124477d5..83e65dbb5 100644 --- a/nuttx/sched/env_release.c +++ b/nuttx/sched/env_release.c @@ -2,7 +2,7 @@ * sched/env_clearenv.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -55,12 +55,12 @@ ****************************************************************************/ /**************************************************************************** - * Function: env_release + * Name: env_release * * Description: - * The env_release() function clears the environment of all name-value pairs - * and sets the value of the external variable environ to NULL. - + * The env_release() function clears the environment of all name-value + * pairs and sets the value of the external variable environ to NULL. + * * Parameters: * ptcb Identifies the TCB containing the environment structure * @@ -75,6 +75,7 @@ int env_release(FAR _TCB *ptcb) { int ret = OK; + if (!ptcb) { ret = -EINVAL; @@ -111,8 +112,10 @@ int env_release(FAR _TCB *ptcb) ptcb->envp = NULL; } + sched_unlock(); } + return ret; } diff --git a/nuttx/sched/env_removevar.c b/nuttx/sched/env_removevar.c index b4890a35d..e96aa7a37 100644 --- a/nuttx/sched/env_removevar.c +++ b/nuttx/sched/env_removevar.c @@ -2,7 +2,7 @@ * sched/env_removevar.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -53,7 +53,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: env_removevar + * Name: env_removevar * * Description: * Remove the referenced name=value pair from the environment @@ -109,6 +109,7 @@ int env_removevar(environ_t *envp, char *pvar) ret = OK; } } + return ret; } diff --git a/nuttx/sched/env_setenv.c b/nuttx/sched/env_setenv.c index bc1ff33b1..c186241ef 100644 --- a/nuttx/sched/env_setenv.c +++ b/nuttx/sched/env_setenv.c @@ -2,7 +2,7 @@ * sched/env_setenv.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -61,7 +61,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: setenv + * Name: setenv * * Description: * The setenv() function adds the variable name to the environment with the @@ -148,8 +148,8 @@ int setenv(const char *name, const char *value, int overwrite) } /* Get the size of the new name=value string. The +2 is for the '=' and for - * null terminator - */ + * null terminator + */ varlen = strlen(name) + strlen(value) + 2; diff --git a/nuttx/sched/env_share.c b/nuttx/sched/env_share.c index 15bfcccb9..5f37a0219 100644 --- a/nuttx/sched/env_share.c +++ b/nuttx/sched/env_share.c @@ -2,7 +2,7 @@ * sched/env_share.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -43,6 +43,7 @@ #include #include + #include "os_internal.h" #include "env_internal.h" @@ -55,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: env_share + * Name: env_share * * Description: * Increment the reference count on the internal environment structure of @@ -106,6 +107,7 @@ int env_share(FAR _TCB *ptcb) ptcb->envp = envp; sched_unlock(); } + return ret; } diff --git a/nuttx/sched/env_unsetenv.c b/nuttx/sched/env_unsetenv.c index a751661c7..52469fac9 100644 --- a/nuttx/sched/env_unsetenv.c +++ b/nuttx/sched/env_unsetenv.c @@ -2,7 +2,7 @@ * sched/env_unsetenv.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -59,7 +59,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: unsetenv + * Name: unsetenv * * Description: * The unsetenv() function deletes the variable name from the environment. diff --git a/nuttx/sched/errno_get.c b/nuttx/sched/errno_get.c index 7461a42c7..cac041f64 100644 --- a/nuttx/sched/errno_get.c +++ b/nuttx/sched/errno_get.c @@ -2,7 +2,7 @@ * sched/errno_get.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: get_errno + * Name: get_errno * * Description: * Return the value of the thread specific errno. This function is only diff --git a/nuttx/sched/errno_getptr.c b/nuttx/sched/errno_getptr.c index 8daf5b2cc..0b27768da 100644 --- a/nuttx/sched/errno_getptr.c +++ b/nuttx/sched/errno_getptr.c @@ -2,7 +2,7 @@ * sched/errno_getptr.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -61,7 +61,7 @@ static int g_irqerrno; ****************************************************************************/ /**************************************************************************** - * Function: get_errno_ptr + * Name: get_errno_ptr * * Description: * Return a pointer to the thread specific errno. diff --git a/nuttx/sched/errno_set.c b/nuttx/sched/errno_set.c index 2bf01d9b1..eda680b64 100644 --- a/nuttx/sched/errno_set.c +++ b/nuttx/sched/errno_set.c @@ -2,7 +2,7 @@ * sched/errno_set.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -58,7 +58,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: set_errno + * Name: set_errno * * Description: * Set the value of the thread specific errno. This function is only diff --git a/nuttx/sched/exit.c b/nuttx/sched/exit.c index 56258844f..7e50c273c 100644 --- a/nuttx/sched/exit.c +++ b/nuttx/sched/exit.c @@ -43,7 +43,9 @@ #include #include #include + #include + #include "os_internal.h" /**************************************************************************** @@ -75,7 +77,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: exit + * Name: exit * * Description: * The exit() function causes normal process termination and the value of diff --git a/nuttx/sched/getpid.c b/nuttx/sched/getpid.c index 158b29370..f41467d9f 100644 --- a/nuttx/sched/getpid.c +++ b/nuttx/sched/getpid.c @@ -2,7 +2,7 @@ * sched/getpid.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -40,6 +40,7 @@ #include #include #include + #include "os_internal.h" /************************************************************************ @@ -76,9 +77,9 @@ pid_t getpid(void) { - /* Return the task ID from the TCB at the head of the - * ready-to-run task list - */ + /* Return the task ID from the TCB at the head of the + * ready-to-run task list + */ - return ((FAR _TCB*)g_readytorun.head)->pid; + return ((FAR _TCB*)g_readytorun.head)->pid; } diff --git a/nuttx/sched/irq_attach.c b/nuttx/sched/irq_attach.c index 07ded0629..3f27a0530 100644 --- a/nuttx/sched/irq_attach.c +++ b/nuttx/sched/irq_attach.c @@ -38,7 +38,9 @@ ****************************************************************************/ #include + #include + #include "irq_internal.h" /**************************************************************************** @@ -69,8 +71,8 @@ * Name: irq_attach * * Description: - * Configure the IRQ subsystem so that IRQ number 'irq' - * is dispatched to 'isr' + * Configure the IRQ subsystem so that IRQ number 'irq' is dispatched to + * 'isr' * ****************************************************************************/ @@ -123,5 +125,3 @@ int irq_attach(int irq, xcpt_t isr) return OK; #endif } - - diff --git a/nuttx/sched/irq_dispatch.c b/nuttx/sched/irq_dispatch.c index 4b2447cbf..1c39f59d1 100644 --- a/nuttx/sched/irq_dispatch.c +++ b/nuttx/sched/irq_dispatch.c @@ -2,7 +2,7 @@ * sched/irq_dispatch.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -73,9 +73,9 @@ * Name: irq_dispatch * * Description: - * This function must be called from the achitecture- - * specific logic in order to dispaly an interrupt to - * the appropriate, registered handling logic. + * This function must be called from the achitecture-specific logic in + * order to dispatch an interrupt to the appropriate, registered handling + * logic. * ***************************************************************************/ diff --git a/nuttx/sched/irq_initialize.c b/nuttx/sched/irq_initialize.c index 48afa4431..2053dcb83 100644 --- a/nuttx/sched/irq_initialize.c +++ b/nuttx/sched/irq_initialize.c @@ -2,7 +2,7 @@ * sched/irq_initialize.c * * Copyright (C) 2007-2008, 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -40,6 +40,7 @@ #include #include #include + #include "irq_internal.h" /**************************************************************************** @@ -69,7 +70,7 @@ FAR xcpt_t g_irqvector[NR_IRQS+1]; ****************************************************************************/ /**************************************************************************** - * Function: irq_initialize + * Name: irq_initialize * * Description: * Configure the IRQ subsystem diff --git a/nuttx/sched/irq_internal.h b/nuttx/sched/irq_internal.h index 4d180ec12..28411f64f 100644 --- a/nuttx/sched/irq_internal.h +++ b/nuttx/sched/irq_internal.h @@ -2,7 +2,7 @@ * sched/irq_internal.h * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __IRQ_INTERNAL_H -#define __IRQ_INTERNAL_H +#ifndef __SCHED_IRQ_INTERNAL_H +#define __SCHED_IRQ_INTERNAL_H /**************************************************************************** * Included Files @@ -79,5 +79,5 @@ EXTERN int irq_unexpected_isr(int irq, FAR void *context); } #endif -#endif /* __IRQ_INTERNAL_H */ +#endif /* __SCHED_IRQ_INTERNAL_H */ diff --git a/nuttx/sched/irq_unexpectedisr.c b/nuttx/sched/irq_unexpectedisr.c index e00e534a3..c0090ead4 100644 --- a/nuttx/sched/irq_unexpectedisr.c +++ b/nuttx/sched/irq_unexpectedisr.c @@ -2,7 +2,7 @@ * sched/irq_unexpectedisr.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,8 +38,11 @@ ****************************************************************************/ #include -#include + #include + +#include + #include "os_internal.h" #include "irq_internal.h" @@ -68,11 +71,11 @@ ****************************************************************************/ /**************************************************************************** - * Function: irq_unexpected_isr + * Name: irq_unexpected_isr * * Description: - * An interrupt has been received for an IRQ that was - * never registered with the system. + * An interrupt has been received for an IRQ that was never registered + * with the system. * ****************************************************************************/ diff --git a/nuttx/sched/kmm_addregion.c b/nuttx/sched/kmm_addregion.c index ed923a56f..652367f5a 100644 --- a/nuttx/sched/kmm_addregion.c +++ b/nuttx/sched/kmm_addregion.c @@ -2,7 +2,7 @@ * sched/kmm_addregion.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -84,7 +84,7 @@ typedef void (*kmaddregion_t)(FAR void*, size_t); ************************************************************************/ /************************************************************************ - * Function: kmm_addregion + * Name: kmm_addregion * * Description: * This is a simple redirection to the user-space mm_addregion() diff --git a/nuttx/sched/kmm_initialize.c b/nuttx/sched/kmm_initialize.c index 59a554adc..6dd08951b 100644 --- a/nuttx/sched/kmm_initialize.c +++ b/nuttx/sched/kmm_initialize.c @@ -2,7 +2,7 @@ * sched/kmm_initialize.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -84,7 +84,7 @@ typedef void (*kminitialize_t)(FAR void*, size_t); ************************************************************************/ /************************************************************************ - * Function: kmm_initialize + * Name: kmm_initialize * * Description: * This is a simple redirection to the user-space mm_initialize() diff --git a/nuttx/sched/kmm_kfree.c b/nuttx/sched/kmm_kfree.c index 2e64be4bc..0f0eaa6c2 100644 --- a/nuttx/sched/kmm_kfree.c +++ b/nuttx/sched/kmm_kfree.c @@ -2,7 +2,7 @@ * sched/kmm_kfree.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -84,7 +84,7 @@ typedef void (*kfree_t)(FAR void *); ************************************************************************/ /************************************************************************ - * Function: kfree + * Name: kfree * * Description: * This is a simple redirection to the user-space free() function. diff --git a/nuttx/sched/kmm_kmalloc.c b/nuttx/sched/kmm_kmalloc.c index aee5306f2..5e34c157f 100644 --- a/nuttx/sched/kmm_kmalloc.c +++ b/nuttx/sched/kmm_kmalloc.c @@ -2,7 +2,7 @@ * sched/kmm_kmalloc.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -84,7 +84,7 @@ typedef FAR void *(*kmalloc_t)(size_t); ************************************************************************/ /************************************************************************ - * Function: kmalloc + * Name: kmalloc * * Description: * This is a simple redirection to the user-space malloc() function. diff --git a/nuttx/sched/kmm_krealloc.c b/nuttx/sched/kmm_krealloc.c index 91b3448b8..3d3726566 100644 --- a/nuttx/sched/kmm_krealloc.c +++ b/nuttx/sched/kmm_krealloc.c @@ -2,7 +2,7 @@ * sched/kmm_krealloc.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -84,7 +84,7 @@ typedef FAR void *(*krealloc_t)(FAR void*, size_t); ************************************************************************/ /************************************************************************ - * Function: krealloc + * Name: krealloc * * Description: * This is a simple redirection to the user-space realloc() function. diff --git a/nuttx/sched/kmm_kzalloc.c b/nuttx/sched/kmm_kzalloc.c index aba3cf26f..42bcfcc0f 100644 --- a/nuttx/sched/kmm_kzalloc.c +++ b/nuttx/sched/kmm_kzalloc.c @@ -2,7 +2,7 @@ * sched/kmm_kzalloc.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -84,7 +84,7 @@ typedef FAR void *(*kzalloc_t)(size_t); ************************************************************************/ /************************************************************************ - * Function: kzalloc + * Name: kzalloc * * Description: * This is a simple redirection to the user-space zalloc() function. diff --git a/nuttx/sched/kmm_semaphore.c b/nuttx/sched/kmm_semaphore.c index a78a0bed7..7fce747b6 100644 --- a/nuttx/sched/kmm_semaphore.c +++ b/nuttx/sched/kmm_semaphore.c @@ -2,7 +2,7 @@ * sched/kmm_semaphore.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -86,7 +86,7 @@ typedef void (*kmgivesemaphore_t)(void); ************************************************************************/ /************************************************************************ - * Function: kmm_trysemaphore + * Name: kmm_trysemaphore * * Description: * This is a simple redirection to the user-space mm_trysemaphore() @@ -112,7 +112,7 @@ int kmm_trysemaphore(void) } /************************************************************************ - * Function: kmm_givesemaphore + * Name: kmm_givesemaphore * * Description: * This is a simple redirection to the user-space mm_givesemaphore() diff --git a/nuttx/sched/mq_close.c b/nuttx/sched/mq_close.c index 4f6b0e0b5..57780a8e6 100644 --- a/nuttx/sched/mq_close.c +++ b/nuttx/sched/mq_close.c @@ -1,8 +1,8 @@ -/************************************************************ +/**************************************************************************** * sched/mq_close.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,71 +31,69 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include #include #include + #include "os_internal.h" #include "mq_internal.h" -/************************************************************ +/**************************************************************************** * Definitions - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Global Variables - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Variables - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Functions - ************************************************************/ + ****************************************************************************/ -/************************************************************ - * Function: mq_desfree +/**************************************************************************** + * Name: mq_desfree * * Description: - * Deallocate a message queue descriptor but returning it - * to the free liest + * Deallocate a message queue descriptor but returning it to the free list * * Inputs: * mqdes - message queue descriptor to free * - ************************************************************/ + ****************************************************************************/ #define mq_desfree(mqdes) sq_addlast((FAR sq_entry_t*)mqdes, &g_desfree) -/************************************************************ +/**************************************************************************** * Public Functions - ************************************************************/ + ****************************************************************************/ -/************************************************************ - * Function: mq_close +/**************************************************************************** + * Name: mq_close * * Description: - * This function is used to indicate that the calling task - * is finished with the specified message queued mqdes. - * The mq_close() deallocates any system resources - * allocated by the system for use by this task for its - * message queue. + * This function is used to indicate that the calling task is finished + * with the specified message queued mqdes. The mq_close() deallocates + * any system resources allocated by the system for use by this task for + * its message queue. * - * If the calling task has attached a notification to the - * message queue via this mqdes, this attachment will be - * removed and the message queue is available for another - * process to attach a notification. + * If the calling task has attached a notification to the message queue + * via this mqdes, this attachment will be removed and the message queue + * is available for another process to attach a notification. * * Parameters: * mqdes - Message queue descriptor. @@ -105,12 +103,12 @@ * otherwise, -1 (ERROR). * * Assumptions: - * - The behavior of a task that is blocked on either a mq_send() - * or mq_receive is undefined when mq_close() is called. - * - The results of using this message queue descriptor after a - * a successful return from mq_close() is undefined. + * - The behavior of a task that is blocked on either a mq_send() or + * mq_receive() is undefined when mq_close() is called. + * - The results of using this message queue descriptor after a successful + * return from mq_close() is undefined. * - ************************************************************/ + ****************************************************************************/ int mq_close(mqd_t mqdes) { diff --git a/nuttx/sched/mq_descreate.c b/nuttx/sched/mq_descreate.c index c8a0cfeae..14937888c 100644 --- a/nuttx/sched/mq_descreate.c +++ b/nuttx/sched/mq_descreate.c @@ -2,7 +2,7 @@ * sched/mq_descreate.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,19 +39,21 @@ #include -#include /* va_list */ +#include #include #include #include #include #include +#include #include + #include +#include + #include "os_internal.h" #include "sig_internal.h" -#include -#include #include "mq_internal.h" /**************************************************************************** @@ -75,7 +77,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: mq_desalloc + * Name: mq_desalloc * * Description: * Allocate a message queue descriptor. @@ -117,7 +119,7 @@ static mqd_t mq_desalloc(void) ****************************************************************************/ /**************************************************************************** - * Function: mq_descreate + * Name: mq_descreate * * Description: * Create a message queue descriptor for the specified TCB @@ -128,7 +130,8 @@ static mqd_t mq_desalloc(void) * oflags - access rights for the descriptor * * Return Value: - * + * On success, the message queue descriptor is returned. NULL is returned + * on a failure to allocate. * ****************************************************************************/ diff --git a/nuttx/sched/mq_findnamed.c b/nuttx/sched/mq_findnamed.c index be3830374..d23b81c5e 100644 --- a/nuttx/sched/mq_findnamed.c +++ b/nuttx/sched/mq_findnamed.c @@ -2,7 +2,7 @@ * sched/mq_findnamed.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -40,6 +40,7 @@ #include #include + #include "mq_internal.h" /************************************************************************ @@ -67,18 +68,18 @@ ************************************************************************/ /************************************************************************ - * Function: mq_findnamed + * Name: mq_findnamed * * Description: - * This function finds the named message queue with the - * specified name in the list of message queues. + * This function finds the named message queue with the specified name + * in the list of message queues. * * Inputs: * mq_name - the name of the message queue to find * * Return Value: - * A reference to the matching named message queue - * structure (or NULL if none was found). + * A reference to the matching named message queue structure (or NULL + * if none was found). * ************************************************************************/ diff --git a/nuttx/sched/mq_initialize.c b/nuttx/sched/mq_initialize.c index 2e85e148c..5b03a1120 100644 --- a/nuttx/sched/mq_initialize.c +++ b/nuttx/sched/mq_initialize.c @@ -2,7 +2,7 @@ * sched/mq_initialize.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -53,9 +53,7 @@ * Private Type Declarations ************************************************************************/ -/* This is a container for a list of message queue - * descriptors. - */ +/* This is a container for a list of message queue descriptors. */ struct mq_des_block_s { @@ -71,22 +69,22 @@ struct mq_des_block_s sq_queue_t g_msgqueues; -/* The g_msgfree is a list of messages that are available - * for general use. The number of messages in this list is a - * system configuration item. +/* The g_msgfree is a list of messages that are available for general + * use. The number of messages in this list is a system configuration + * item. */ sq_queue_t g_msgfree; -/* The g_msgfreeInt is a list of messages that are reserved - * for use by interrupt handlers. +/* The g_msgfreeInt is a list of messages that are reserved for use by + * interrupt handlers. */ sq_queue_t g_msgfreeirq; -/* The g_desfree data structure is a list of message - * descriptors available to the operating system for general use. - * The number of messages in the pool is a constant. +/* The g_desfree data structure is a list of message descriptors available + * to the operating system for general use. The number of messages in the + * pool is a constant. */ sq_queue_t g_desfree; @@ -95,21 +93,19 @@ sq_queue_t g_desfree; * Private Variables ************************************************************************/ -/* g_msgalloc is a pointer to the start of the allocated - * block of messages. +/* g_msgalloc is a pointer to the start of the allocated block of + * messages. */ static mqmsg_t *g_msgalloc; -/* g_msgfreeirqalloc is a pointer to the start of the - * allocated block of messages. +/* g_msgfreeirqalloc is a pointer to the start of the allocated block of + * messages. */ static mqmsg_t *g_msgfreeirqalloc; -/* g_desalloc is a list of allocated block of message queue - * descriptors. - */ +/* g_desalloc is a list of allocated block of message queue descriptors. */ static sq_queue_t g_desalloc; @@ -118,15 +114,14 @@ static sq_queue_t g_desalloc; ************************************************************************/ /************************************************************************ - * Function: mq_msgblockalloc + * Name: mq_msgblockalloc * * Description: - * Allocate a block of messages and place them on the free - * list. + * Allocate a block of messages and place them on the free list. * - * - * Inputs: + * Inputs Parameters: * queue + * ************************************************************************/ static mqmsg_t *mq_msgblockalloc(sq_queue_t *queue, uint16_t nmsgs, @@ -159,13 +154,12 @@ static mqmsg_t *mq_msgblockalloc(sq_queue_t *queue, uint16_t nmsgs, ************************************************************************/ /************************************************************************ - * Function: mq_initialize + * Name: mq_initialize * * Description: - * This function initializes the messasge system. This - * function must be called early in the initialization - * sequence before any of the other message interfaces - * execute. + * This function initializes the messasge system. This function must + * be called early in the initialization sequence before any of the + * other message interfaces execute. * * Inputs: * None @@ -207,7 +201,7 @@ void mq_initialize(void) } /************************************************************************ - * Function: mq_desblockalloc + * Name: mq_desblockalloc * * Description: * Allocate a block of message descriptors and place them on the free diff --git a/nuttx/sched/mq_internal.h b/nuttx/sched/mq_internal.h index c9666f683..6135bfaef 100644 --- a/nuttx/sched/mq_internal.h +++ b/nuttx/sched/mq_internal.h @@ -2,7 +2,7 @@ * sched/mq_internal.h * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -63,14 +63,14 @@ #define MQ_MAX_MSGS 16 #define MQ_PRIO_MAX _POSIX_MQ_PRIO_MAX -/* This defines the number of messages descriptors to allocate - * at each "gulp." +/* This defines the number of messages descriptors to allocate at each + * "gulp." */ #define NUM_MSG_DESCRIPTORS 24 -/* This defines the number of messages to set aside for - * exclusive use by interrupt handlers +/* This defines the number of messages to set aside for exclusive use by + * interrupt handlers */ #define NUM_INTERRUPT_MSGS 8 @@ -85,6 +85,7 @@ enum mqalloc_e MQ_ALLOC_DYN, /* dynamically allocated; free when unused */ MQ_ALLOC_IRQ /* Preallocated, reserved for interrupt handling */ }; + typedef enum mqalloc_e mqalloc_t; /* This structure describes one buffered POSIX message. */ @@ -101,6 +102,7 @@ struct mqmsg #endif uint8_t mail[MQ_MAX_BYTES]; /* Message data */ }; + typedef struct mqmsg mqmsg_t; /**************************************************************************** @@ -111,22 +113,21 @@ typedef struct mqmsg mqmsg_t; extern sq_queue_t g_msgqueues; -/* The g_msgfree is a list of messages that are available - * for general use. The number of messages in this list is a - * system configuration item. +/* The g_msgfree is a list of messages that are available for general use. + * The number of messages in this list is a system configuration item. */ extern sq_queue_t g_msgfree; -/* The g_msgfreeInt is a list of messages that are reserved - * for use by interrupt handlers. +/* The g_msgfreeInt is a list of messages that are reserved for use by + * interrupt handlers. */ extern sq_queue_t g_msgfreeirq; -/* The g_desfree data structure is a list of message - * descriptors available to the operating system for general use. - * The number of messages in the pool is a constant. +/* The g_desfree data structure is a list of message descriptors available + * to the operating system for general use. The number of messages in the + * pool is a constant. */ extern sq_queue_t g_desfree; diff --git a/nuttx/sched/mq_msgfree.c b/nuttx/sched/mq_msgfree.c index 8147dd518..91322fbf3 100644 --- a/nuttx/sched/mq_msgfree.c +++ b/nuttx/sched/mq_msgfree.c @@ -2,7 +2,7 @@ * sched/mq_msgfree.c * * Copyright (C) 2007 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -69,13 +69,12 @@ ************************************************************************/ /************************************************************************ - * Function: mq_msgfree + * Name: mq_msgfree * * Description: - * The mq_msgfree function will return a message to the - * free pool of messages if it was a pre-allocated message. - * If the message was allocated dynamically it will be - * deallocated. + * The mq_msgfree function will return a message to the free pool of + * messages if it was a pre-allocated message. If the message was + * allocated dynamically it will be deallocated. * * Inputs: * mqmsg - message to free @@ -128,7 +127,6 @@ void mq_msgfree(FAR mqmsg_t *mqmsg) { sched_free(mqmsg); } - else { PANIC(OSERR_BADMSGTYPE); diff --git a/nuttx/sched/mq_msgqfree.c b/nuttx/sched/mq_msgqfree.c index 74ba3d441..d7d87db3d 100644 --- a/nuttx/sched/mq_msgqfree.c +++ b/nuttx/sched/mq_msgqfree.c @@ -2,7 +2,7 @@ * sched/mq_msgqfree.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -68,7 +68,7 @@ ************************************************************************/ /************************************************************************ - * Function: mq_msgqfree + * Name: mq_msgqfree * * Description: * This function deallocates an initialized message queue diff --git a/nuttx/sched/mq_notify.c b/nuttx/sched/mq_notify.c index ce64d5a54..589bee312 100644 --- a/nuttx/sched/mq_notify.c +++ b/nuttx/sched/mq_notify.c @@ -72,22 +72,21 @@ ************************************************************************/ /************************************************************************ - * Function: mq_notify + * Name: mq_notify * * Description: - * If "notification" is not NULL, this function connects - * the task with the message queue such that the specified - * signal will be sent to the task whenever the message - * changes from empty to non-empty. One one notification - * can be attached to a message queue. + * If "notification" is not NULL, this function connects the task with + * the message queue such that the specified signal will be sent to the + * task whenever the message changes from empty to non-empty. Only one + * notification can be attached to a message queue. * - * If "notification" is NULL, the attached notification is - * detached (if it was held by the calling task) and the - * queue is available to attach another notification. + * If "notification" is NULL, the attached notification is detached (if + * it was held by the calling task) and the queue is available to attach + * another notification. * - * When the notification is sent to the registered process, - * its registration will be removed. The message queue - * will then be available for registration. + * When the notification is sent to the registered process, its + * registration will be removed. The message queue will then be + * available for registration. * * Parameters: * mqdes - Message queue descriptor diff --git a/nuttx/sched/mq_open.c b/nuttx/sched/mq_open.c index de9388195..5e1b9b137 100644 --- a/nuttx/sched/mq_open.c +++ b/nuttx/sched/mq_open.c @@ -2,7 +2,7 @@ * sched/mq_open.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -79,21 +79,21 @@ ****************************************************************************/ /**************************************************************************** - * Function: mq_open + * Name: mq_open * * Description: - * This function establish a connection between a named - * message queue and the calling task. After a successful - * call of mq_open(), the task can reference the message - * queue using the address returned by the call. The - * message queue remains usable until it is closed by a - * successful call to mq_close(). + * This function establish a connection between a named message queue and + * the calling task. After a successful call of mq_open(), the task can + * reference the message queue using the address returned by the call. The + * message queue remains usable until it is closed by a successful call to + * mq_close(). * * Parameters: * mq_name - Name of the queue to open * oflags - open flags - * Optional parameters. When the O_CREAT flag is - * specified, two optional parameters are expected: + * Optional parameters. When the O_CREAT flag is specified, two optional + * parameters are expected: + * * 1. mode_t mode (ignored), and * 2. struct mq_attr *attr. The mq_maxmsg attribute * is used at the time that the message queue is @@ -221,6 +221,7 @@ mqd_t mq_open(const char *mq_name, int oflags, ...) } } } + sched_unlock(); } diff --git a/nuttx/sched/mq_rcvinternal.c b/nuttx/sched/mq_rcvinternal.c index 8ec066da8..e80685e87 100644 --- a/nuttx/sched/mq_rcvinternal.c +++ b/nuttx/sched/mq_rcvinternal.c @@ -81,9 +81,9 @@ * Name: mq_verifyreceive * * Description: - * This is internal, common logic shared by both mq_receive - * and mq_timedreceive. This function verifies the - * input parameters that are common to both functions. + * This is internal, common logic shared by both mq_receive and + * mq_timedreceive. This function verifies the input parameters that are + * common to both functions. * * Parameters: * mqdes - Message Queue Descriptor @@ -91,12 +91,12 @@ * msglen - Size of the buffer in bytes * * Return Value: - * One success, 0 (OK) is returned. On failure, -1 (ERROR) is - * returned and the errno is set appropriately: + * One success, 0 (OK) is returned. On failure, -1 (ERROR) is returned and + * the errno is set appropriately: * * EPERM Message queue opened not opened for reading. - * EMSGSIZE 'msglen' was less than the maxmsgsize attribute of the - * message queue. + * EMSGSIZE 'msglen' was less than the maxmsgsize attribute of the message + * queue. * EINVAL Invalid 'msg' or 'mqdes' * * Assumptions: @@ -129,30 +129,28 @@ int mq_verifyreceive(mqd_t mqdes, void *msg, size_t msglen) } /**************************************************************************** - * Function: mq_waitreceive + * Name: mq_waitreceive * * Description: - * This is internal, common logic shared by both mq_receive - * and mq_timedreceive. This function waits for a message to - * be received on the specified message queue, removes the - * message from the queue, and returns it. + * This is internal, common logic shared by both mq_receive and + * mq_timedreceive. This function waits for a message to be received on + * the specified message queue, removes the message from the queue, and + * returns it. * * Parameters: * mqdes - Message queue descriptor * * Return Value: - * On success, a reference to the received message. If the - * wait was interrupted by a signal or a timeout, then the - * errno will be set appropriately and NULL will be returned. + * On success, a reference to the received message. If the wait was + * interrupted by a signal or a timeout, then the errno will be set + * appropriately and NULL will be returned. * * Assumptions: - * - The caller has provided all validity checking of the - * input parameters using mq_verifyreceive. - * - Interrupts should be disabled throughout this call. This - * is necessary because messages can be sent from interrupt - * level processing. - * - For mq_timedreceive, setting of the timer and this wait - * must be atomic. + * - The caller has provided all validity checking of the input parameters + * using mq_verifyreceive. + * - Interrupts should be disabled throughout this call. This is necessary + * because messages can be sent from interrupt level processing. + * - For mq_timedreceive, setting of the timer and this wait must be atomic. * ****************************************************************************/ @@ -215,38 +213,34 @@ FAR mqmsg_t *mq_waitreceive(mqd_t mqdes) { msgq->nmsgs--; } + return rcvmsg; } /**************************************************************************** - * Function: mq_doreceive + * Name: mq_doreceive * * Description: - * This is internal, common logic shared by both mq_receive - * and mq_timedreceive. This function accepts the message - * obtained by mq_waitmsg, provides the message content to - * the user, notifies any threads that were waiting for - * the message queue to become non-full, and disposes of the - * message structure + * This is internal, common logic shared by both mq_receive and + * mq_timedreceive. This function accepts the message obtained by + * mq_waitmsg, provides the message content to the user, notifies any + * threads that were waiting for the message queue to become non-full, + * and disposes of the message structure * * Parameters: * mqdes - Message queue descriptor * mqmsg - The message obtained by mq_waitmsg() - * ubuffer - The address of the user provided buffer to - * receive the message - * prio - The user-provided location to return the - * message priority. + * ubuffer - The address of the user provided buffer to receive the message + * prio - The user-provided location to return the message priority. * * Return Value: - * Returns the length of the received message. This - * function does not fail. + * Returns the length of the received message. This function does not fail. * * Assumptions: - * - The caller has provided all validity checking of the - * input parameters using mq_verifyreceive. - * - The user buffer, ubuffer, is known to be large enough - * to accept the largest message that an be sent on this - * message queue + * - The caller has provided all validity checking of the input parameters + * using mq_verifyreceive. + * - The user buffer, ubuffer, is known to be large enough to accept the + * largest message that an be sent on this message queue * - Pre-emption should be disabled throughout this call. * ****************************************************************************/ @@ -308,6 +302,7 @@ ssize_t mq_doreceive(mqd_t mqdes, mqmsg_t *mqmsg, void *ubuffer, int *prio) msgq->nwaitnotfull--; up_unblock_task(btcb); } + irqrestore(saved_state); } diff --git a/nuttx/sched/mq_receive.c b/nuttx/sched/mq_receive.c index aff9e3be8..760433446 100644 --- a/nuttx/sched/mq_receive.c +++ b/nuttx/sched/mq_receive.c @@ -2,7 +2,7 @@ * sched/mq_receive.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -73,25 +73,22 @@ ************************************************************************/ /************************************************************************ - * Function: mq_receive + * Name: mq_receive * * Description: - * This function receives the oldest of the highest - * priority messages from the message queue specified by - * "mqdes." If the size of the buffer in bytes (msglen) is - * less than the "mq_msgsize" attribute of the message - * queue, mq_receive will return an error. Otherwise, the - * selected message is removed from the queue and copied to - * "msg." + * This function receives the oldest of the highest priority messages + * from the message queue specified by "mqdes." If the size of the + * buffer in bytes (msglen) is less than the "mq_msgsize" attribute of + * the message queue, mq_receive will return an error. Otherwise, the + * selected message is removed from the queue and copied to "msg." * - * If the message queue is empty and O_NONBLOCK was not - * set, mq_receive() will block until a message is added - * to the message queue. If more than one task is waiting - * to receive a message, only the task with the highest - * priority that has waited the longest will be unblocked. + * If the message queue is empty and O_NONBLOCK was not set, + * mq_receive() will block until a message is added to the message + * queue. If more than one task is waiting to receive a message, only + * the task with the highest priority that has waited the longest will + * be unblocked. * - * If the queue is empty and O_NONBLOCK is set, ERROR will - * be returned. + * If the queue is empty and O_NONBLOCK is set, ERROR will be returned. * * Parameters: * mqdes - Message Queue Descriptor @@ -100,9 +97,8 @@ * prio - If not NULL, the location to store message priority. * * Return Value: - * One success, the length of the selected message in bytes.is - * returned. On failure, -1 (ERROR) is returned and the errno - * is set appropriately: + * One success, the length of the selected message in bytes is returned. + * On failure, -1 (ERROR) is returned and the errno is set appropriately: * * EAGAIN The queue was empty, and the O_NONBLOCK flag was set * for the message queue description referred to by 'mqdes'. diff --git a/nuttx/sched/mq_send.c b/nuttx/sched/mq_send.c index 921ff7fcc..40628e924 100644 --- a/nuttx/sched/mq_send.c +++ b/nuttx/sched/mq_send.c @@ -74,7 +74,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: mq_send + * Name: mq_send * * Description: * This function adds the specificied message (msg) to the message queue diff --git a/nuttx/sched/mq_sndinternal.c b/nuttx/sched/mq_sndinternal.c index 3d9c88769..51f898875 100644 --- a/nuttx/sched/mq_sndinternal.c +++ b/nuttx/sched/mq_sndinternal.c @@ -134,11 +134,12 @@ int mq_verifysend(mqd_t mqdes, const void *msg, size_t msglen, int prio) } /**************************************************************************** - * Function: mq_msgalloc + * Name: mq_msgalloc * * Description: * The mq_msgalloc function will get a free message for use by the - * operating system. The message will be allocated from the g_msgfree list. + * operating system. The message will be allocated from the g_msgfree + * list. * * If the list is empty AND the message is NOT being allocated from the * interrupt level, then the message will be allocated. If a message @@ -221,7 +222,7 @@ FAR mqmsg_t *mq_msgalloc(void) } /**************************************************************************** - * Function: mq_waitsend + * Name: mq_waitsend * * Description: * This is internal, common logic shared by both mq_send and mq_timesend. @@ -311,7 +312,7 @@ int mq_waitsend(mqd_t mqdes) } /**************************************************************************** - * Function: mq_dosend + * Name: mq_dosend * * Description: * This is internal, common logic shared by both mq_send and mq_timesend. diff --git a/nuttx/sched/mq_timedreceive.c b/nuttx/sched/mq_timedreceive.c index 856c08be5..0df904830 100644 --- a/nuttx/sched/mq_timedreceive.c +++ b/nuttx/sched/mq_timedreceive.c @@ -2,7 +2,7 @@ * sched/mq_timedreceive.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -47,6 +47,7 @@ #include #include #include + #include #include "os_internal.h" @@ -74,7 +75,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: mq_rcvtimeout + * Name: mq_rcvtimeout * * Description: * This function is called if the timeout elapses before the message queue @@ -96,15 +97,14 @@ static void mq_rcvtimeout(int argc, uint32_t pid) FAR _TCB *wtcb; irqstate_t saved_state; - /* Disable interrupts. This is necessary because an - * interrupt handler may attempt to send a message while we are - * doing this. + /* Disable interrupts. This is necessary because an interrupt handler may + * attempt to send a message while we are doing this. */ saved_state = irqsave(); - /* Get the TCB associated with this pid. It is possible that - * task may no longer be active when this watchdog goes off. + /* Get the TCB associated with this pid. It is possible that task may no + * longer be active when this watchdog goes off. */ wtcb = sched_gettcb((pid_t)pid); @@ -130,35 +130,30 @@ static void mq_rcvtimeout(int argc, uint32_t pid) ****************************************************************************/ /**************************************************************************** - * Function: mq_timedreceive + * Name: mq_timedreceive * * Description: - * This function receives the oldest of the highest - * priority messages from the message queue specified by - * "mqdes." If the size of the buffer in bytes (msglen) is - * less than the "mq_msgsize" attribute of the message - * queue, mq_timedreceive will return an error. Otherwise, the - * selected message is removed from the queue and copied to - * "msg." + * This function receives the oldest of the highest priority messages from + * the message queue specified by "mqdes." If the size of the buffer in + * bytes (msglen) is less than the "mq_msgsize" attribute of the message + * queue, mq_timedreceive will return an error. Otherwise, the selected + * message is removed from the queue and copied to "msg." * - * If the message queue is empty and O_NONBLOCK was not - * set, mq_timedreceive() will block until a message is added - * to the message queue (or until a timeout occurs). If more - * than one task is waiting to receive a message, only the - * task with the highest priority that has waited the longest - * will be unblocked. + * If the message queue is empty and O_NONBLOCK was not set, + * mq_timedreceive() will block until a message is added to the message + * queue (or until a timeout occurs). If more than one task is waiting + * to receive a message, only the task with the highest priority that has + * waited the longest will be unblocked. * - * mq_timedreceive() behaves just like mq_receive(), except - * that if the queue is empty and the O_NONBLOCK flag is not - * enabled for the message queue description, then abstime - * points to a structure which specifies a ceiling on the time - * for which the call will block. This ceiling is an absolute - * timeout in seconds and nanoseconds since the Epoch (midnight + * mq_timedreceive() behaves just like mq_receive(), except that if the + * queue is empty and the O_NONBLOCK flag is not enabled for the message + * queue description, then abstime points to a structure which specifies a + * ceiling on the time for which the call will block. This ceiling is an + * absolute timeout in seconds and nanoseconds since the Epoch (midnight * on the morning of 1 January 1970). * - * If no message is available, and the timeout has already - * expired by the time of the call, mq_timedreceive() returns - * immediately. + * If no message is available, and the timeout has already expired by the + * time of the call, mq_timedreceive() returns immediately. * * Parameters: * mqdes - Message Queue Descriptor @@ -168,9 +163,8 @@ static void mq_rcvtimeout(int argc, uint32_t pid) * abstime - the absolute time to wait until a timeout is declared. * * Return Value: - * One success, the length of the selected message in bytes.is - * returned. On failure, -1 (ERROR) is returned and the errno - * is set appropriately: + * One success, the length of the selected message in bytes is returned. + * On failure, -1 (ERROR) is returned and the errno is set appropriately: * * EAGAIN The queue was empty, and the O_NONBLOCK flag was set * for the message queue description referred to by 'mqdes'. diff --git a/nuttx/sched/mq_timedsend.c b/nuttx/sched/mq_timedsend.c index 4f329d311..745cc6272 100644 --- a/nuttx/sched/mq_timedsend.c +++ b/nuttx/sched/mq_timedsend.c @@ -2,7 +2,7 @@ * sched/mq_timedsend.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -74,7 +74,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: mq_sndtimeout + * Name: mq_sndtimeout * * Description: * This function is called if the timeout elapses before the message queue @@ -96,15 +96,14 @@ static void mq_sndtimeout(int argc, uint32_t pid) FAR _TCB *wtcb; irqstate_t saved_state; - /* Disable interrupts. This is necessary because an - * interrupt handler may attempt to send a message while we are - * doing this. + /* Disable interrupts. This is necessary because an interrupt handler may + * attempt to send a message while we are doing this. */ saved_state = irqsave(); - /* Get the TCB associated with this pid. It is possible that - * task may no longer be active when this watchdog goes off. + /* Get the TCB associated with this pid. It is possible that task may no + * longer be active when this watchdog goes off. */ wtcb = sched_gettcb((pid_t)pid); @@ -130,7 +129,7 @@ static void mq_sndtimeout(int argc, uint32_t pid) ****************************************************************************/ /**************************************************************************** - * Function: mq_send + * Name: mq_send * * Description: * This function adds the specificied message (msg) to the message queue diff --git a/nuttx/sched/mq_unlink.c b/nuttx/sched/mq_unlink.c index 0f1e63e48..1fa25dfa8 100644 --- a/nuttx/sched/mq_unlink.c +++ b/nuttx/sched/mq_unlink.c @@ -2,7 +2,7 @@ * sched.mq_unlink.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -71,14 +71,13 @@ ************************************************************************/ /************************************************************************ - * Function: mq_unlink + * Name: mq_unlink * * Description: - * This function removes the message queue named by - * "mq_name." If one or more tasks have the message queue - * open when mq_unlink() is called, removal of the message - * queue is postponed until all references to the message - * queue have been closed. + * This function removes the message queue named by "mq_name." If one + * or more tasks have the message queue open when mq_unlink() is called, + * removal of the message queue is postponed until all references to the + * message queue have been closed. * * Parameters: * mq_name - Name of the message queue @@ -138,6 +137,7 @@ int mq_unlink(const char *mq_name) ret = OK; } + sched_unlock(); } diff --git a/nuttx/sched/mq_waitirq.c b/nuttx/sched/mq_waitirq.c index 69f09a4f1..94a15df3c 100644 --- a/nuttx/sched/mq_waitirq.c +++ b/nuttx/sched/mq_waitirq.c @@ -2,7 +2,7 @@ * sched/mq_waitirq.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sem_waitirq + * Name: sem_waitirq * * Description: * This function is called when a signal or a timeout is received by a diff --git a/nuttx/sched/on_exit.c b/nuttx/sched/on_exit.c index f91eb2e11..8c08026fd 100644 --- a/nuttx/sched/on_exit.c +++ b/nuttx/sched/on_exit.c @@ -80,7 +80,7 @@ ************************************************************************/ /************************************************************************ - * Function: atexit + * Name: atexit * * Description: * Registers a function to be called at program exit. diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h index b7376eb1e..13b8083cf 100644 --- a/nuttx/sched/os_internal.h +++ b/nuttx/sched/os_internal.h @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __OS_INTERNAL_H -#define __OS_INTERNAL_H +#ifndef __SCHED_OS_INTERNAL_H +#define __SCHED_OS_INTERNAL_H /**************************************************************************** * Included Files @@ -46,6 +46,7 @@ #include #include #include + #include /**************************************************************************** @@ -141,6 +142,7 @@ struct pidhash_s FAR _TCB *tcb; pid_t pid; }; + typedef struct pidhash_s pidhash_t; /* This structure defines an element of the g_tasklisttable[]. @@ -153,6 +155,7 @@ struct tasklist_s DSEG volatile dq_queue_t *list; /* Pointer to the task list */ bool prioritized; /* true if the list is prioritized */ }; + typedef struct tasklist_s tasklist_t; /**************************************************************************** @@ -161,27 +164,25 @@ typedef struct tasklist_s tasklist_t; /* Declared in os_start.c ***************************************************/ -/* The state of a task is indicated both by the task_state field - * of the TCB and by a series of task lists. All of these - * tasks lists are declared below. Although it is not always - * necessary, most of these lists are prioritized so that common - * list handling logic can be used (only the g_readytorun, - * the g_pendingtasks, and the g_waitingforsemaphore lists need +/* The state of a task is indicated both by the task_state field of the TCB + * and by a series of task lists. All of these tasks lists are declared + * below. Although it is not always necessary, most of these lists are + * prioritized so that common list handling logic can be used (only the + * g_readytorun, the g_pendingtasks, and the g_waitingforsemaphore lists need * to be prioritized). */ -/* This is the list of all tasks that are ready to run. The head - * of this list is the currently active task; the tail of this - * list is always the idle task. +/* This is the list of all tasks that are ready to run. The head of this + * list is the currently active task; the tail of this list is always the + * IDLE task. */ extern volatile dq_queue_t g_readytorun; -/* This is the list of all tasks that are ready-to-run, but - * cannot be placed in the g_readytorun list because: (1) They - * are higher priority than the currently active task at the head - * of the g_readytorun list, and (2) the currenly active task has - * disabled pre-emption. +/* This is the list of all tasks that are ready-to-run, but cannot be placed + * in the g_readytorun list because: (1) They are higher priority than the + * currently active task at the head of the g_readytorun list, and (2) the + * currently active task has disabled pre-emption. */ extern volatile dq_queue_t g_pendingtasks; @@ -238,21 +239,20 @@ extern volatile pid_t g_lastpid; /* The following hash table is used for two things: * - * 1. This hash table greatly speeds the determination of - * a new unique process ID for a task, and + * 1. This hash table greatly speeds the determination of a new unique + * process ID for a task, and * 2. Is used to quickly map a process ID into a TCB. * - * It has the side effects of using more memory and limiting - * the number of tasks to CONFIG_MAX_TASKS. + * It has the side effects of using more memory and limiting the number + * of tasks to CONFIG_MAX_TASKS. */ extern pidhash_t g_pidhash[CONFIG_MAX_TASKS]; -/* This is a table of task lists. This table is indexed by - * the task state enumeration type (tstate_t) and provides - * a pointer to the associated static task list (if there - * is one) as well as a boolean indication as to if the list - * is an ordered list or not. +/* This is a table of task lists. This table is indexed by the task state + * enumeration type (tstate_t) and provides a pointer to the associated + * static task list (if there is one) as well as a boolean indication as to + * if the list is an ordered list or not. */ extern const tasklist_t g_tasklisttable[NUM_TASK_STATES]; @@ -261,47 +261,46 @@ extern const tasklist_t g_tasklisttable[NUM_TASK_STATES]; * Public Function Prototypes ****************************************************************************/ -extern int os_bringup(void); -extern void task_start(void); -extern int task_schedsetup(FAR _TCB *tcb, int priority, start_t start, - main_t main); -extern int task_argsetup(FAR _TCB *tcb, const char *name, const char *argv[]); -extern void task_exithook(FAR _TCB *tcb, int status); -extern int task_deletecurrent(void); +int os_bringup(void); +void task_start(void); +int task_schedsetup(FAR _TCB *tcb, int priority, start_t start, + main_t main); +int task_argsetup(FAR _TCB *tcb, FAR const char *name, FAR const char *argv[]); +void task_exithook(FAR _TCB *tcb, int status); +int task_deletecurrent(void); #ifndef CONFIG_CUSTOM_STACK -extern int kernel_thread(const char *name, int priority, - int stack_size, main_t entry, const char *argv[]); +int kernel_thread(FAR const char *name, int priority, int stack_size, + main_t entry, FAR const char *argv[]); #else -extern int kernel_thread(const char *name, int priority, - main_t entry, const char *argv[]); +int kernel_thread(FAR const char *name, int priority, main_t entry, + FAR const char *argv[]); #endif -extern bool sched_addreadytorun(FAR _TCB *rtrtcb); -extern bool sched_removereadytorun(FAR _TCB *rtrtcb); -extern bool sched_addprioritized(FAR _TCB *newTcb, DSEG dq_queue_t *list); -extern bool sched_mergepending(void); -extern void sched_addblocked(FAR _TCB *btcb, tstate_t task_state); -extern void sched_removeblocked(FAR _TCB *btcb); -extern int sched_setpriority(FAR _TCB *tcb, int sched_priority); +bool sched_addreadytorun(FAR _TCB *rtrtcb); +bool sched_removereadytorun(FAR _TCB *rtrtcb); +bool sched_addprioritized(FAR _TCB *newTcb, DSEG dq_queue_t *list); +bool sched_mergepending(void); +void sched_addblocked(FAR _TCB *btcb, tstate_t task_state); +void sched_removeblocked(FAR _TCB *btcb); +int sched_setpriority(FAR _TCB *tcb, int sched_priority); #ifdef CONFIG_PRIORITY_INHERITANCE -extern int sched_reprioritize(FAR _TCB *tcb, int sched_priority); +int sched_reprioritize(FAR _TCB *tcb, int sched_priority); #else # define sched_reprioritize(tcb,sched_priority) sched_setpriority(tcb,sched_priority) #endif -extern FAR _TCB *sched_gettcb(pid_t pid); -extern bool sched_verifytcb(FAR _TCB *tcb); +FAR _TCB *sched_gettcb(pid_t pid); +bool sched_verifytcb(FAR _TCB *tcb); #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 -extern int sched_setupidlefiles(FAR _TCB *tcb); -extern int sched_setuptaskfiles(FAR _TCB *tcb); -extern int sched_setuppthreadfiles(FAR _TCB *tcb); -#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 -extern int sched_setupstreams(FAR _TCB *tcb); -extern int sched_flushfiles(FAR _TCB *tcb); +int sched_setupidlefiles(FAR _TCB *tcb); +int sched_setuptaskfiles(FAR _TCB *tcb); +int sched_setuppthreadfiles(FAR _TCB *tcb); +#if CONFIG_NFILE_STREAMS > 0 +int sched_setupstreams(FAR _TCB *tcb); #endif -extern int sched_releasefiles(FAR _TCB *tcb); +int sched_releasefiles(FAR _TCB *tcb); #endif -extern int sched_releasetcb(FAR _TCB *tcb); -extern void sched_garbagecollection(void); +int sched_releasetcb(FAR _TCB *tcb); +void sched_garbagecollection(void); -#endif /* __OS_INTERNAL_H */ +#endif /* __SCHED_OS_INTERNAL_H */ diff --git a/nuttx/sched/os_start.c b/nuttx/sched/os_start.c index 2f154c6ec..6cd508b8c 100644 --- a/nuttx/sched/os_start.c +++ b/nuttx/sched/os_start.c @@ -77,27 +77,25 @@ ****************************************************************************/ /* Task Lists ***************************************************************/ -/* The state of a task is indicated both by the task_state field - * of the TCB and by a series of task lists. All of these - * tasks lists are declared below. Although it is not always - * necessary, most of these lists are prioritized so that common - * list handling logic can be used (only the g_readytorun, - * the g_pendingtasks, and the g_waitingforsemaphore lists need +/* The state of a task is indicated both by the task_state field of the TCB + * and by a series of task lists. All of these tasks lists are declared + * below. Although it is not always necessary, most of these lists are + * prioritized so that common list handling logic can be used (only the + * g_readytorun, the g_pendingtasks, and the g_waitingforsemaphore lists need * to be prioritized). */ -/* This is the list of all tasks that are ready to run. The head - * of this list is the currently active task; the tail of this - * list is always the idle task. +/* This is the list of all tasks that are ready to run. The head of this + * list is the currently active task; the tail of this list is always the + * IDLE task. */ volatile dq_queue_t g_readytorun; -/* This is the list of all tasks that are ready-to-run, but - * cannot be placed in the g_readytorun list because: (1) They - * are higher priority than the currently active task at the head - * of the g_readytorun list, and (2) the currenly active task has - * disabled pre-emption. +/* This is the list of all tasks that are ready-to-run, but cannot be placed + * in the g_readytorun list because: (1) They are higher priority than the + * currently active task at the head of the g_readytorun list, and (2) the + * currently active task has disabled pre-emption. */ volatile dq_queue_t g_pendingtasks; @@ -197,11 +195,10 @@ const tasklist_t g_tasklisttable[NUM_TASK_STATES] = /**************************************************************************** * Private Variables ****************************************************************************/ -/* This is the task control block for this thread of execution. - * This thread of execution is the idle task. NOTE: the - * system boots into the idle task. The idle task spawns - * the user init task and the user init task is responsible - * for bringing up the rest of the system +/* This is the task control block for this thread of execution. This thread + * of execution is the IDLE task. NOTE: the system boots into the IDLE + * task. The IDLE task spawns the user initialization task (user_start) and + * that user init task is responsible for bringing up the rest of the system */ static FAR _TCB g_idletcb; @@ -219,10 +216,12 @@ static FAR const char g_idlename[] = "Idle Task"; ****************************************************************************/ /**************************************************************************** - * Name: os_start - * Description: This function is called to initialize the - * operating system and to spawn the user init thread of - * execution + * Name: os_start + * + * Description: + * This function is called to initialize the operating system and to spawn + * the user initization thread of execution + * ****************************************************************************/ void os_start(void) diff --git a/nuttx/sched/pg_internal.h b/nuttx/sched/pg_internal.h index 6ea35eed4..e7bafcd91 100644 --- a/nuttx/sched/pg_internal.h +++ b/nuttx/sched/pg_internal.h @@ -2,7 +2,7 @@ * sched/pg_internal.h * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -119,7 +119,7 @@ extern FAR _TCB *g_pftcb; * ****************************************************************************/ -extern int pg_worker(int argc, char *argv[]); +int pg_worker(int argc, char *argv[]); #endif /* __ASSEMBLY__ */ #endif /* CONFIG_PAGING */ diff --git a/nuttx/sched/pg_miss.c b/nuttx/sched/pg_miss.c index 7abf0e2c2..8a649a6d5 100644 --- a/nuttx/sched/pg_miss.c +++ b/nuttx/sched/pg_miss.c @@ -2,7 +2,7 @@ * sched/pg_miss.c * * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/sched/pg_worker.c b/nuttx/sched/pg_worker.c index c9c175b5a..4a18ec9a3 100644 --- a/nuttx/sched/pg_worker.c +++ b/nuttx/sched/pg_worker.c @@ -3,7 +3,7 @@ * Page fill worker thread implementation. * * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -81,10 +81,9 @@ pid_t g_pgworker; -/* The page fill worker thread maintains a static variable called - * g_pftcb. If no fill is in progress, g_pftcb will be NULL. - * Otherwise, g_pftcb will point to the TCB of the task which is - * receiving the fill that is in progess. +/* The page fill worker thread maintains a static variable called g_pftcb. + * If no fill is in progress, g_pftcb will be NULL. Otherwise, g_pftcb will + * point to the TCB of the task which is receiving the fill that is in progess. * * NOTE: I think that this is the only state in which a TCB does not reside * in some list. Here is it in limbo, outside of the normally queuing while @@ -178,26 +177,27 @@ static void pg_callback(FAR _TCB *tcb, int result) priority = htcb->sched_priority; } - /* If this higher priority is higher than current page fill worker - * thread, then boost worker thread's priority to that level. Thus, - * the page fill worker thread will always run at the priority of - * the highest priority task that is waiting for a fill. - */ + /* If this higher priority is higher than current page fill worker + * thread, then boost worker thread's priority to that level. Thus, + * the page fill worker thread will always run at the priority of + * the highest priority task that is waiting for a fill. + */ - if (priority > wtcb->sched_priority) - { - pgllvdbg("New worker priority. %d->%d\n", - wtcb->sched_priority, priority); - sched_setpriority(wtcb, priority); - } + if (priority > wtcb->sched_priority) + { + pgllvdbg("New worker priority. %d->%d\n", + wtcb->sched_priority, priority); + sched_setpriority(wtcb, priority); + } - /* Save the page fill result (don't permit the value -EBUSY) */ + /* Save the page fill result (don't permit the value -EBUSY) */ - if (result == -EBUSY) - { - result = -ENOSYS; - } - g_fillresult = result; + if (result == -EBUSY) + { + result = -ENOSYS; + } + + g_fillresult = result; } /* Signal the page fill worker thread (in any event) */ @@ -262,50 +262,50 @@ static inline bool pg_dequeue(void) if (!up_checkmapping(g_pftcb)) { - /* This page needs to be filled. pg_miss bumps up - * the priority of the page fill worker thread as each - * TCB is added to the g_waitingforfill list. So we - * may need to also drop the priority of the worker - * thread as the next TCB comes off of the list. - * - * If wtcb->sched_priority > CONFIG_PAGING_DEFPRIO, - * then the page fill worker thread is executing at - * an elevated priority that may be reduced. - * - * If wtcb->sched_priority > g_pftcb->sched_priority - * then the page fill worker thread is executing at - * a higher priority than is appropriate for this - * fill (this priority can get re-boosted by pg_miss() - * if a new higher priority fill is required). - */ + /* This page needs to be filled. pg_miss bumps up + * the priority of the page fill worker thread as each + * TCB is added to the g_waitingforfill list. So we + * may need to also drop the priority of the worker + * thread as the next TCB comes off of the list. + * + * If wtcb->sched_priority > CONFIG_PAGING_DEFPRIO, + * then the page fill worker thread is executing at + * an elevated priority that may be reduced. + * + * If wtcb->sched_priority > g_pftcb->sched_priority + * then the page fill worker thread is executing at + * a higher priority than is appropriate for this + * fill (this priority can get re-boosted by pg_miss() + * if a new higher priority fill is required). + */ - FAR _TCB *wtcb = (FAR _TCB *)g_readytorun.head; - if (wtcb->sched_priority > CONFIG_PAGING_DEFPRIO && - wtcb->sched_priority > g_pftcb->sched_priority) - { - /* Don't reduce the priority of the page fill - * worker thread lower than the configured - * minimum. - */ + FAR _TCB *wtcb = (FAR _TCB *)g_readytorun.head; + if (wtcb->sched_priority > CONFIG_PAGING_DEFPRIO && + wtcb->sched_priority > g_pftcb->sched_priority) + { + /* Don't reduce the priority of the page fill + * worker thread lower than the configured + * minimum. + */ - int priority = g_pftcb->sched_priority; - if (priority < CONFIG_PAGING_DEFPRIO) - { - priority = CONFIG_PAGING_DEFPRIO; - } + int priority = g_pftcb->sched_priority; + if (priority < CONFIG_PAGING_DEFPRIO) + { + priority = CONFIG_PAGING_DEFPRIO; + } - /* Reduce the priority of the page fill worker thread */ + /* Reduce the priority of the page fill worker thread */ - pgllvdbg("New worker priority. %d->%d\n", - wtcb->sched_priority, priority); - sched_setpriority(wtcb, priority); - } + pgllvdbg("New worker priority. %d->%d\n", + wtcb->sched_priority, priority); + sched_setpriority(wtcb, priority); + } - /* Return with g_pftcb holding the pointer to - * the TCB associated with task that requires the page fill. - */ + /* Return with g_pftcb holding the pointer to + * the TCB associated with task that requires the page fill. + */ - return true; + return true; } /* The page need by this task has already been mapped into the @@ -317,6 +317,7 @@ static inline bool pg_dequeue(void) } } while (g_pftcb != NULL); + return false; } @@ -421,6 +422,7 @@ static inline bool pg_startfill(void) * task must still be available to run. */ #endif /* CONFIG_PAGING_BLOCKINGFILL */ + return true; } @@ -670,6 +672,7 @@ int pg_worker(int argc, char *argv[]) pg_alldone(); #endif } + return OK; /* To keep some compilers happy */ } #endif /* CONFIG_PAGING */ diff --git a/nuttx/sched/prctl.c b/nuttx/sched/prctl.c index 817083561..b340d0ec8 100644 --- a/nuttx/sched/prctl.c +++ b/nuttx/sched/prctl.c @@ -46,6 +46,7 @@ #include #include + #include "os_internal.h" /************************************************************************ diff --git a/nuttx/sched/pthread_barrierdestroy.c b/nuttx/sched/pthread_barrierdestroy.c index 6720b9d99..40e8e875c 100644 --- a/nuttx/sched/pthread_barrierdestroy.c +++ b/nuttx/sched/pthread_barrierdestroy.c @@ -2,7 +2,7 @@ * sched/pthread_barriedestroy.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -69,7 +69,7 @@ ********************************************************************************/ /******************************************************************************** - * Function: pthread_barrier_destroy + * Name: pthread_barrier_destroy * * Description: * The pthread_barrier_destroy() function destroys the barrier referenced by diff --git a/nuttx/sched/pthread_barrierinit.c b/nuttx/sched/pthread_barrierinit.c index 1d8dd00c3..73b974b18 100644 --- a/nuttx/sched/pthread_barrierinit.c +++ b/nuttx/sched/pthread_barrierinit.c @@ -2,7 +2,7 @@ * sched/pthread_barrieinit.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -69,7 +69,7 @@ ********************************************************************************/ /******************************************************************************** - * Function: pthread_barrier_init + * Name: pthread_barrier_init * * Description: * The pthread_barrier_init() function allocates any resources required to use @@ -117,5 +117,6 @@ int pthread_barrier_init(FAR pthread_barrier_t *barrier, sem_init(&barrier->sem, 0, 0); barrier->count = count; } + return ret; } diff --git a/nuttx/sched/pthread_barrierwait.c b/nuttx/sched/pthread_barrierwait.c index b8588aff0..8ca8d1754 100644 --- a/nuttx/sched/pthread_barrierwait.c +++ b/nuttx/sched/pthread_barrierwait.c @@ -2,7 +2,7 @@ * sched/pthread_barrierwait.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -70,7 +70,7 @@ ********************************************************************************/ /******************************************************************************** - * Function: pthread_barrier_wait + * Name: pthread_barrier_wait * * Description: * The pthread_barrier_wait() function synchronizse participating threads at @@ -159,7 +159,7 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier) { /* If the thread is awakened by a signal, just continue to wait */ - int errornumber = *get_errno_ptr(); + int errornumber = get_errno(); if (errornumber != EINTR) { /* If it is awakened by some other error, then there is a diff --git a/nuttx/sched/pthread_cancel.c b/nuttx/sched/pthread_cancel.c index 2ff1daf87..5e34eeaba 100644 --- a/nuttx/sched/pthread_cancel.c +++ b/nuttx/sched/pthread_cancel.c @@ -2,7 +2,7 @@ * sched/pthread_cancel.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -123,6 +123,7 @@ int pthread_cancel(pthread_t thread) sched_unlock(); return OK; } + sched_unlock(); /* Check to see if the ID refers to ourselves.. this would be the diff --git a/nuttx/sched/pthread_completejoin.c b/nuttx/sched/pthread_completejoin.c index fa7c2a443..7c5191034 100644 --- a/nuttx/sched/pthread_completejoin.c +++ b/nuttx/sched/pthread_completejoin.c @@ -69,12 +69,12 @@ ************************************************************************/ /************************************************************************ - * Function: pthread_notifywaiters + * Name: pthread_notifywaiters * * Description: - * Notify all other threads waiting in phread join for this - * thread's exit data. This must be done by the child - * at child thread destruction time. + * Notify all other threads waiting in phread join for this thread's + * exit data. This must be done by the child at child thread + * destruction time. * ************************************************************************/ @@ -117,6 +117,7 @@ static bool pthread_notifywaiters(FAR join_t *pjoin) (void)pthread_takesemaphore(&pjoin->data_sem); return true; } + return false; } @@ -125,20 +126,20 @@ static bool pthread_notifywaiters(FAR join_t *pjoin) ************************************************************************/ /************************************************************************ - * Function: pthread_completejoin + * Name: pthread_completejoin * * Description: - * A thread has been terminated -- either by returning, - * calling pthread_exit(), or through pthread_cancel(). - * In any event, we must complete any pending join events. + * A thread has been terminated -- either by returning, calling + * pthread_exit(), or through pthread_cancel(). In any event, we must + * complete any pending join events. * * Parameters: * exit_value * * Returned Value: - * OK unless there is no join information associated with - * the pid. This could happen, for example, if a task - * started with task_create() calls pthread_exit(). + * OK unless there is no join information associated with the pid. + * This could happen, for example, if a task started with task_create() + * calls pthread_exit(). * * Assumptions: * @@ -195,16 +196,15 @@ int pthread_completejoin(pid_t pid, FAR void *exit_value) } /************************************************************************ - * Function: pthread_destroyjoin + * Name: pthread_destroyjoin * * Description: - * This is called from pthread_completejoin if the join - * info was detached or from pthread_join when the last - * waiting thread has received the thread exit info. + * This is called from pthread_completejoin if the join info was + * detached or from pthread_join when the last waiting thread has + * received the thread exit info. * - * Or it may never be called if the join info was never - * detached or if no thread ever calls pthread_join. In - * case, there is a memory leak! + * Or it may never be called if the join info was never detached or if + * no thread ever calls pthread_join. In case, there is a memory leak! * * Assumptions: * The caller holds g_join_semaphore diff --git a/nuttx/sched/pthread_condbroadcast.c b/nuttx/sched/pthread_condbroadcast.c index 5b69ea428..05f4bb483 100644 --- a/nuttx/sched/pthread_condbroadcast.c +++ b/nuttx/sched/pthread_condbroadcast.c @@ -2,7 +2,7 @@ * sched/pthread_condbroadcast.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -71,7 +71,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: pthread_cond_broadcast + * Name: pthread_cond_broadcast * * Description: * A thread broadcast on a condition variable. @@ -99,9 +99,9 @@ int pthread_cond_broadcast(FAR pthread_cond_t *cond) } else { - /* Disable pre-emption until all of the waiting threads have - * been restarted. This is necessary to assure that the sval - * behaves as expected in the following while loop + /* Disable pre-emption until all of the waiting threads have been + * restarted. This is necessary to assure that the sval behaves as + * expected in the following while loop */ sched_lock(); @@ -109,8 +109,9 @@ int pthread_cond_broadcast(FAR pthread_cond_t *cond) /* Get the current value of the semaphore */ if (sem_getvalue((sem_t*)&cond->sem, &sval) != OK) - ret = EINVAL; - + { + ret = EINVAL; + } else { /* Loop until all of the waiting threads have been restarted. */ diff --git a/nuttx/sched/pthread_conddestroy.c b/nuttx/sched/pthread_conddestroy.c index dc176af77..11292e639 100644 --- a/nuttx/sched/pthread_conddestroy.c +++ b/nuttx/sched/pthread_conddestroy.c @@ -2,7 +2,7 @@ * sched/pthread_conddestroy.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -49,7 +49,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: pthread_cond_destroy + * Name: pthread_cond_destroy * * Description: * A thread can delete condition variables. diff --git a/nuttx/sched/pthread_condinit.c b/nuttx/sched/pthread_condinit.c index f341d28fa..e49bb8658 100644 --- a/nuttx/sched/pthread_condinit.c +++ b/nuttx/sched/pthread_condinit.c @@ -2,7 +2,7 @@ * sched/pthread_condinit.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -50,7 +50,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: pthread_cond_init + * Name: pthread_cond_init * * Description: * A thread can create condition variables. diff --git a/nuttx/sched/pthread_condsignal.c b/nuttx/sched/pthread_condsignal.c index 8f96532df..48ff4cf20 100644 --- a/nuttx/sched/pthread_condsignal.c +++ b/nuttx/sched/pthread_condsignal.c @@ -70,7 +70,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: pthread_cond_signal + * Name: pthread_cond_signal * * Description: * A thread can signal on a condition variable. diff --git a/nuttx/sched/pthread_condtimedwait.c b/nuttx/sched/pthread_condtimedwait.c index 6c43e819c..25f86d813 100644 --- a/nuttx/sched/pthread_condtimedwait.c +++ b/nuttx/sched/pthread_condtimedwait.c @@ -2,7 +2,7 @@ * sched/pthread_condtimedwait.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -74,7 +74,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: pthread_condtimedout + * Name: pthread_condtimedout * * Description: * This function is called if the timeout elapses before @@ -111,7 +111,7 @@ static void pthread_condtimedout(int argc, uint32_t pid, uint32_t signo) ****************************************************************************/ /**************************************************************************** - * Function: pthread_cond_timedwait + * Name: pthread_cond_timedwait * * Description: * A thread can perform a timed wait on a condition variable. @@ -255,7 +255,7 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex, * signal posted by pthread_condtimedout(). */ - if (*get_errno_ptr() == EINTR) + if (get_errno() == EINTR) { sdbg("Timedout!\n"); ret = ETIMEDOUT; diff --git a/nuttx/sched/pthread_condwait.c b/nuttx/sched/pthread_condwait.c index 986349137..bf0164d2d 100644 --- a/nuttx/sched/pthread_condwait.c +++ b/nuttx/sched/pthread_condwait.c @@ -72,11 +72,10 @@ ****************************************************************************/ /**************************************************************************** - * Function: int pthread_cond_wait + * Name: int pthread_cond_wait * * Description: - * A thread can wait for a condition variable to be - * signalled or broadcast. + * A thread can wait for a condition variable to be signalled or broadcast. * * Parameters: * None @@ -107,7 +106,6 @@ int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex) { ret = EPERM; } - else { /* Give up the mutex */ diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c index d51a5956b..5fdf3b88d 100644 --- a/nuttx/sched/pthread_create.c +++ b/nuttx/sched/pthread_create.c @@ -2,7 +2,7 @@ * sched/pthread_create.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -89,23 +89,22 @@ static const char g_pthreadname[] = ""; * Name: pthread_argsetup * * Description: - * This functions sets up parameters in the Task Control - * Block (TCB) in preparation for starting a new thread. + * This functions sets up parameters in the Task Control Block (TCB) in + * preparation for starting a new thread. * - * pthread_argsetup() is called from task_init() and task_start() - * to create a new task (with arguments cloned via strdup) - * or pthread_create() which has one argument passed by - * value (distinguished by the pthread boolean argument). + * pthread_argsetup() is called from task_init() and task_start() to create + * a new task (with arguments cloned via strdup) or pthread_create() which + * has one argument passed by value (distinguished by the pthread boolean + * argument). * * Input Parameters: * tcb - Address of the new task's TCB * name - Name of the new task (not used) - * argv - A pointer to an array of input parameters. - * Up to CONFIG_MAX_TASK_ARG parameters may be - * provided. If fewer than CONFIG_MAX_TASK_ARG - * parameters are passed, the list should be - * terminated with a NULL argv[] value. - * If no parameters are required, argv may be NULL. + * argv - A pointer to an array of input parameters. Up to + * CONFIG_MAX_TASK_ARG parameters may be provided. If fewer + * than CONFIG_MAX_TASK_ARG parameters are passed, the list + * should be terminated with a NULL argv[] value. If no + * parameters are required, argv may be NULL. * * Return Value: * None @@ -145,7 +144,7 @@ static void pthread_argsetup(FAR _TCB *tcb, pthread_addr_t arg) } /**************************************************************************** - * Function: pthread_addjoininfo + * Name: pthread_addjoininfo * * Description: * Add a join_t to the local data set. @@ -172,6 +171,7 @@ static void pthread_addjoininfo(FAR join_t *pjoin) { g_pthread_tail->next = pjoin; } + g_pthread_tail = pjoin; } @@ -226,8 +226,8 @@ static void pthread_start(void) * Name: pthread_create * * Description: - * This function creates and activates a new thread with a - * specified attributes. + * This function creates and activates a new thread with a specified + * attributes. * * Input Parameters: * thread @@ -430,5 +430,6 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr, sched_free(pjoin); return EIO; } + return OK; } diff --git a/nuttx/sched/pthread_detach.c b/nuttx/sched/pthread_detach.c index 52ea63ca5..a959d94b3 100644 --- a/nuttx/sched/pthread_detach.c +++ b/nuttx/sched/pthread_detach.c @@ -2,7 +2,7 @@ * sched/pthread_detach.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -73,11 +73,11 @@ ************************************************************************/ /************************************************************************ - * Function: pthread_detach + * Name: pthread_detach * * Description: - * A thread object may be "detached" to specify that the return - * value and completion status will not be requested. + * A thread object may be "detached" to specify that the return value + * and completion status will not be requested. * * Parameters: * thread @@ -129,6 +129,7 @@ int pthread_detach(pthread_t thread) ret = OK; } + (void)pthread_givesemaphore(&g_join_semaphore); sdbg("Returning %d\n", ret); diff --git a/nuttx/sched/pthread_exit.c b/nuttx/sched/pthread_exit.c index b8183142a..db51be78f 100644 --- a/nuttx/sched/pthread_exit.c +++ b/nuttx/sched/pthread_exit.c @@ -76,7 +76,7 @@ ************************************************************************/ /************************************************************************ - * Function: pthread_exit + * Name: pthread_exit * * Description: * Terminate execution of a thread started with pthread_create. @@ -124,6 +124,7 @@ void pthread_exit(FAR void *exit_value) { error_code = EXIT_FAILURE; } + exit(error_code); } diff --git a/nuttx/sched/pthread_findjoininfo.c b/nuttx/sched/pthread_findjoininfo.c index ea8acfac3..584ed8f96 100644 --- a/nuttx/sched/pthread_findjoininfo.c +++ b/nuttx/sched/pthread_findjoininfo.c @@ -2,7 +2,7 @@ * pthread_findjoininfo.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,7 +38,9 @@ ************************************************************************/ #include + #include + #include "pthread_internal.h" /************************************************************************ @@ -66,7 +68,7 @@ ************************************************************************/ /************************************************************************ - * Function: thread_findjoininfo + * Name: thread_findjoininfo * * Description: * Find a join_t to the local data set. diff --git a/nuttx/sched/pthread_getschedparam.c b/nuttx/sched/pthread_getschedparam.c index 462c6c320..c376fd400 100644 --- a/nuttx/sched/pthread_getschedparam.c +++ b/nuttx/sched/pthread_getschedparam.c @@ -1,8 +1,8 @@ -/******************************************************************************************** +/**************************************************************************** * pthread_getschedparam.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ********************************************************************************************/ + ****************************************************************************/ -/******************************************************************************************** +/**************************************************************************** * Included Files - ********************************************************************************************/ + ****************************************************************************/ #include #include @@ -44,46 +44,46 @@ #include #include "pthread_internal.h" -/******************************************************************************************** +/**************************************************************************** * Definitions - ********************************************************************************************/ + ****************************************************************************/ -/******************************************************************************************** +/**************************************************************************** * Private Type Declarations - ********************************************************************************************/ + ****************************************************************************/ -/******************************************************************************************** +/**************************************************************************** * Global Variables - ********************************************************************************************/ + ****************************************************************************/ -/******************************************************************************************** +/**************************************************************************** * Private Variables - ********************************************************************************************/ + ****************************************************************************/ -/******************************************************************************************** +/**************************************************************************** * Private Functions - ********************************************************************************************/ + ****************************************************************************/ -/******************************************************************************************** +/**************************************************************************** * Public Functions - *********************************************************************************************/ + *****************************************************************************/ -/******************************************************************************************** - * Function: pthread_getschedparam +/**************************************************************************** + * Name: pthread_getschedparam * * Description: * The pthread_getschedparam() functions will get the scheduling policy and * parameters of threads. For SCHED_FIFO and SCHED_RR, the only required * member of the sched_param structure is the priority sched_priority. * - * The pthread_getschedparam() function will retrieve the scheduling policy - * and scheduling parameters for the thread whose thread ID is given by - * 'thread' and will store those values in 'policy' and 'param', + * The pthread_getschedparam() function will retrieve the scheduling + * policy and scheduling parameters for the thread whose thread ID is + * given by 'thread' and will store those values in 'policy' and 'param', * respectively. The priority value returned from pthread_getschedparam() * will be the value specified by the most recent pthread_setschedparam(), * pthread_setschedprio(), or pthread_create() call affecting the target - * thread. It will not reflect any temporary adjustments to its priority (such - * as might result of any priority inheritance, for example). + * thread. It will not reflect any temporary adjustments to its priority + * (such as might result of any priority inheritance, for example). * * The policy parameter may have the value SCHED_FIFO, or SCHED_RR * (SCHED_OTHER and SCHED_SPORADIC, in particular, are not supported). @@ -101,9 +101,10 @@ * * Assumptions: * - ********************************************************************************************/ + ****************************************************************************/ -int pthread_getschedparam(pthread_t thread, FAR int *policy, FAR struct sched_param *param) +int pthread_getschedparam(pthread_t thread, FAR int *policy, + FAR struct sched_param *param) { int ret; @@ -128,7 +129,7 @@ int pthread_getschedparam(pthread_t thread, FAR int *policy, FAR struct sched_pa *policy = sched_getscheduler((pid_t)thread); if (*policy == ERROR) { - ret = *get_errno_ptr(); + ret = get_errno(); } } diff --git a/nuttx/sched/pthread_getspecific.c b/nuttx/sched/pthread_getspecific.c index e0f606eaf..eeead14fa 100644 --- a/nuttx/sched/pthread_getspecific.c +++ b/nuttx/sched/pthread_getspecific.c @@ -2,7 +2,7 @@ * sched/pthread_getspecific.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -71,26 +71,23 @@ ************************************************************************/ /************************************************************************ - * Function: pthread_getspecific + * Name: pthread_getspecific * * Description: - * The pthread_getspecific() function returns the value - * currently bound to the specified key on behalf of the - * calling thread. + * The pthread_getspecific() function returns the value currently + * bound to the specified key on behalf of the calling thread. * - * The effect of calling pthread_getspecific() with - * with a key value not obtained from pthread_create() or - * after a key has been deleted with pthread_key_delete() - * is undefined. + * The effect of calling pthread_getspecific() with with a key value + * not obtained from pthread_create() or after a key has been deleted + * with pthread_key_delete() is undefined. * * Parameters: * key = The data key to get or set * * Return Value: - * The function pthread_getspecific() returns the thread- - * specific data associated with the given key. If no - * thread specific data is associated with the key, then - * the value NULL is returned. + * The function pthread_getspecific() returns the thread-specific data + * associated with the given key. If no thread specific data is + * associated with the key, then the value NULL is returned. * * EINVAL - The key value is invalid. * diff --git a/nuttx/sched/pthread_initialize.c b/nuttx/sched/pthread_initialize.c index 7aa4ed708..09db1d50e 100644 --- a/nuttx/sched/pthread_initialize.c +++ b/nuttx/sched/pthread_initialize.c @@ -2,7 +2,7 @@ * sched/pthread_initialize.c * * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -89,11 +89,10 @@ uint8_t g_pthread_num_keys; ****************************************************************************/ /**************************************************************************** - * Function: pthread_initialize + * Name: pthread_initialize * * Description: - * This is an internal OS function called only at power-up - * boot time. + * This is an internal OS function called only at power-up boot time. * * Parameters: * None @@ -121,7 +120,7 @@ void pthread_initialize(void) } /**************************************************************************** - * Function: pthread_takesemaphore and pthread_givesemaphore + * Name: pthread_takesemaphore and pthread_givesemaphore * * Description: * Support managed access to the private data sets. @@ -151,9 +150,9 @@ int pthread_takesemaphore(sem_t *sem) * awakened by the receipt of a signal. */ - if (*get_errno_ptr() != EINTR) + if (get_errno() != EINTR) { - *get_errno_ptr() = EINVAL; + set_errno(EINVAL); return ERROR; } } @@ -163,7 +162,7 @@ int pthread_takesemaphore(sem_t *sem) { /* NULL semaphore pointer! */ - *get_errno_ptr() = EINVAL; + set_errno(EINVAL); return ERROR; } } @@ -184,7 +183,7 @@ int pthread_givesemaphore(sem_t *sem) { /* sem_post() reported an error */ - *get_errno_ptr() = EINVAL; + set_errno(EINVAL); return ERROR; } } @@ -192,7 +191,7 @@ int pthread_givesemaphore(sem_t *sem) { /* NULL semaphore pointer! */ - *get_errno_ptr() = EINVAL; + set_errno(EINVAL); return ERROR; } } diff --git a/nuttx/sched/pthread_internal.h b/nuttx/sched/pthread_internal.h index 6d8961e37..ca70ab291 100644 --- a/nuttx/sched/pthread_internal.h +++ b/nuttx/sched/pthread_internal.h @@ -2,7 +2,7 @@ * sched/pthread_internal.h * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -57,13 +57,11 @@ * Public Type Declarations ****************************************************************************/ -/* The following defines an entry in the pthread logic's - * local data set. Note that this structure is used to - * implemented a singly linked list. This structure - * is used (instead of, say, a binary search tree) because - * the data set will be searched using the pid as - * a key -- a process IDs will always be created in a - * montonically increasing fashion. +/* The following defines an entry in the pthread logic's local data set. + * Note that this structure is used to implemented a singly linked list. + * This structure is used (instead of, say, a binary search tree) because + * the data set will be searched using the pid as a key -- a process IDs will + * always be created in a montonically increasing fashion. */ struct join_s @@ -79,28 +77,27 @@ struct join_s pthread_addr_t exit_value; /* Returned data */ }; + typedef struct join_s join_t; /**************************************************************************** * Public Variables ****************************************************************************/ -/* This is the head of a private singly linked list. It - * is used to retain information about the spawned threads. +/* This is the head of a private singly linked list. It is used to retain + * information about the spawned threads. */ extern FAR join_t *g_pthread_head; extern FAR join_t *g_pthread_tail; -/* Mutually exclusive access to this data set is enforced with - * the following (un-named) semaphore. +/* Mutually exclusive access to this data set is enforced with the following + * (un-named) semaphore. */ extern sem_t g_join_semaphore; -/* This keys track of the number of global keys that have been - * allocated. - */ +/* This keys track of the number of global keys that have been allocated. */ extern uint8_t g_pthread_num_keys; diff --git a/nuttx/sched/pthread_join.c b/nuttx/sched/pthread_join.c index b4f60a7c9..6a02af352 100644 --- a/nuttx/sched/pthread_join.c +++ b/nuttx/sched/pthread_join.c @@ -42,6 +42,7 @@ #include #include #include + #include "os_internal.h" #include "pthread_internal.h" @@ -70,11 +71,11 @@ ****************************************************************************/ /**************************************************************************** - * Function: pthread_join + * Name: pthread_join * * Description: - * A thread can await termination of another thread and - * retrieve the return value of the thread. + * A thread can await termination of another thread and retrieve the + * return value of the thread. * * Parameters: * thread @@ -83,12 +84,12 @@ * Return Value: * 0 if successful. Otherwise, one of the following error codes: * - * EINVAL The value specified by thread does not refer to a - * joinable thread. - * ESRCH No thread could be found corresponding to that - * specified by the given thread ID. - * EDEADLK A deadlock was detected or the value of thread - * specifies the calling thread. + * EINVAL The value specified by thread does not refer to ajoinable + * thread. + * ESRCH No thread could be found corresponding to thatspecified by the + * given thread ID. + * EDEADLK A deadlock was detected or the value of thread specifies the + * calling thread. * * Assumptions: * @@ -236,8 +237,8 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value) { (void)pthread_destroyjoin(pjoin); } - (void)pthread_givesemaphore(&g_join_semaphore); + (void)pthread_givesemaphore(&g_join_semaphore); ret = OK; } diff --git a/nuttx/sched/pthread_keycreate.c b/nuttx/sched/pthread_keycreate.c index 466cef84d..7579e4c11 100644 --- a/nuttx/sched/pthread_keycreate.c +++ b/nuttx/sched/pthread_keycreate.c @@ -2,7 +2,7 @@ * sched/pthread_keycreate.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -70,45 +70,39 @@ ****************************************************************************/ /**************************************************************************** - * Function: pthread_key_create + * Name: pthread_key_create * * Description: - * This function creates a thread-specific data key visible - * to all threads in the system. Although the same key value - * may be used by different threads, the values bound to - * the key by pthread_setspecific() are maintained on a - * per-thread basis and persist for the life of the calling + * This function creates a thread-specific data key visible to all threads + * in the system. Although the same key value may be used by different + * threads, the values bound to the key by pthread_setspecific() are + * maintained on a per-thread basis and persist for the life of the calling * thread. * - * Upon key creation, the value NULL will be associated with - * the new key in all active threads. Upon thread - * creation, the value NULL will be associated with all - * defined keys in the new thread. + * Upon key creation, the value NULL will be associated with the new key + * in all active threads. Upon thread creation, the value NULL will be + * associated with all defined keys in the new thread. * * Parameters: * key = A pointer to the key to create. - * destructor = An optional destructor() function that may - * be associated with each key that is invoked when a - * thread exits. However, this argument is ignored in - * the current implementation. + * destructor = An optional destructor() function that may be associated + * with each key that is invoked when a thread exits. However, this + * argument is ignored in the current implementation. * * Return Value: - * If successful, the pthread_key_create() function will - * store the newly created key value at *key and return - * zero (OK). Otherwise, an error number will be - * returned to indicate the error: + * If successful, the pthread_key_create() function will store the newly + * created key value at *key and return zero (OK). Otherwise, an error + * number will bereturned to indicate the error: * - * EAGAIN - The system lacked sufficient resources - * to create another thread-specific data key, or the - * system-imposed limit on the total number of keys - * pers process {PTHREAD_KEYS_MAX} has been exceeded + * EAGAIN - The system lacked sufficient resources to create another + * thread-specific data key, or the system-imposed limit on the total + * number of keys pers process {PTHREAD_KEYS_MAX} has been exceeded * ENONMEM - Insufficient memory exists to create the key. * * Assumptions: * * POSIX Compatibility: - * - The present implementation ignores the destructor - * argument. + * - The present implementation ignores the destructor argument. * ****************************************************************************/ diff --git a/nuttx/sched/pthread_keydelete.c b/nuttx/sched/pthread_keydelete.c index 397f06267..d55a448ed 100644 --- a/nuttx/sched/pthread_keydelete.c +++ b/nuttx/sched/pthread_keydelete.c @@ -2,7 +2,7 @@ * sched/pthread_keydelete.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -70,12 +70,12 @@ ************************************************************************/ /************************************************************************ - * Function: pthread_key_delete + * Name: pthread_key_delete * * Description: - * This POSIX function should delete a thread-specific data - * key previously returned by pthread_key_create(). However, - * this function does nothing in the present implementation. + * This POSIX function should delete a thread-specific data key + * previously returned by pthread_key_create(). However, this function + * does nothing in the present implementation. * * Parameters: * key = the key to delete diff --git a/nuttx/sched/pthread_kill.c b/nuttx/sched/pthread_kill.c index f876220f7..5a1506c0c 100644 --- a/nuttx/sched/pthread_kill.c +++ b/nuttx/sched/pthread_kill.c @@ -50,23 +50,22 @@ ************************************************************************/ /************************************************************************ - * Function: pthread_kill + * Name: pthread_kill * * Description: - * The pthread_kill() system call can be used to send any - * signal to a thread. See kill() for further information - * as this is just a simple wrapper around the kill() - * function. + * The pthread_kill() system call can be used to send any signal to a + * thread. See kill() for further information as this is just a simple + * wrapper around the kill() function. * * Parameters: - * thread - The id of the thread to receive the signal. Only - * positive, non-zero values of 'thread' are supported. - * signo - The signal number to send. If 'signo' is zero, - * no signal is sent, but all error checking is performed. + * thread - The id of the thread to receive the signal. Only positive, + * non-zero values of 'thread' are supported. + * signo - The signal number to send. If 'signo' is zero, no signal is + * sent, but all error checking is performed. * * Return Value: - * On success the signal was send and zero is returned. - * On error one of the following error numbers is returned. + * On success the signal was send and zero is returned. On error one + * of the following error numbers is returned. * * EINVAL An invalid signal was specified. * EPERM The thread does not have permission to send the @@ -89,6 +88,7 @@ int pthread_kill(pthread_t thread, int signo) { ret = get_errno(); } + return ret; } diff --git a/nuttx/sched/pthread_mutexdestroy.c b/nuttx/sched/pthread_mutexdestroy.c index fa78fe82b..f66358534 100644 --- a/nuttx/sched/pthread_mutexdestroy.c +++ b/nuttx/sched/pthread_mutexdestroy.c @@ -2,7 +2,7 @@ * sched/pthread_mutexdestroy.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -44,6 +44,7 @@ #include #include #include + #include "pthread_internal.h" /**************************************************************************** @@ -71,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: pthread_mutex_destroy + * Name: pthread_mutex_destroy * * Description: * Destroy a mutex. @@ -121,6 +122,7 @@ int pthread_mutex_destroy(FAR pthread_mutex_t *mutex) ret = EINVAL; } } + sched_unlock(); } diff --git a/nuttx/sched/pthread_mutexinit.c b/nuttx/sched/pthread_mutexinit.c index 6004076cb..265f014e3 100644 --- a/nuttx/sched/pthread_mutexinit.c +++ b/nuttx/sched/pthread_mutexinit.c @@ -2,7 +2,7 @@ * sched/pthread_mutexinit.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -71,7 +71,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: pthread_mutex_init + * Name: pthread_mutex_init * * Description: * Create a mutex diff --git a/nuttx/sched/pthread_mutexlock.c b/nuttx/sched/pthread_mutexlock.c index a56fd9d71..7681d771a 100644 --- a/nuttx/sched/pthread_mutexlock.c +++ b/nuttx/sched/pthread_mutexlock.c @@ -2,7 +2,7 @@ * sched/pthread_mutexlock.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -72,35 +72,38 @@ ****************************************************************************/ /**************************************************************************** - * Function: pthread_mutex_lock + * Name: pthread_mutex_lock * * Description: - * The mutex object referenced by mutex is locked by calling pthread_mutex_lock(). - * If the mutex is already locked, the calling thread blocks until the mutex - * becomes available. This operation returns with the mutex object referenced - * by mutex in the locked state with the calling thread as its owner. + * The mutex object referenced by mutex is locked by calling + * pthread_mutex_lock(). If the mutex is already locked, the calling thread + * blocks until the mutex becomes available. This operation returns with the + * mutex object referenced by mutex in the locked state with the calling + * thread as its owner. * - * If the mutex type is PTHREAD_MUTEX_NORMAL, deadlock detection is not provided. - * Attempting to relock the mutex causes deadlock. If a thread attempts to unlock - * a mutex that it has not locked or a mutex which is unlocked, undefined behavior - * results. + * If the mutex type is PTHREAD_MUTEX_NORMAL, deadlock detection is not + * provided. Attempting to relock the mutex causes deadlock. If a thread + * attempts to unlock a mutex that it has not locked or a mutex which is + * unlocked, undefined behavior results. * - * If the mutex type is PTHREAD_MUTEX_ERRORCHECK, then error checking is provided. - * If a thread attempts to relock a mutex that it has already locked, an error - * will be returned. If a thread attempts to unlock a mutex that it has not - * locked or a mutex which is unlocked, an error will be returned. + * If the mutex type is PTHREAD_MUTEX_ERRORCHECK, then error checking is + * provided. If a thread attempts to relock a mutex that it has already + * locked, an error will be returned. If a thread attempts to unlock a + * mutex that it has not locked or a mutex which is unlocked, an error will + * be returned. * - * If the mutex type is PTHREAD_MUTEX_RECURSIVE, then the mutex maintains the concept - * of a lock count. When a thread successfully acquires a mutex for the first time, - * the lock count is set to one. Every time a thread relocks this mutex, the lock count - * is incremented by one. Each time the thread unlocks the mutex, the lock count is - * decremented by one. When the lock count reaches zero, the mutex becomes available - * for other threads to acquire. If a thread attempts to unlock a mutex that it has - * not locked or a mutex which is unlocked, an error will be returned. + * If the mutex type is PTHREAD_MUTEX_RECURSIVE, then the mutex maintains + * the concept of a lock count. When a thread successfully acquires a mutex + * for the first time, the lock count is set to one. Every time a thread + * relocks this mutex, the lock count is incremented by one. Each time the + * thread unlocks the mutex, the lock count is decremented by one. When the + * lock count reaches zero, the mutex becomes available for other threads to + * acquire. If a thread attempts to unlock a mutex that it has not locked or + * a mutex which is unlocked, an error will be returned. * - * If a signal is delivered to a thread waiting for a mutex, upon return from - * the signal handler the thread resumes waiting for the mutex as if it was - * not interrupted. + * If a signal is delivered to a thread waiting for a mutex, upon return + * from the signal handler the thread resumes waiting for the mutex as if + * it was not interrupted. * * Parameters: * mutex - A reference to the mutex to be locked. @@ -141,16 +144,16 @@ int pthread_mutex_lock(FAR pthread_mutex_t *mutex) #ifdef CONFIG_MUTEX_TYPES if (mutex->type == PTHREAD_MUTEX_RECURSIVE) { - /* Yes... just increment the number of locks held and return success */ - - mutex->nlocks++; + /* Yes... just increment the number of locks held and return success */ + + mutex->nlocks++; } else #endif { - /* No, then we would deadlock... return an error (default behavior - * is like PTHREAD_MUTEX_ERRORCHECK) - */ + /* No, then we would deadlock... return an error (default behavior + * is like PTHREAD_MUTEX_ERRORCHECK) + */ sdbg("Returning EDEADLK\n"); ret = EDEADLK; @@ -174,6 +177,7 @@ int pthread_mutex_lock(FAR pthread_mutex_t *mutex) #endif } } + sched_unlock(); } diff --git a/nuttx/sched/pthread_mutextrylock.c b/nuttx/sched/pthread_mutextrylock.c index 24779cbf7..d88012b51 100644 --- a/nuttx/sched/pthread_mutextrylock.c +++ b/nuttx/sched/pthread_mutextrylock.c @@ -2,7 +2,7 @@ * sched/pthread_mutextrylock.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -45,6 +45,7 @@ #include #include #include + #include "pthread_internal.h" /**************************************************************************** @@ -72,7 +73,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: pthread_mutex_trylock + * Name: pthread_mutex_trylock * * Description: * The function pthread_mutex_trylock() is identical to pthread_mutex_lock() @@ -126,7 +127,7 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex) /* Was it not available? */ - else if (*get_errno_ptr() == EAGAIN) + else if (get_errno() == EAGAIN) { ret = EBUSY; } diff --git a/nuttx/sched/pthread_mutexunlock.c b/nuttx/sched/pthread_mutexunlock.c index 90ed5e537..34846f952 100644 --- a/nuttx/sched/pthread_mutexunlock.c +++ b/nuttx/sched/pthread_mutexunlock.c @@ -2,7 +2,7 @@ * sched/pthread_mutexunlock.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: pthread_mutex_unlock + * Name: pthread_mutex_unlock * * Description: * The pthread_mutex_unlock() function releases the mutex object referenced diff --git a/nuttx/sched/pthread_once.c b/nuttx/sched/pthread_once.c index dc0fcd2bd..413300472 100644 --- a/nuttx/sched/pthread_once.c +++ b/nuttx/sched/pthread_once.c @@ -2,7 +2,7 @@ * sched/pthread_once.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -70,7 +70,7 @@ ********************************************************************************/ /******************************************************************************** - * Function: pthread_once + * Name: pthread_once * * Description: * The first call to pthread_once() by any thread with a given once_control, @@ -88,13 +88,15 @@ * init_routine - The initialization routine that will be called once. * * Return Value: - * 0 (OK) on success or EINVAL if either once_control or init_routine are invalid + * 0 (OK) on success or EINVAL if either once_control or init_routine are + * invalid * * Assumptions: * ********************************************************************************/ -int pthread_once(FAR pthread_once_t *once_control, CODE void (*init_routine)(void)) +int pthread_once(FAR pthread_once_t *once_control, + CODE void (*init_routine)(void)) { /* Sanity checks */ diff --git a/nuttx/sched/pthread_removejoininfo.c b/nuttx/sched/pthread_removejoininfo.c index 3251b67fe..defc02991 100644 --- a/nuttx/sched/pthread_removejoininfo.c +++ b/nuttx/sched/pthread_removejoininfo.c @@ -2,7 +2,7 @@ * sched/pthread_removejoininfo.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -65,7 +65,7 @@ ************************************************************************/ /************************************************************************ - * Function: pthread_removejoininfo + * Name: pthread_removejoininfo * * Description: * Remove a join_t from the local data set. diff --git a/nuttx/sched/pthread_setcancelstate.c b/nuttx/sched/pthread_setcancelstate.c index eaa754174..2c6bf3083 100644 --- a/nuttx/sched/pthread_setcancelstate.c +++ b/nuttx/sched/pthread_setcancelstate.c @@ -2,7 +2,7 @@ * pthread_setcancelstate.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -69,6 +69,10 @@ * Public Functions ******************************************************************************************/ +/****************************************************************************************** + * Name: pthread_setcancelstate + ******************************************************************************************/ + int pthread_setcancelstate(int state, FAR int *oldstate) { _TCB *tcb = (_TCB*)g_readytorun.head; diff --git a/nuttx/sched/pthread_setschedparam.c b/nuttx/sched/pthread_setschedparam.c index e3e3c8ae9..019a7c7a5 100644 --- a/nuttx/sched/pthread_setschedparam.c +++ b/nuttx/sched/pthread_setschedparam.c @@ -1,4 +1,4 @@ -/******************************************************************************************** +/**************************************************************************** * pthread_setschedparam.c * * Copyright (C) 2007, 2008, 2012 Gregory Nutt. All rights reserved. @@ -31,55 +31,57 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ********************************************************************************************/ + ****************************************************************************/ -/******************************************************************************************** +/**************************************************************************** * Included Files - ********************************************************************************************/ + ****************************************************************************/ #include #include #include #include #include + #include "pthread_internal.h" -/******************************************************************************************** +/**************************************************************************** * Definitions - ********************************************************************************************/ + ****************************************************************************/ -/******************************************************************************************** +/**************************************************************************** * Private Type Declarations - ********************************************************************************************/ + ****************************************************************************/ -/******************************************************************************************** +/**************************************************************************** * Global Variables - ********************************************************************************************/ + ****************************************************************************/ -/******************************************************************************************** +/**************************************************************************** * Private Variables - ********************************************************************************************/ + ****************************************************************************/ -/******************************************************************************************** +/**************************************************************************** * Private Functions - ********************************************************************************************/ + ****************************************************************************/ -/******************************************************************************************** +/**************************************************************************** * Public Functions - ********************************************************************************************/ + ****************************************************************************/ -/******************************************************************************************** - * Function: pthread_setschedparam +/**************************************************************************** + * Name: pthread_setschedparam * * Description: - * The pthread_setschedparam() functions will set the scheduling policy and - * parameters of threads. For SCHED_FIFO and SCHED_RR, the only required - * member of the sched_param structure is the priority sched_priority. + * The pthread_setschedparam() functions will set the scheduling policy + * and parameters of threads. For SCHED_FIFO and SCHED_RR, the only + * required member of the sched_param structure is the priority + * sched_priority. * - * The pthread_setschedparam() function will set the scheduling policy and - * associated scheduling parameters for the thread whose thread ID is - * given by 'thread' to the policy and associated parameters provided in - * 'policy' and 'param', respectively. + * The pthread_setschedparam() function will set the scheduling policy + * and associated scheduling parameters for the thread whose thread ID + * is given by 'thread' to the policy and associated parameters provided + * in 'policy' and 'param', respectively. * * The policy parameter may have the value SCHED_FIFO, or SCHED_RR * (SCHED_OTHER and SCHED_SPORADIC, in particular, are not supported). @@ -99,8 +101,9 @@ * 0 if successful. Otherwise, an error code identifying the cause of the * failure: * - * EINVAL The value specified by 'policy' or one of the scheduling parameters - * associated with the scheduling policy 'policy' is invalid. + * EINVAL The value specified by 'policy' or one of the scheduling + * parameters associated with the scheduling policy 'policy' is + * invalid. * ENOTSUP An attempt was made to set the policy or scheduling parameters * to an unsupported value (SCHED_OTHER and SCHED_SPORADIC in * particular are not supported) @@ -113,7 +116,7 @@ * * Assumptions: * - ********************************************************************************************/ + ****************************************************************************/ int pthread_setschedparam(pthread_t thread, int policy, FAR const struct sched_param *param) { @@ -123,7 +126,7 @@ int pthread_setschedparam(pthread_t thread, int policy, FAR const struct sched_p /* Set the errno to some non-zero value (failsafe) */ - *get_errno_ptr() = EINVAL; + set_errno(EINVAL); /* Let sched_setscheduler do all of the work */ @@ -132,8 +135,8 @@ int pthread_setschedparam(pthread_t thread, int policy, FAR const struct sched_p { /* If sched_setscheduler() fails, return the errno */ - ret = *get_errno_ptr(); + ret = get_errno(); } - return ret; - } + return ret; +} diff --git a/nuttx/sched/pthread_setschedprio.c b/nuttx/sched/pthread_setschedprio.c index fc4c2d612..a523b20ea 100644 --- a/nuttx/sched/pthread_setschedprio.c +++ b/nuttx/sched/pthread_setschedprio.c @@ -2,7 +2,7 @@ * pthread_schedsetprio.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/sched/pthread_setspecific.c b/nuttx/sched/pthread_setspecific.c index b9f166d34..33fb4aeeb 100644 --- a/nuttx/sched/pthread_setspecific.c +++ b/nuttx/sched/pthread_setspecific.c @@ -2,7 +2,7 @@ * sched/pthread_setspecific.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -70,7 +70,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: pthread_setspecific + * Name: pthread_setspecific * * Description: * The pthread_setspecific() function associates a thread- diff --git a/nuttx/sched/pthread_sigmask.c b/nuttx/sched/pthread_sigmask.c index dac921903..c66b8591c 100644 --- a/nuttx/sched/pthread_sigmask.c +++ b/nuttx/sched/pthread_sigmask.c @@ -2,7 +2,7 @@ * sched/pthread_sigmask.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -69,7 +69,7 @@ ************************************************************************/ /************************************************************************ - * Function: pthread_sigmask + * Name: pthread_sigmask * * Description: * This function is a simple wrapper around sigprocmask(). diff --git a/nuttx/sched/pthread_yield.c b/nuttx/sched/pthread_yield.c index 6c7a42e20..c4535b9db 100644 --- a/nuttx/sched/pthread_yield.c +++ b/nuttx/sched/pthread_yield.c @@ -2,7 +2,7 @@ * sched/pthread_yield.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -65,7 +65,7 @@ ************************************************************************/ /************************************************************************ - * Function: pthread_yield + * Name: pthread_yield * * Description: * A thread may tell the scheduler that its processor can be diff --git a/nuttx/sched/sched_addblocked.c b/nuttx/sched/sched_addblocked.c index 9231afa49..c0b80c8ac 100644 --- a/nuttx/sched/sched_addblocked.c +++ b/nuttx/sched/sched_addblocked.c @@ -2,7 +2,7 @@ * sched/sched_addblocked.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -72,8 +72,8 @@ * Name: sched_addblocked * * Description: - * This function adds a TCB to one of the blocked state - * task lists as inferreded from task_state. + * This function adds a TCB to one of the blocked state task lists as + * inferred from task_state. * * Inputs: * btcb - Points to the TCB that is blocked @@ -90,31 +90,33 @@ void sched_addblocked(FAR _TCB *btcb, tstate_t task_state) { - /* Make sure that we received a valid blocked state */ + /* Make sure that we received a valid blocked state */ - ASSERT(task_state >= FIRST_BLOCKED_STATE && - task_state <= LAST_BLOCKED_STATE); + ASSERT(task_state >= FIRST_BLOCKED_STATE && + task_state <= LAST_BLOCKED_STATE); - /* Add the TCB to the blocked task list associated with - * this state. First, determine if the task is to be added - * to a prioritized task list - */ + /* Add the TCB to the blocked task list associated with this state. + * First, determine if the task is to be added to a prioritized task + * list + */ - if (g_tasklisttable[task_state].prioritized) - { - /* Add the task to a prioritized list */ + if (g_tasklisttable[task_state].prioritized) + { + /* Add the task to a prioritized list */ - sched_addprioritized(btcb, (FAR dq_queue_t*)g_tasklisttable[task_state].list); - } - else - { - /* Add the task to a non-prioritized list */ + sched_addprioritized(btcb, + (FAR dq_queue_t*)g_tasklisttable[task_state].list); + } + else + { + /* Add the task to a non-prioritized list */ - dq_addlast((FAR dq_entry_t*)btcb, (FAR dq_queue_t*)g_tasklisttable[task_state].list); - } + dq_addlast((FAR dq_entry_t*)btcb, + (FAR dq_queue_t*)g_tasklisttable[task_state].list); + } - /* Make sure the TCB's state corresponds to the list */ + /* Make sure the TCB's state corresponds to the list */ - btcb->task_state = task_state; + btcb->task_state = task_state; } diff --git a/nuttx/sched/sched_addprioritized.c b/nuttx/sched/sched_addprioritized.c index d937dcee3..8f19a4731 100644 --- a/nuttx/sched/sched_addprioritized.c +++ b/nuttx/sched/sched_addprioritized.c @@ -2,7 +2,7 @@ * sched/sched_addprioritized.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -71,7 +71,7 @@ ************************************************************************/ /************************************************************************ - * Function: sched_addprioritized + * Name: sched_addprioritized * * Description: * This function adds a TCB to a prioritized TCB list. diff --git a/nuttx/sched/sched_addreadytorun.c b/nuttx/sched/sched_addreadytorun.c index 51e219342..f6117b6ff 100644 --- a/nuttx/sched/sched_addreadytorun.c +++ b/nuttx/sched/sched_addreadytorun.c @@ -2,7 +2,7 @@ * sched/sched_addreadytorun.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -103,15 +103,15 @@ bool sched_addreadytorun(FAR _TCB *btcb) FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; bool ret; - /* Check if pre-emption is disabled for the current running - * task and if the new ready-to-run task would cause the - * current running task to be preempted. + /* Check if pre-emption is disabled for the current running task and if + * the new ready-to-run task would cause the current running task to be + * preempted. */ if (rtcb->lockcount && rtcb->sched_priority < btcb->sched_priority) { - /* Yes. Preemption would occur! Add the new ready-to-run - * task to the g_pendingtasks task list for now. + /* Yes. Preemption would occur! Add the new ready-to-run task to the + * g_pendingtasks task list for now. */ sched_addprioritized(btcb, (FAR dq_queue_t*)&g_pendingtasks); diff --git a/nuttx/sched/sched_foreach.c b/nuttx/sched/sched_foreach.c index 3af74c704..192094533 100644 --- a/nuttx/sched/sched_foreach.c +++ b/nuttx/sched/sched_foreach.c @@ -2,7 +2,7 @@ * sched/sched_foreach.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -45,7 +45,7 @@ ************************************************************************/ /************************************************************************ - * Function: sched_foreach + * Name: sched_foreach * * Description: * Enumerate over each task and provide the TCB of each @@ -77,6 +77,7 @@ void sched_foreach(sched_foreach_t handler, FAR void *arg) handler(g_pidhash[ndx].tcb, arg); } } + irqrestore(flags); } diff --git a/nuttx/sched/sched_free.c b/nuttx/sched/sched_free.c index e7c8bf56b..4df77b109 100644 --- a/nuttx/sched/sched_free.c +++ b/nuttx/sched/sched_free.c @@ -84,10 +84,9 @@ void sched_free(FAR void *address) { - /* Check if this is an attempt to deallocate memory from - * an exception handler. If this function is called from the - * IDLE task, then we must have exclusive access to the memory - * manager to do this. + /* Check if this is an attempt to deallocate memory from an exception + * handler. If this function is called from the IDLE task, then we + * must have exclusive access to the memory manager to do this. */ if (up_interrupt_context() || kmm_trysemaphore() != 0) diff --git a/nuttx/sched/sched_garbage.c b/nuttx/sched/sched_garbage.c index 714422bd6..b8bec9399 100644 --- a/nuttx/sched/sched_garbage.c +++ b/nuttx/sched/sched_garbage.c @@ -2,7 +2,7 @@ * sched/sched_garbage.c * * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/sched/sched_getfiles.c b/nuttx/sched/sched_getfiles.c index c8cbfe160..256b4cb6b 100644 --- a/nuttx/sched/sched_getfiles.c +++ b/nuttx/sched/sched_getfiles.c @@ -2,7 +2,7 @@ * sched/sched_getfiles.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -50,7 +50,7 @@ ************************************************************************/ /************************************************************************ - * Function: sched_getfiles + * Name: sched_getfiles * * Description: * Return a pointer to the file list for this thread diff --git a/nuttx/sched/sched_getparam.c b/nuttx/sched/sched_getparam.c index a74e4d65e..47eab4988 100644 --- a/nuttx/sched/sched_getparam.c +++ b/nuttx/sched/sched_getparam.c @@ -2,7 +2,7 @@ * sched/sched_getparam.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,8 +38,10 @@ ************************************************************************/ #include + #include #include + #include "os_internal.h" /************************************************************************ @@ -135,6 +137,7 @@ int sched_getparam (pid_t pid, struct sched_param * param) param->sched_priority = (int)tcb->sched_priority; } + sched_unlock(); } diff --git a/nuttx/sched/sched_getscheduler.c b/nuttx/sched/sched_getscheduler.c index 1515ae69c..5771e86ff 100644 --- a/nuttx/sched/sched_getscheduler.c +++ b/nuttx/sched/sched_getscheduler.c @@ -2,7 +2,7 @@ * sched/sched_getscheduler.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,10 +38,13 @@ ************************************************************************/ #include + #include #include #include + #include + #include "os_internal.h" /************************************************************************ @@ -76,21 +79,20 @@ * Name: sched_getscheduler * * Description: - * sched_getscheduler() returns the scheduling policy - * currently applied to the process identified by pid. If - * pid equals zero, the policy of the calling process will - * be retrieved. + * sched_getscheduler() returns the scheduling policy currently + * applied to the task identified by pid. If pid equals zero, the + * policy of the calling task will be retrieved. * * Inputs: - * pid - the task ID of the task to query. If pid is - * zero, the calling task is queried. + * pid - the task ID of the task to query. If pid is zero, the + * calling task is queried. * * Return Value: - * On success, sched_getscheduler() returns the policy for - * the task (either SCHED_FIFO or SCHED_RR). On error, - * ERROR (-1) is returned, and errno is set appropriately: + * On success, sched_getscheduler() returns the policy for the task + * (either SCHED_FIFO or SCHED_RR). On error, ERROR (-1) is + * returned, and errno is set appropriately: * - * ESRCH The task whose ID is pid could not be found. + * ESRCH The task whose ID is pid could not be found. * * Assumptions: * @@ -113,7 +115,7 @@ int sched_getscheduler(pid_t pid) if (!tcb) { - *get_errno_ptr() = ESRCH; + set_errno(ESRCH); return ERROR; } #if CONFIG_RR_INTERVAL > 0 diff --git a/nuttx/sched/sched_getsockets.c b/nuttx/sched/sched_getsockets.c index 8a220fe4f..cd499420f 100644 --- a/nuttx/sched/sched_getsockets.c +++ b/nuttx/sched/sched_getsockets.c @@ -2,7 +2,7 @@ * sched/sched_getsockets.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -53,7 +53,7 @@ ************************************************************************/ /************************************************************************ - * Function: sched_getsockets + * Name: sched_getsockets * * Description: * Return a pointer to the socket list for this thread diff --git a/nuttx/sched/sched_getstreams.c b/nuttx/sched/sched_getstreams.c index abf3d7ef2..f7c21ab4c 100644 --- a/nuttx/sched/sched_getstreams.c +++ b/nuttx/sched/sched_getstreams.c @@ -2,7 +2,7 @@ * sched/sched_getstreams.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -50,7 +50,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sched_getstreams + * Name: sched_getstreams * * Description: * Return a pointer to the streams list for this thread diff --git a/nuttx/sched/sched_gettcb.c b/nuttx/sched/sched_gettcb.c index 39933369f..1e50ef50f 100644 --- a/nuttx/sched/sched_gettcb.c +++ b/nuttx/sched/sched_gettcb.c @@ -2,7 +2,7 @@ * sched/sched_gettcb.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,7 +38,9 @@ ****************************************************************************/ #include + #include + #include "os_internal.h" /**************************************************************************** diff --git a/nuttx/sched/sched_lock.c b/nuttx/sched/sched_lock.c index 2dd406203..61a8a3bc8 100644 --- a/nuttx/sched/sched_lock.c +++ b/nuttx/sched/sched_lock.c @@ -2,7 +2,7 @@ * sched/sched_lock.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -77,11 +77,10 @@ * Name: sched_lock * * Description: - * This function disables context switching by disabling - * addition of new tasks to the g_readytorun task list. - * The task that calls this function will be the only task - * that is allowed to run until it either calls - * sched_unlock() (the appropriate number of times) or + * This function disables context switching by disabling addition of + * new tasks to the g_readytorun task list. The task that calls this + * function will be the only task that is allowed to run until it + * either calls sched_unlock() (the appropriate number of times) or * until it blocks itself. * * Inputs @@ -106,5 +105,6 @@ int sched_lock(void) ASSERT(rtcb->lockcount < MAX_LOCK_COUNT); rtcb->lockcount++; } + return OK; } diff --git a/nuttx/sched/sched_lockcount.c b/nuttx/sched/sched_lockcount.c index 6ac3a9dee..4dc7a8201 100644 --- a/nuttx/sched/sched_lockcount.c +++ b/nuttx/sched/sched_lockcount.c @@ -2,7 +2,7 @@ * sched/sched_lockcount.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -91,7 +91,7 @@ int sched_lockcount(void) { - _TCB *rtcb = (_TCB*)g_readytorun.head; - return (int)rtcb->lockcount; + _TCB *rtcb = (_TCB*)g_readytorun.head; + return (int)rtcb->lockcount; } diff --git a/nuttx/sched/sched_mergepending.c b/nuttx/sched/sched_mergepending.c index 202228412..71d575c23 100644 --- a/nuttx/sched/sched_mergepending.c +++ b/nuttx/sched/sched_mergepending.c @@ -71,11 +71,11 @@ ************************************************************************/ /************************************************************************ - * Function: sched_mergepending + * Name: sched_mergepending * * Description: - * This function merges the prioritized g_pendingtasks list - * into the prioritized g_readytorun task list. + * This function merges the prioritized g_pendingtasks list into the + * prioritized g_readytorun task list. * * Inputs: * None diff --git a/nuttx/sched/sched_processtimer.c b/nuttx/sched/sched_processtimer.c index 5c98bc45b..2224b7691 100644 --- a/nuttx/sched/sched_processtimer.c +++ b/nuttx/sched/sched_processtimer.c @@ -2,7 +2,7 @@ * sched/sched_processtimer.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -87,7 +87,6 @@ static void sched_process_timeslice(void) if (rtcb->timeslice <= 1) { - /* Yes, Now check if the task has pre-emption disabled. * If so, then we will freeze the timeslice count at * the value until the next tick after pre-emption @@ -187,5 +186,5 @@ void sched_process_timer(void) * timeslice. */ - sched_process_timeslice(); + sched_process_timeslice(); } diff --git a/nuttx/sched/sched_releasefiles.c b/nuttx/sched/sched_releasefiles.c index dc08488dc..a3ef71af4 100644 --- a/nuttx/sched/sched_releasefiles.c +++ b/nuttx/sched/sched_releasefiles.c @@ -55,7 +55,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sched_releasefiles + * Name: sched_releasefiles * * Description: * Release file resources attached to a TCB. This file may be called @@ -107,6 +107,7 @@ int sched_releasefiles(_TCB *tcb) } #endif /* CONFIG_NSOCKET_DESCRIPTORS */ } + return OK; } diff --git a/nuttx/sched/sched_releasetcb.c b/nuttx/sched/sched_releasetcb.c index 362f67ef5..21837262d 100644 --- a/nuttx/sched/sched_releasetcb.c +++ b/nuttx/sched/sched_releasetcb.c @@ -61,15 +61,15 @@ static void sched_releasepid(pid_t pid) { - int hash_ndx = PIDHASH(pid); + int hash_ndx = PIDHASH(pid); - /* Make any pid associated with this hash available. Note: - * no special precautions need be taken here because the - * following action is atomic - */ + /* Make any pid associated with this hash available. Note: + * no special precautions need be taken here because the + * following action is atomic + */ - g_pidhash[hash_ndx].tcb = NULL; - g_pidhash[hash_ndx].pid = INVALID_PROCESS_ID; + g_pidhash[hash_ndx].tcb = NULL; + g_pidhash[hash_ndx].pid = INVALID_PROCESS_ID; } /************************************************************************ @@ -77,7 +77,7 @@ static void sched_releasepid(pid_t pid) ************************************************************************/ /************************************************************************ - * Function: sched_releasetcb + * Name: sched_releasetcb * * Description: * Free all resources contained in a TCB diff --git a/nuttx/sched/sched_removeblocked.c b/nuttx/sched/sched_removeblocked.c index 6a2194781..8d5a127d2 100644 --- a/nuttx/sched/sched_removeblocked.c +++ b/nuttx/sched/sched_removeblocked.c @@ -2,7 +2,7 @@ * sched/sched_removeblocked.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -72,9 +72,8 @@ * Name: sched_removeblocked * * Description: - * This function removes a TCB from one of the blocked - * state task lists as inferreded from the task_state - * inside the TCB. + * This function removes a TCB from one of the blocked state task + * lists as inferred from the task_state inside the TCB. * * Inputs: * btcb - Points to the TCB that is blocked diff --git a/nuttx/sched/sched_removereadytorun.c b/nuttx/sched/sched_removereadytorun.c index 82c24402c..4982808e2 100644 --- a/nuttx/sched/sched_removereadytorun.c +++ b/nuttx/sched/sched_removereadytorun.c @@ -83,9 +83,8 @@ * g_readytorun list) has changed. * * Assumptions: - * - The caller has established a critical section before - * calling this function (calling sched_lock() first is NOT - * a good idea -- use irqsave()). + * - The caller has established a critical section before calling this + * function (calling sched_lock() first is NOT a good idea -- use irqsave()). * - The caller handles the condition that occurs if the * the head of the g_readytorun list is changed. * @@ -95,9 +94,8 @@ bool sched_removereadytorun(FAR _TCB *rtcb) { bool ret = false; - /* Check if the TCB to be removed is at the head of the ready - * to run list. In this case, we are removing the currently - * active task. + /* Check if the TCB to be removed is at the head of the ready to run list. + * In this case, we are removing the currently active task. */ if (!rtcb->blink) diff --git a/nuttx/sched/sched_reprioritize.c b/nuttx/sched/sched_reprioritize.c index 3fa1c4da0..bd316ec75 100644 --- a/nuttx/sched/sched_reprioritize.c +++ b/nuttx/sched/sched_reprioritize.c @@ -81,9 +81,9 @@ * Description: * This function sets the priority of a specified task. * - * NOTE: Setting a task's priority to the same value has a similar - * effect to sched_yield() -- The task will be moved to after all other - * tasks with the same priority. + * NOTE: Setting a task's priority to the same value has a similar effect + * to sched_yield() -- The task will be moved to after all other tasks + * with the same priority. * * Inputs: * tcb - the TCB of task to reprioritize. @@ -93,8 +93,8 @@ * On success, sched_setparam() returns 0 (OK). On error, -1 * (ERROR) is returned, and errno is set appropriately. * - * EINVAL The parameter 'param' is invalid or does not make - * sense for the current scheduling policy. + * EINVAL The parameter 'param' is invalid or does not make sense for the + * current scheduling policy. * EPERM The calling task does not have appropriate privileges. * ESRCH The task whose ID is pid could not be found. * @@ -120,9 +120,9 @@ int sched_reprioritize(FAR _TCB *tcb, int sched_priority) /* Discard any pending reprioritizations as well */ -# if CONFIG_SEM_NNESTPRIO > 0 +#if CONFIG_SEM_NNESTPRIO > 0 tcb->npend_reprio = 0; -# endif +#endif } return ret; } diff --git a/nuttx/sched/sched_rrgetinterval.c b/nuttx/sched/sched_rrgetinterval.c index 114f36532..961c58ec5 100644 --- a/nuttx/sched/sched_rrgetinterval.c +++ b/nuttx/sched/sched_rrgetinterval.c @@ -2,7 +2,7 @@ * sched/sched_rrgetinterval.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,10 +38,13 @@ ************************************************************************/ #include + #include #include #include + #include + #include "os_internal.h" #include "clock_internal.h" @@ -77,21 +80,20 @@ * Name: sched_rr_get_interval * * Description: - * sched_rr_get_interval() writes the timeslice interval - * for task identified by 'pid' into the timespec structure - * pointed to by 'interval.' If pid is zero, the timeslice - * for the calling process is written into 'interval. The - * identified process should be running under the SCHED_RR - * scheduling policy.' + * sched_rr_get_interval() writes the timeslice interval for task + * identified by 'pid' into the timespec structure pointed to by + * 'interval.' If pid is zero, the timeslice for the calling process + * is written into 'interval. The identified process should be running + * under the SCHED_RRscheduling policy.' * * Inputs: - * pid - the task ID of the task. If pid is zero, the - * priority of the calling task is returned. + * pid - the task ID of the task. If pid is zero, the priority of the + * calling task is returned. * interval - a structure used to return the time slice * * Return Value: - * On success, sched_rr_get_interval() returns OK (0). On - * error, ERROR (-1) is returned, and errno is set to: + * On success, sched_rr_get_interval() returns OK (0). On error, + * ERROR (-1) is returned, and errno is set to: * * EFAULT -- Cannot copy to interval * EINVAL Invalid pid. @@ -107,8 +109,8 @@ int sched_rr_get_interval(pid_t pid, struct timespec *interval) #if CONFIG_RR_INTERVAL > 0 FAR _TCB *rrtcb; - /* If pid is zero, the timeslice for the calling process is - * written into 'interval.' + /* If pid is zero, the timeslice for the calling process is written + * into 'interval.' */ if (!pid) @@ -120,7 +122,7 @@ int sched_rr_get_interval(pid_t pid, struct timespec *interval) else if (pid < 0) { - *get_errno_ptr() = EINVAL; + set_errno(EINVAL); return ERROR; } @@ -131,14 +133,14 @@ int sched_rr_get_interval(pid_t pid, struct timespec *interval) rrtcb = sched_gettcb(pid); if (!rrtcb) { - *get_errno_ptr() = ESRCH; + set_errno(ESRCH); return ERROR; } } if (!interval) { - *get_errno_ptr() = EFAULT; + set_errno(EFAULT); return ERROR; } @@ -149,7 +151,7 @@ int sched_rr_get_interval(pid_t pid, struct timespec *interval) return OK; #else - *get_errno_ptr() = ENOSYS; + set_errno(ENOSYS); return ERROR; #endif } diff --git a/nuttx/sched/sched_self.c b/nuttx/sched/sched_self.c index 99a0f1995..9517e6306 100644 --- a/nuttx/sched/sched_self.c +++ b/nuttx/sched/sched_self.c @@ -2,7 +2,7 @@ * sched/sched_self.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/sched/sched_setparam.c b/nuttx/sched/sched_setparam.c index 2b0f804a6..6ea4e8f74 100644 --- a/nuttx/sched/sched_setparam.c +++ b/nuttx/sched/sched_setparam.c @@ -2,7 +2,7 @@ * sched/sched_setparam.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,10 +38,13 @@ ****************************************************************************/ #include + #include #include #include + #include + #include "os_internal.h" /**************************************************************************** @@ -78,23 +81,23 @@ * Description: * This function sets the priority of a specified task. * - * NOTE: Setting a task's priority to the same value has a similar - * effect to sched_yield() -- The task will be moved to after all other - * tasks with the same priority. + * NOTE: Setting a task's priority to the same value has a similar effect + * to sched_yield() -- The task will be moved to after all other tasks + * with the same priority. * * Inputs: - * pid - the task ID of the task to reprioritize. If pid is - * zero, the priority of the calling task is changed. - * param - A structure whose member sched_priority is the integer - * priority. The range of valid priority numbers is from - * SCHED_PRIORITY_MIN through SCHED_PRIORITY_MAX. + * pid - the task ID of the task to reprioritize. If pid is zero, the + * priority of the calling task is changed. + * param - A structure whose member sched_priority is the integer priority. + * The range of valid priority numbers is from SCHED_PRIORITY_MIN + * through SCHED_PRIORITY_MAX. * * Return Value: - * On success, sched_setparam() returns 0 (OK). On error, -1 - * (ERROR) is returned, and errno is set appropriately. + * On success, sched_setparam() returns 0 (OK). On error, -1 (ERROR) is + * returned, and errno is set appropriately. * - * EINVAL The parameter 'param' is invalid or does not make - * sense for the current scheduling policy. + * EINVAL The parameter 'param' is invalid or does not make sense for the + * current scheduling policy. * EPERM The calling task does not have appropriate privileges. * ESRCH The task whose ID is pid could not be found. * diff --git a/nuttx/sched/sched_setpriority.c b/nuttx/sched/sched_setpriority.c index c5b7839aa..6aa0789ea 100644 --- a/nuttx/sched/sched_setpriority.c +++ b/nuttx/sched/sched_setpriority.c @@ -2,7 +2,7 @@ * sched/sched_setpriority.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -80,20 +80,20 @@ * Description: * This function sets the priority of a specified task. * - * NOTE: Setting a task's priority to the same value has a similar - * effect to sched_yield() -- The task will be moved to after all other - * tasks with the same priority. + * NOTE: Setting a task's priority to the same value has a similar effect + * to sched_yield() -- The task will be moved to after all other tasks + * with the same priority. * * Inputs: * tcb - the TCB of task to reprioritize. * sched_priority - The new task priority * * Return Value: - * On success, sched_setparam() returns 0 (OK). On error, -1 - * (ERROR) is returned, and errno is set appropriately. + * On success, sched_setparam() returns 0 (OK). On error, -1 (ERROR) is + * returned, and errno is set appropriately. * - * EINVAL The parameter 'param' is invalid or does not make - * sense for the current scheduling policy. + * EINVAL The parameter 'param' is invalid or does not make sense for the + * current scheduling policy. * EPERM The calling task does not have appropriate privileges. * ESRCH The task whose ID is pid could not be found. * @@ -127,76 +127,77 @@ int sched_setpriority(FAR _TCB *tcb, int sched_priority) task_state = tcb->task_state; switch (task_state) { - /* CASE 1. The task is running or ready-to-run and a context switch - * may be caused by the re-prioritization - */ + /* CASE 1. The task is running or ready-to-run and a context switch + * may be caused by the re-prioritization + */ - case TSTATE_TASK_RUNNING: + case TSTATE_TASK_RUNNING: - /* A context switch will occur if the new priority of the running - * task becomes less than OR EQUAL TO the next highest priority - * ready to run task. - */ + /* A context switch will occur if the new priority of the running + * task becomes less than OR EQUAL TO the next highest priority + * ready to run task. + */ - if (sched_priority <= tcb->flink->sched_priority) - { - /* A context switch will occur. */ + if (sched_priority <= tcb->flink->sched_priority) + { + /* A context switch will occur. */ - up_reprioritize_rtr(tcb, (uint8_t)sched_priority); - } + up_reprioritize_rtr(tcb, (uint8_t)sched_priority); + } - /* Otherwise, we can just change priority since it has no effect */ + /* Otherwise, we can just change priority since it has no effect */ - else - { - /* Change the task priority */ + else + { + /* Change the task priority */ - tcb->sched_priority = (uint8_t)sched_priority; - } - break; + tcb->sched_priority = (uint8_t)sched_priority; + } + break; - /* CASE 2. The task is running or ready-to-run and a context switch - * may be caused by the re-prioritization - */ + /* CASE 2. The task is running or ready-to-run and a context switch + * may be caused by the re-prioritization + */ - case TSTATE_TASK_READYTORUN: + case TSTATE_TASK_READYTORUN: - /* A context switch will occur if the new priority of the ready-to - * run task is (strictly) greater than the current running task - */ + /* A context switch will occur if the new priority of the ready-to + * run task is (strictly) greater than the current running task + */ - if (sched_priority > rtcb->sched_priority) - { - /* A context switch will occur. */ + if (sched_priority > rtcb->sched_priority) + { + /* A context switch will occur. */ - up_reprioritize_rtr(tcb, (uint8_t)sched_priority); - } + up_reprioritize_rtr(tcb, (uint8_t)sched_priority); + } - /* Otherwise, we can just change priority and re-schedule (since it - * have no other effect). - */ + /* Otherwise, we can just change priority and re-schedule (since it + * have no other effect). + */ - else - { - /* Remove the TCB from the ready-to-run task list */ + else + { + /* Remove the TCB from the ready-to-run task list */ - ASSERT(!sched_removereadytorun(tcb)); + ASSERT(!sched_removereadytorun(tcb)); - /* Change the task priority */ + /* Change the task priority */ - tcb->sched_priority = (uint8_t)sched_priority; + tcb->sched_priority = (uint8_t)sched_priority; - /* Put it back into the ready-to-run task list */ + /* Put it back into the ready-to-run task list */ - ASSERT(!sched_addreadytorun(tcb)); - } - break; + ASSERT(!sched_addreadytorun(tcb)); + } + break; - /* CASE 3. The task is not in the ready to run list. Changing its - * Priority cannot effect the currently executing task. - */ + /* CASE 3. The task is not in the ready to run list. Changing its + * Priority cannot effect the currently executing task. + */ + + default: - default: /* CASE 3a. The task resides in a prioritized list. */ if (g_tasklisttable[task_state].prioritized) diff --git a/nuttx/sched/sched_setscheduler.c b/nuttx/sched/sched_setscheduler.c index dafab3e7b..7f7f345b4 100644 --- a/nuttx/sched/sched_setscheduler.c +++ b/nuttx/sched/sched_setscheduler.c @@ -38,11 +38,14 @@ ****************************************************************************/ #include + #include #include #include #include + #include + #include "os_internal.h" #include "clock_internal.h" @@ -78,28 +81,24 @@ * Name:sched_setscheduler * * Description: - * sched_setscheduler() sets both the scheduling policy - * and the priority for the task identified by pid. If - * pid equals zero, the scheduler of the calling task - * will be set. The parameter 'param' holds the priority + * sched_setscheduler() sets both the scheduling policy and the priority + * for the task identified by pid. If pid equals zero, the scheduler of + * the calling task will be set. The parameter 'param' holds the priority * of the thread under the new policy. * * Inputs: - * pid - the task ID of the task to modify. If pid is zero, - * the calling task is modified. - * policy - Scheduling policy requested (either SCHED_FIFO - * or SCHED_RR) - * param - A structure whose member sched_priority is the - * new priority. The range of valid priority numbers is - * from SCHED_PRIORITY_MIN through SCHED_PRIORITY_MAX. + * pid - the task ID of the task to modify. If pid is zero, the calling + * task is modified. + * policy - Scheduling policy requested (either SCHED_FIFO or SCHED_RR) + * param - A structure whose member sched_priority is the new priority. + * The range of valid priority numbers is from SCHED_PRIORITY_MIN + * through SCHED_PRIORITY_MAX. * * Return Value: - * On success, sched_setscheduler() returns OK (zero). On - * error, ERROR (-1) is returned, and errno is set - * appropriately: + * On success, sched_setscheduler() returns OK (zero). On error, ERROR + * (-1) is returned, and errno is set appropriately: * - * EINVAL The scheduling policy is not one of the - * recognized policies. + * EINVAL The scheduling policy is not one of the recognized policies. * ESRCH The task whose ID is pid could not be found. * * Assumptions: @@ -143,16 +142,14 @@ int sched_setscheduler(pid_t pid, int policy, return ERROR; } - /* Prohibit any context switches while we muck with - * priority and scheduler settings. + /* Prohibit any context switches while we muck with priority and scheduler + * settings. */ sched_lock(); #if CONFIG_RR_INTERVAL > 0 - /* Further, disable timer interrupts while we set up - * scheduling policy. - */ + /* Further, disable timer interrupts while we set up scheduling policy. */ saved_state = irqsave(); if (policy == SCHED_RR) @@ -165,9 +162,11 @@ int sched_setscheduler(pid_t pid, int policy, else { /* Set FIFO scheduling */ + tcb->flags &= ~TCB_FLAG_ROUND_ROBIN; tcb->timeslice = 0; } + irqrestore(saved_state); #endif diff --git a/nuttx/sched/sched_setupidlefiles.c b/nuttx/sched/sched_setupidlefiles.c index f2bfb78d2..ae814e1a6 100644 --- a/nuttx/sched/sched_setupidlefiles.c +++ b/nuttx/sched/sched_setupidlefiles.c @@ -62,7 +62,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sched_setupidlefiles + * Name: sched_setupidlefiles * * Description: * Configure the idle thread's TCB. @@ -83,32 +83,32 @@ int sched_setupidlefiles(FAR _TCB *tcb) int fd; #endif -#if CONFIG_NFILE_DESCRIPTORS > 0 /* Allocate file descriptors for the TCB */ +#if CONFIG_NFILE_DESCRIPTORS > 0 tcb->filelist = files_alloclist(); if (!tcb->filelist) { return -ENOMEM; } -#endif /* CONFIG_NFILE_DESCRIPTORS */ +#endif -#if CONFIG_NSOCKET_DESCRIPTORS > 0 /* Allocate socket descriptors for the TCB */ +#if CONFIG_NSOCKET_DESCRIPTORS > 0 tcb->sockets = net_alloclist(); if (!tcb->sockets) { return -ENOMEM; } -#endif /* CONFIG_NSOCKET_DESCRIPTORS */ +#endif -#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_DEV_CONSOLE) /* Open stdin, dup to get stdout and stderr. This should always * be the first file opened and, hence, should always get file * descriptor 0. */ +#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_DEV_CONSOLE) fd = open("/dev/console", O_RDWR); if (fd == 0) { @@ -134,17 +134,15 @@ int sched_setupidlefiles(FAR _TCB *tcb) } return -ENFILE; } +#endif + + /* Allocate file/socket streams for the TCB */ #if CONFIG_NFILE_STREAMS > 0 - /* Allocate file strems for the TCB */ - return sched_setupstreams(tcb); #else return OK; -#endif /* CONFIG_NFILE_STREAMS */ -#else - return OK; -#endif /* CONFIG_NFILE_DESCRIPTORS && CONFIG_DEV_CONSOLE */ +#endif } #endif /* CONFIG_NFILE_DESCRIPTORS || CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/sched/sched_setuppthreadfiles.c b/nuttx/sched/sched_setuppthreadfiles.c index 75e20ef0a..648d9273e 100644 --- a/nuttx/sched/sched_setuppthreadfiles.c +++ b/nuttx/sched/sched_setuppthreadfiles.c @@ -58,11 +58,11 @@ ****************************************************************************/ /**************************************************************************** - * Function: sched_setuppthreadfiles + * Name: sched_setuppthreadfiles * * Description: - * Configure a newly allocated TCB so that it will inherit - * file descriptors and streams from the parent pthread. + * Configure a newly allocated TCB so that it will inherit file + * descriptors and streams from the parent pthread. * * Parameters: * tcb - tcb of the new task. @@ -85,6 +85,16 @@ int sched_setuppthreadfiles(FAR _TCB *tcb) tcb->filelist = rtcb->filelist; files_addreflist(tcb->filelist); +#endif /* CONFIG_NFILE_DESCRIPTORS */ + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 + /* The child thread inherits the parent socket descriptors */ + + tcb->sockets = rtcb->sockets; + net_addreflist(tcb->sockets); + +#endif /* CONFIG_NSOCKET_DESCRIPTORS */ + #if CONFIG_NFILE_STREAMS > 0 /* The child thread inherits the parent streams */ @@ -92,16 +102,6 @@ int sched_setuppthreadfiles(FAR _TCB *tcb) lib_addreflist(tcb->streams); #endif /* CONFIG_NFILE_STREAMS */ -#endif /* CONFIG_NFILE_DESCRIPTORS */ - -#if CONFIG_NSOCKET_DESCRIPTORS > 0 - /* The child thread inherits the parent file descriptors */ - - tcb->sockets = rtcb->sockets; - net_addreflist(tcb->sockets); - -#endif /* CONFIG_NSOCKET_DESCRIPTORS */ - return OK; } diff --git a/nuttx/sched/sched_setupstreams.c b/nuttx/sched/sched_setupstreams.c index 0706e1188..22895b047 100644 --- a/nuttx/sched/sched_setupstreams.c +++ b/nuttx/sched/sched_setupstreams.c @@ -46,7 +46,12 @@ #include #include -#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 +/* Make sure that there are file or socket descriptors in the system and + * that some number of streams have been configured. + */ + +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 +#if CONFIG_NFILE_STREAMS > 0 /**************************************************************************** * Private Functions @@ -56,9 +61,18 @@ * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: sched_setupstreams + * + * Description: + * Setup streams data structures that may be used for standard C buffered + * I/O with underlying socket or file desciptors + * + ****************************************************************************/ + int sched_setupstreams(FAR _TCB *tcb) { - /* Allocate file strems for the TCB */ + /* Allocate file streams for the TCB */ tcb->streams = lib_alloclist(); if (tcb->streams) @@ -80,4 +94,5 @@ int sched_setupstreams(FAR _TCB *tcb) return OK; } -#endif /* CONFIG_NFILE_STREAMS && CONFIG_NFILE_STREAMS */ +#endif /* CONFIG_NFILE_STREAMS > 0 */ +#endif /* CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0*/ diff --git a/nuttx/sched/sched_setuptaskfiles.c b/nuttx/sched/sched_setuptaskfiles.c index 3b75fa350..7f754e151 100644 --- a/nuttx/sched/sched_setuptaskfiles.c +++ b/nuttx/sched/sched_setuptaskfiles.c @@ -69,12 +69,128 @@ * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: sched_dupfiles + * + * Description: + * Duplicate parent task's file descriptors. + * + * Input Parameters: + * tcb - tcb of the new task. + * + * Return Value: + * None + * + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_FDCLONE_DISABLE) +static inline void sched_dupfiles(FAR _TCB *tcb) +{ + /* The parent task is the one at the head of the ready-to-run list */ + + FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; + FAR struct file *parent; + FAR struct file *child; + int i; + + /* Duplicate the file descriptors. This will be either all of the + * file descriptors or just the first three (stdin, stdout, and stderr) + * if CONFIG_FDCLONE_STDIO is defined. NFSDS_TOCLONE is set + * accordingly above. + */ + + if (rtcb->filelist) + { + /* Get pointers to the parent and child task file lists */ + + parent = rtcb->filelist->fl_files; + child = tcb->filelist->fl_files; + + /* Check each file in the parent file list */ + + for (i = 0; i < NFDS_TOCLONE; i++) + { + /* Check if this file is opened by the parent. We can tell if + * if the file is open because it contain a reference to a non-NULL + * i-node structure. + */ + + if (parent[i].f_inode) + { + /* Yes... duplicate it for the child */ + + (void)files_dup(&parent[i], &child[i]); + } + } + } +} +#else /* CONFIG_NFILE_DESCRIPTORS && !CONFIG_FDCLONE_DISABLE */ +# define sched_dupfiles(tcb) +#endif /* CONFIG_NFILE_DESCRIPTORS && !CONFIG_FDCLONE_DISABLE */ + +/**************************************************************************** + * Name: sched_dupsockets + * + * Description: + * Duplicate the parent task's socket descriptors. + * + * Input Parameters: + * tcb - tcb of the new task. + * + * Return Value: + * None + * + ****************************************************************************/ + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 && !defined(CONFIG_SDCLONE_DISABLE) +static inline void sched_dupsockets(FAR _TCB *tcb) +{ + /* The parent task is the one at the head of the ready-to-run list */ + + FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; + FAR struct sockets *parent; + FAR struct sockets *child; + int i; + + /* Duplicate the socket descriptors of all sockets opened by the parent + * task. + */ + + if (rtcb->sockets) + { + /* Get pointers to the parent and child task socket lists */ + + parent = rtcb->sockets->sl_sockets; + child = tcb->sockets->sl_sockets; + + /* Check each socket in the parent socket list */ + + for (i = 0; i < CONFIG_NSOCKET_DESCRIPTORS; i++) + { + /* Check if this parent socket is allocated. We can tell if the + * socket is allocated because it will have a positive, non-zero + * reference count. + */ + + if (parent[i].s_crefs > 0) + { + /* Yes... duplicate it for the child */ + + (void)net_clone(&parent[i], &child[i]); + } + } + } +} +#else /* CONFIG_NSOCKET_DESCRIPTORS && !CONFIG_SDCLONE_DISABLE */ +# define sched_dupsockets(tcb) +#endif /* CONFIG_NSOCKET_DESCRIPTORS && !CONFIG_SDCLONE_DISABLE */ + /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Function: sched_setuptaskfiles + * Name: sched_setuptaskfiles * * Description: * Configure a newly allocated TCB so that it will inherit @@ -92,88 +208,41 @@ int sched_setuptaskfiles(FAR _TCB *tcb) { -#if CONFIG_NFILE_DESCRIPTORS > 0 - FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - int i; -#endif /* CONFIG_NFILE_DESCRIPTORS > 0 */ - int ret = OK; - -#if CONFIG_NFILE_DESCRIPTORS > 0 - /* Allocate file descriptors for the TCB */ +#if CONFIG_NFILE_DESCRIPTORS > 0 tcb->filelist = files_alloclist(); if (!tcb->filelist) { return -ENOMEM; } - -#endif /* CONFIG_NFILE_DESCRIPTORS */ - -#if CONFIG_NSOCKET_DESCRIPTORS > 0 +#endif /* Allocate socket descriptors for the TCB */ +#if CONFIG_NSOCKET_DESCRIPTORS > 0 tcb->sockets = net_alloclist(); if (!tcb->sockets) { return -ENOMEM; } - -#endif /* CONFIG_NSOCKET_DESCRIPTORS */ - -#if CONFIG_NFILE_DESCRIPTORS > 0 -#if !defined(CONFIG_FDCLONE_DISABLE) - - /* Duplicate the file descriptors. This will be either all of the - * file descriptors or just the first three (stdin, stdout, and stderr) - * if CONFIG_FDCLONE_STDIO is defined. NFSDS_TOCLONE is set - * accordingly above. - */ - - if (rtcb->filelist) - { - for (i = 0; i < NFDS_TOCLONE; i++) - { - /* Check if this file is opened */ - - if (rtcb->filelist->fl_files[i].f_inode) - { - (void)files_dup(&rtcb->filelist->fl_files[i], - &tcb->filelist->fl_files[i]); - } - } - } #endif + /* Duplicate the parent task's file descriptors */ + + sched_dupfiles(tcb); + + /* Duplicate the parent task's socket descriptors */ + + sched_dupsockets(tcb); + + /* Allocate file/socket streams for the new TCB */ + #if CONFIG_NFILE_STREAMS > 0 - - /* Allocate file streams for the TCB */ - - ret = sched_setupstreams(tcb); - -#endif /* CONFIG_NFILE_STREAMS */ -#endif /* CONFIG_NFILE_DESCRIPTORS */ - -#if CONFIG_NSOCKET_DESCRIPTORS > 0 && !defined(CONFIG_SDCLONE_DISABLE) - - /* Duplicate the socket descriptors */ - - if (rtcb->sockets) - { - for (i = 0; i < CONFIG_NSOCKET_DESCRIPTORS; i++) - { - /* Check if this socket is allocated */ - - if (rtcb->sockets->sl_sockets[i].s_crefs > 0) - { - (void)net_clone(&rtcb->sockets->sl_sockets[i], - &tcb->sockets->sl_sockets[i]); - } - } - } + return sched_setupstreams(tcb); +#else + return OK; #endif - return ret; } -#endif /* CONFIG_NFILE_DESCRIPTORS || CONFIG_NSOCKET_DESCRIPTORS */ +#endif /* CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0*/ diff --git a/nuttx/sched/sched_unlock.c b/nuttx/sched/sched_unlock.c index 302aea6b7..9a52e8358 100644 --- a/nuttx/sched/sched_unlock.c +++ b/nuttx/sched/sched_unlock.c @@ -2,7 +2,7 @@ * sched/sched_unlock.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -74,13 +74,14 @@ /************************************************************************ * Name: sched_unlock * - * Description: This function decrements the preemption lock - * count. Typically this is paired with sched_lock() and - * concludes a critical section of code. Preemption will not - * be unlocked until sched_unlock() has been called as many - * times as sched_lock(). When the lockcount is decremented - * to zero, any tasks that were eligible to preempt the - * current task will execute. + * Description: + * This function decrements the preemption lock count. Typically this + * is paired with sched_lock() and concludes a critical section of + * code. Preemption will not be unlocked until sched_unlock() has + * been called as many times as sched_lock(). When the lockcount is + * decremented to zero, any tasks that were eligible to preempt the + * current task will execute. + * ************************************************************************/ int sched_unlock(void) @@ -122,6 +123,7 @@ int sched_unlock(void) up_release_pending(); } } + irqrestore(flags); } return OK; diff --git a/nuttx/sched/sched_verifytcb.c b/nuttx/sched/sched_verifytcb.c index af7cdebe1..bcf097a5c 100644 --- a/nuttx/sched/sched_verifytcb.c +++ b/nuttx/sched/sched_verifytcb.c @@ -2,7 +2,7 @@ * sched/ched_verifytcb.c * * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/sched/sched_waitpid.c b/nuttx/sched/sched_waitpid.c index 5eefba371..9be622311 100644 --- a/nuttx/sched/sched_waitpid.c +++ b/nuttx/sched/sched_waitpid.c @@ -2,7 +2,7 @@ * sched/sched_waitpid.c * * Copyright (C) 2011-2012 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 @@ -58,7 +58,7 @@ *****************************************************************************/ /***************************************************************************** - * Function: sched_waitpid + * Name: sched_waitpid * * Description: * @@ -179,9 +179,9 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) { _TCB *tcb = sched_gettcb(pid); - bool mystat; - int err; - int ret; + bool mystat; + int err; + int ret; /* Disable pre-emption so that nothing changes in the following tests */ @@ -228,6 +228,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) { tcb->stat_loc = NULL; } + goto errout; } diff --git a/nuttx/sched/sched_yield.c b/nuttx/sched/sched_yield.c index a7af4c787..b2e6493d0 100644 --- a/nuttx/sched/sched_yield.c +++ b/nuttx/sched/sched_yield.c @@ -2,7 +2,7 @@ * sched/sched_yield.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -75,8 +75,8 @@ * Name: sched_yield * * Description: - * This function forces the calling task to give up the CPU - * (only to other tasks at the same priority). + * This function forces the calling task to give up the CPU (only to other + * tasks at the same priority). * * Inputs: * None @@ -92,9 +92,9 @@ int sched_yield(void) { FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; - /* This equivalent to just resetting the task priority to - * its current value since this will cause the task to - * be rescheduled behind any other tasks at the same priority. + /* This equivalent to just resetting the task priority to its current value + * since this will cause the task to be rescheduled behind any other tasks + * at the same priority. */ return sched_setpriority(rtcb, rtcb->sched_priority); diff --git a/nuttx/sched/sem_close.c b/nuttx/sched/sem_close.c index 279e42737..169fc0448 100644 --- a/nuttx/sched/sem_close.c +++ b/nuttx/sched/sem_close.c @@ -2,7 +2,7 @@ * sched/sem_close.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -71,7 +71,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sem_close + * Name: sem_close * * Description: * This function is called to indicate that the calling task is finished @@ -132,6 +132,7 @@ int sem_close(FAR sem_t *sem) } ret = OK; } + sched_unlock(); } diff --git a/nuttx/sched/sem_destroy.c b/nuttx/sched/sem_destroy.c index 95db46468..90a2b95ef 100644 --- a/nuttx/sched/sem_destroy.c +++ b/nuttx/sched/sem_destroy.c @@ -2,7 +2,7 @@ * lib/semaphore/sem_destroy.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -69,7 +69,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sem_destroy + * Name: sem_destroy * * Description: * This function is used to destroy the un-named semaphore indicated by @@ -120,7 +120,7 @@ int sem_destroy (FAR sem_t *sem) } else { - errno = -EINVAL; - return ERROR; + errno = -EINVAL; + return ERROR; } } diff --git a/nuttx/sched/sem_findnamed.c b/nuttx/sched/sem_findnamed.c index 3d73038b5..bcba47a8a 100644 --- a/nuttx/sched/sem_findnamed.c +++ b/nuttx/sched/sem_findnamed.c @@ -2,7 +2,7 @@ * sem_findnamed.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -68,11 +68,10 @@ ************************************************************************/ /************************************************************************ - * Function: sem_findnamed + * Name: sem_findnamed * * Description: - * Search the g_nsems list to find the semaphore with - * the matching name. + * Search the g_nsems list to find the semaphore with the matching name. * * Parameters: * name - semaphore name diff --git a/nuttx/sched/sem_holder.c b/nuttx/sched/sem_holder.c index 2dfc50ee6..6003c563d 100644 --- a/nuttx/sched/sem_holder.c +++ b/nuttx/sched/sem_holder.c @@ -2,7 +2,7 @@ * sched/sem_holder.c * * Copyright (C) 2009-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -64,7 +64,8 @@ * Private Type Declarations ****************************************************************************/ -typedef int (*holderhandler_t)(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg); +typedef int (*holderhandler_t)(FAR struct semholder_s *pholder, + FAR sem_t *sem, FAR void *arg); /**************************************************************************** * Global Variables @@ -86,7 +87,7 @@ static FAR struct semholder_s *g_freeholders; ****************************************************************************/ /**************************************************************************** - * Function: sem_allocholder + * Name: sem_allocholder ****************************************************************************/ static inline FAR struct semholder_s *sem_allocholder(sem_t *sem) @@ -125,11 +126,12 @@ static inline FAR struct semholder_s *sem_allocholder(sem_t *sem) #endif sdbg("Insufficient pre-allocated holders\n"); } + return pholder; } /**************************************************************************** - * Function: sem_findholder + * Name: sem_findholder ****************************************************************************/ static FAR struct semholder_s *sem_findholder(sem_t *sem, FAR _TCB *htcb) @@ -157,7 +159,7 @@ static FAR struct semholder_s *sem_findholder(sem_t *sem, FAR _TCB *htcb) } /**************************************************************************** - * Function: sem_findorallocateholder + * Name: sem_findorallocateholder ****************************************************************************/ static inline FAR struct semholder_s *sem_findorallocateholder(sem_t *sem, FAR _TCB *htcb) @@ -167,11 +169,12 @@ static inline FAR struct semholder_s *sem_findorallocateholder(sem_t *sem, FAR _ { pholder = sem_allocholder(sem); } + return pholder; } /**************************************************************************** - * Function: sem_freeholder + * Name: sem_freeholder ****************************************************************************/ static inline void sem_freeholder(sem_t *sem, FAR struct semholder_s *pholder) @@ -242,6 +245,7 @@ static int sem_foreachholder(FAR sem_t *sem, holderhandler_t handler, FAR void * ret = handler(pholder, sem, arg); } } + return ret; } @@ -261,7 +265,8 @@ static int sem_recoverholders(FAR struct semholder_s *pholder, FAR sem_t *sem, F * Name: sem_boostholderprio ****************************************************************************/ -static int sem_boostholderprio(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg) +static int sem_boostholderprio(FAR struct semholder_s *pholder, + FAR sem_t *sem, FAR void *arg) { FAR _TCB *htcb = (FAR _TCB *)pholder->holder; FAR _TCB *rtcb = (FAR _TCB*)arg; @@ -343,15 +348,15 @@ static int sem_boostholderprio(FAR struct semholder_s *pholder, FAR sem_t *sem, * because the thread is already running at a sufficient priority. */ - else if (rtcb->sched_priority > htcb->sched_priority) - { - /* Raise the priority of the holder of the semaphore. This - * cannot cause a context switch because we have preemption - * disabled. The task will be marked "pending" and the switch - * will occur during up_block_task() processing. - */ + else if (rtcb->sched_priority > htcb->sched_priority) + { + /* Raise the priority of the holder of the semaphore. This + * cannot cause a context switch because we have preemption + * disabled. The task will be marked "pending" and the switch + * will occur during up_block_task() processing. + */ - (void)sched_setpriority(htcb, rtcb->sched_priority); + (void)sched_setpriority(htcb, rtcb->sched_priority); } #endif @@ -365,7 +370,6 @@ static int sem_boostholderprio(FAR struct semholder_s *pholder, FAR sem_t *sem, #ifdef CONFIG_DEBUG static int sem_verifyholder(FAR struct semholder_s *pholder, FAR sem_t *sem, FAR void *arg) { -// REMOVE ME #if 0 // Need to revisit this, but these assumptions seem to be untrue -- OR there is a bug??? FAR _TCB *htcb = (FAR _TCB *)pholder->holder; @@ -443,7 +447,7 @@ static int sem_restoreholderprio(FAR struct semholder_s *pholder, FAR sem_t *sem DEBUGASSERT(htcb->sched_priority == stcb->sched_priority && htcb->npend_reprio == 0); sched_reprioritize(htcb, htcb->base_priority); - } + } /* There are multiple pending priority levels. The thread's "boosted" * priority could greater than or equal to "stcb->sched_priority" (it could be @@ -475,6 +479,7 @@ static int sem_restoreholderprio(FAR struct semholder_s *pholder, FAR sem_t *sem { htcb->pend_reprios[j] = htcb->pend_reprios[i]; } + htcb->npend_reprio = i; /* And apply that priority to the thread (while retaining the base_priority) */ @@ -518,6 +523,7 @@ static int sem_restoreholderprio(FAR struct semholder_s *pholder, FAR sem_t *sem sched_reprioritize(htcb, htcb->base_priority); #endif } + return 0; } @@ -532,6 +538,7 @@ static int sem_restoreholderprioA(FAR struct semholder_s *pholder, FAR sem_t *se { return sem_restoreholderprio(pholder, sem, arg); } + return 0; } @@ -543,6 +550,7 @@ static int sem_restoreholderprioB(FAR struct semholder_s *pholder, FAR sem_t *se (void)sem_restoreholderprio(pholder, sem, arg); return 1; } + return 0; } @@ -551,7 +559,7 @@ static int sem_restoreholderprioB(FAR struct semholder_s *pholder, FAR sem_t *se ****************************************************************************/ /**************************************************************************** - * Function: sem_initholders + * Name: sem_initholders * * Description: * Called from sem_initialize() to set up semaphore holder information. @@ -583,7 +591,7 @@ void sem_initholders(void) } /**************************************************************************** - * Function: sem_destroyholder + * Name: sem_destroyholder * * Description: * Called from sem_destroy() to handle any holders of a semaphore when @@ -623,12 +631,13 @@ void sem_destroyholder(FAR sem_t *sem) { sdbg("Semaphore destroyed with holder\n"); } + sem->hlist.holder = NULL; #endif } /**************************************************************************** - * Function: sem_addholder + * Name: sem_addholder * * Description: * Called from sem_wait() when the calling thread obtains the semaphore @@ -661,7 +670,7 @@ void sem_addholder(FAR sem_t *sem) } /**************************************************************************** - * Function: void sem_boostpriority(sem_t *sem) + * Name: void sem_boostpriority(sem_t *sem) * * Description: * @@ -689,7 +698,7 @@ void sem_boostpriority(FAR sem_t *sem) } /**************************************************************************** - * Function: sem_releaseholder + * Name: sem_releaseholder * * Description: * Called from sem_post() after a thread releases one count on the @@ -724,7 +733,7 @@ void sem_releaseholder(FAR sem_t *sem) } /**************************************************************************** - * Function: sem_restorebaseprio + * Name: sem_restorebaseprio * * Description: * This function is called after the current running task releases a @@ -816,7 +825,7 @@ void sem_restorebaseprio(FAR _TCB *stcb, FAR sem_t *sem) } /**************************************************************************** - * Function: sem_canceled + * Name: sem_canceled * * Description: * Called from sem_waitirq() after a thread that was waiting for a semaphore @@ -848,7 +857,7 @@ void sem_canceled(FAR _TCB *stcb, FAR sem_t *sem) #endif /**************************************************************************** - * Function: sem_enumholders + * Name: sem_enumholders * * Description: * Show information about threads currently waiting on this semaphore @@ -871,7 +880,7 @@ void sem_enumholders(FAR sem_t *sem) #endif /**************************************************************************** - * Function: sem_nfreeholders + * Name: sem_nfreeholders * * Description: * Return the number of available holder containers. This is a good way diff --git a/nuttx/sched/sem_initialize.c b/nuttx/sched/sem_initialize.c index e9ebfb737..d8b402825 100644 --- a/nuttx/sched/sem_initialize.c +++ b/nuttx/sched/sem_initialize.c @@ -72,12 +72,11 @@ dq_queue_t g_nsems; ****************************************************************************/ /**************************************************************************** - * Function: sem_initialize + * Name: sem_initialize * * Description: - * The control structures for all semaphores may be - * initialized by calling sem_initialize. This should be - * done once at poweron. + * The control structures for all semaphores may be initialized by calling + * sem_initialize(). This should be done once at poweron. * * Parameters: * None diff --git a/nuttx/sched/sem_internal.h b/nuttx/sched/sem_internal.h index 4688e0cae..434c551a4 100644 --- a/nuttx/sched/sem_internal.h +++ b/nuttx/sched/sem_internal.h @@ -68,6 +68,7 @@ struct nsem_s bool unlinked; /* true if the semaphore has been unlinked */ sem_t sem; /* The semaphore itself */ }; + typedef struct nsem_s nsem_t; /**************************************************************************** diff --git a/nuttx/sched/sem_open.c b/nuttx/sched/sem_open.c index d5b22f018..817c36b49 100644 --- a/nuttx/sched/sem_open.c +++ b/nuttx/sched/sem_open.c @@ -47,7 +47,9 @@ #include #include #include + #include + #include "sem_internal.h" /**************************************************************************** @@ -75,7 +77,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sem_open + * Name: sem_open * * Description: * This function establishes a connection between named semaphores and a @@ -198,6 +200,7 @@ FAR sem_t *sem_open (FAR const char *name, int oflag, ...) } } } + sched_unlock(); } diff --git a/nuttx/sched/sem_post.c b/nuttx/sched/sem_post.c index 183ca362a..b3780db1f 100644 --- a/nuttx/sched/sem_post.c +++ b/nuttx/sched/sem_post.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sem_post + * Name: sem_post * * Description: * When a task has finished with a semaphore, it will call sem_post(). diff --git a/nuttx/sched/sem_timedwait.c b/nuttx/sched/sem_timedwait.c index 5a1b943a5..6a4724406 100644 --- a/nuttx/sched/sem_timedwait.c +++ b/nuttx/sched/sem_timedwait.c @@ -2,7 +2,7 @@ * sched/sem_timedwait.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -74,7 +74,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sem_timeout + * Name: sem_timeout * * Description: * This function is called if the timeout elapses before the message queue @@ -127,7 +127,7 @@ static void sem_timeout(int argc, uint32_t pid) ****************************************************************************/ /**************************************************************************** - * Function: sem_timedwait + * Name: sem_timedwait * * Description: * This function will lock the semaphore referenced by sem as in the diff --git a/nuttx/sched/sem_trywait.c b/nuttx/sched/sem_trywait.c index d50dc106d..cbd8dae69 100644 --- a/nuttx/sched/sem_trywait.c +++ b/nuttx/sched/sem_trywait.c @@ -2,7 +2,7 @@ * sched/sem_trywait.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -73,23 +73,22 @@ ****************************************************************************/ /**************************************************************************** - * Function: sem_trywait + * Name: sem_trywait * * Description: - * This function locks the specified semaphore only if the - * semaphore is currently not locked. Otherwise, it locks - * the semaphore. In either case, the call returns without - * blocking. + * This function locks the specified semaphore only if the semaphore is + * currently not locked. Otherwise, it locks the semaphore. In either + * case, the call returns without blocking. * * Parameters: * sem - the semaphore descriptor * * Return Value: - * 0 (OK) or -1 (ERROR) if unsuccessful - * If this function returns -1 (ERROR), then the cause - * of the failure will be reported in "errno" as: - * - EINVAL: Invalid attempt to get the semaphore - * - EAGAIN: The semaphore is not available. + * 0 (OK) or -1 (ERROR) if unsuccessful. If this function returns -1 + * (ERROR),then the cause of the failure will be reported in "errno" as: + * + * EINVAL: Invalid attempt to get the semaphore + * EAGAIN: The semaphore is not available. * * Assumptions: * @@ -107,13 +106,12 @@ int sem_trywait(FAR sem_t *sem) /* Assume any errors reported are due to invalid arguments. */ - *get_errno_ptr() = EINVAL; + set_errno(EINVAL); if (sem) { - /* The following operations must be performed with interrupts - * disabled because sem_post() may be called from an interrupt - * handler. + /* The following operations must be performed with interrupts disabled + * because sem_post() may be called from an interrupt handler. */ saved_state = irqsave(); @@ -122,7 +120,7 @@ int sem_trywait(FAR sem_t *sem) * is not available. */ - *get_errno_ptr() = EAGAIN; + set_errno(EAGAIN); /* If the semaphore is available, give it to the requesting task */ diff --git a/nuttx/sched/sem_unlink.c b/nuttx/sched/sem_unlink.c index ec0864180..6fe011540 100644 --- a/nuttx/sched/sem_unlink.c +++ b/nuttx/sched/sem_unlink.c @@ -2,7 +2,7 @@ * sched/sem_unlink.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sem_unlink + * Name: sem_unlink * * Description: * This function removes the semaphore named by the input parameter 'name.' @@ -114,6 +114,7 @@ int sem_unlink(FAR const char *name) /* If the named semaphore was found and if there are no * connects to it, then deallocate it */ + if (!psem->nconnect) { dq_rem((FAR dq_entry_t*)psem, &g_nsems); @@ -131,6 +132,7 @@ int sem_unlink(FAR const char *name) } ret = OK; } + sched_unlock(); } diff --git a/nuttx/sched/sem_wait.c b/nuttx/sched/sem_wait.c index 98097c991..9dfbaa6c3 100644 --- a/nuttx/sched/sem_wait.c +++ b/nuttx/sched/sem_wait.c @@ -73,7 +73,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sem_wait + * Name: sem_wait * * Description: * This function attempts to lock the semaphore referenced by 'sem'. If diff --git a/nuttx/sched/sem_waitirq.c b/nuttx/sched/sem_waitirq.c index 409cf780a..3d3af18de 100644 --- a/nuttx/sched/sem_waitirq.c +++ b/nuttx/sched/sem_waitirq.c @@ -2,7 +2,7 @@ * sched/sem_waitirq.c * * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -70,7 +70,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sem_waitirq + * Name: sem_waitirq * * Description: * This function is called when a signal is received by a task that is diff --git a/nuttx/sched/sig_action.c b/nuttx/sched/sig_action.c index cc4ea263b..fef5f1558 100644 --- a/nuttx/sched/sig_action.c +++ b/nuttx/sched/sig_action.c @@ -2,7 +2,7 @@ * sched/sig_action.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -73,7 +73,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sig_allocateaction + * Name: sig_allocateaction * * Description: * Allocate a new element for a sigaction queue @@ -103,7 +103,7 @@ static FAR sigactq_t *sig_allocateaction(void) { PANIC(OSERR_OUTOFMEMORY); } - } + } return sigact; } @@ -113,7 +113,7 @@ static FAR sigactq_t *sig_allocateaction(void) ****************************************************************************/ /**************************************************************************** - * Function: sigaction + * Name: sigaction * * Description: * This function allows the calling process to examine and/or specify the @@ -257,7 +257,7 @@ int sigaction(int signo, FAR const struct sigaction *act, FAR struct sigaction * } /**************************************************************************** - * Function: sig_releaseaction + * Name: sig_releaseaction * * Description: * Deallocate a sigaction Q entry diff --git a/nuttx/sched/sig_allocatependingsigaction.c b/nuttx/sched/sig_allocatependingsigaction.c index 3294a0ab8..15d6470ca 100644 --- a/nuttx/sched/sig_allocatependingsigaction.c +++ b/nuttx/sched/sig_allocatependingsigaction.c @@ -2,7 +2,7 @@ * sched/sig_allocatependingsigaction.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -71,10 +71,11 @@ ************************************************************************/ /************************************************************************ - * Function: sig_allocatependingsigaction + * Name: sig_allocatependingsigaction * * Description: * Allocate a new element for the pending signal action queue + * ************************************************************************/ FAR sigq_t *sig_allocatependingsigaction(void) diff --git a/nuttx/sched/sig_cleanup.c b/nuttx/sched/sig_cleanup.c index 7fb0d1a9c..4dcc04f8b 100644 --- a/nuttx/sched/sig_cleanup.c +++ b/nuttx/sched/sig_cleanup.c @@ -2,7 +2,7 @@ * sched/sig_cleanup.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -68,13 +68,13 @@ ************************************************************************/ /************************************************************************ - * Function: sig_cleanup + * Name: sig_cleanup * * Description: - * Deallocate all signal-related lists in a TCB. This function - * is called only at task deletion time. The caller is - * expected to have assured the critical section necessary - * to perform this action. + * Deallocate all signal-related lists in a TCB. This function is + * called only at task deletion time. The caller is expected to have + * assured the critical section necessary to perform this action. + * ************************************************************************/ void sig_cleanup(FAR _TCB *stcb) diff --git a/nuttx/sched/sig_deliver.c b/nuttx/sched/sig_deliver.c index bbfe0965c..a1297fbc2 100644 --- a/nuttx/sched/sig_deliver.c +++ b/nuttx/sched/sig_deliver.c @@ -75,12 +75,11 @@ ****************************************************************************/ /**************************************************************************** - * Function: sig_deliver + * Name: sig_deliver * * Description: - * This function is called on the thread of execution of - * the signal receiving task. It processes all queued - * signals then returns. + * This function is called on the thread of execution of the signal + * receiving task. It processes all queued signals then returns. * ****************************************************************************/ diff --git a/nuttx/sched/sig_findaction.c b/nuttx/sched/sig_findaction.c index 6c9d7386f..4115332b6 100644 --- a/nuttx/sched/sig_findaction.c +++ b/nuttx/sched/sig_findaction.c @@ -2,7 +2,7 @@ * sched/sig_findaction.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -65,7 +65,7 @@ ************************************************************************/ /************************************************************************ - * Function: sig_findaction + * Name: sig_findaction * * Description: * Allocate a new element for a signal queue @@ -94,7 +94,7 @@ FAR sigactq_t *sig_findaction(FAR _TCB *stcb, int signo) sigact = sigact->flink); sched_unlock(); - } + } - return sigact; + return sigact; } diff --git a/nuttx/sched/sig_initialize.c b/nuttx/sched/sig_initialize.c index 4c225350a..966d818a1 100644 --- a/nuttx/sched/sig_initialize.c +++ b/nuttx/sched/sig_initialize.c @@ -2,7 +2,7 @@ * sched/sig_initialize.c * * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -58,33 +58,33 @@ * Global Variables ************************************************************************/ -/* The g_sigfreeaction data structure is a list of available - * signal action structures. */ +/* The g_sigfreeaction data structure is a list of available signal + * action structures. + */ sq_queue_t g_sigfreeaction; -/* The g_sigpendingaction data structure is a list of available - * pending signal action structures. +/* The g_sigpendingaction data structure is a list of available pending + * signal action structures. */ sq_queue_t g_sigpendingaction; -/* The g_sigpendingirqaction is a list of available - * pending signal actions that are reserved for use by - * interrupt handlers. +/* The g_sigpendingirqaction is a list of available pending signal actions + * that are reserved for use by interrupt handlers. */ sq_queue_t g_sigpendingirqaction; -/* The g_sigpendingsignal data structure is a list of - * available pending signal structures. +/* The g_sigpendingsignal data structure is a list of available pending + * signal structures. */ sq_queue_t g_sigpendingsignal; -/* The g_sigpendingirqsignal data structure is a list - * of available pending signal structures that are reserved - * for use by interrupt handlers. +/* The g_sigpendingirqsignal data structure is a list of available + * pending signal structures that are reserved for use by interrupt + * handlers. */ sq_queue_t g_sigpendingirqsignal; @@ -93,32 +93,32 @@ sq_queue_t g_sigpendingirqsignal; * Private Variables ************************************************************************/ -/* g_sigactionalloc is a pointer to the start of the - * allocated blocks of signal actions. +/* g_sigactionalloc is a pointer to the start of the allocated blocks of + * signal actions. */ static sigactq_t *g_sigactionalloc; -/* g_sigpendingactionalloc is a pointer to the start of the - * allocated blocks of pending signal actions. +/* g_sigpendingactionalloc is a pointer to the start of the allocated + * blocks of pending signal actions. */ static sigq_t *g_sigpendingactionalloc; -/* g_sigpendingirqactionalloc is a pointer to the start of - * the allocated block of pending signal actions. +/* g_sigpendingirqactionalloc is a pointer to the start of the allocated + * block of pending signal actions. */ static sigq_t *g_sigpendingirqactionalloc; -/* g_sigpendingsignalalloc is a pointer to the start of the - * allocated blocks of pending signals. +/* g_sigpendingsignalalloc is a pointer to the start of the allocated + * blocks of pending signals. */ static sigpendq_t *g_sigpendingsignalalloc; -/* g_sigpendingirqsignalalloc is a pointer to the start of - * the allocated blocks of pending signals. +/* g_sigpendingirqsignalalloc is a pointer to the start of the allocated + * blocks of pending signals. */ static sigpendq_t *g_sigpendingirqsignalalloc; @@ -137,7 +137,7 @@ static sigpendq_t *sig_allocatependingsignalblock(sq_queue_t *siglist, ************************************************************************/ /************************************************************************ - * Function: sig_allocateblock + * Name: sig_allocateblock * * Description: * Allocate a block of pending signal actions and place them @@ -167,15 +167,16 @@ static sigq_t *sig_allocateblock(sq_queue_t *siglist, uint16_t nsigs, } /************************************************************************ - * Function: sig_allocatependingsignalblock + * Name: sig_allocatependingsignalblock * * Description: - * Allocate a block of pending signal structures and place them - * on the free list. + * Allocate a block of pending signal structures and place them on + * the free list. + * ************************************************************************/ static sigpendq_t *sig_allocatependingsignalblock(sq_queue_t *siglist, - uint16_t nsigs, uint8_t sigtype) + uint16_t nsigs, uint8_t sigtype) { sigpendq_t *sigpendalloc; sigpendq_t *sigpend; @@ -201,10 +202,11 @@ static sigpendq_t *sig_allocatependingsignalblock(sq_queue_t *siglist, ************************************************************************/ /************************************************************************ - * Function: sig_initialize + * Name: sig_initialize * * Description: - * Perform one-time power-up initialization + * Perform one-time power-up initialization + * ************************************************************************/ void sig_initialize(void) @@ -218,19 +220,24 @@ void sig_initialize(void) sq_init(&g_sigpendingirqsignal); /* Add a block of signal structures to each list */ + g_sigpendingactionalloc = sig_allocateblock(&g_sigpendingaction, NUM_PENDING_ACTIONS, SIG_ALLOC_FIXED); + g_sigpendingirqactionalloc = sig_allocateblock(&g_sigpendingirqaction, NUM_PENDING_INT_ACTIONS, SIG_ALLOC_IRQ); + sig_allocateactionblock(); + g_sigpendingsignalalloc = sig_allocatependingsignalblock(&g_sigpendingsignal, NUM_SIGNALS_PENDING, SIG_ALLOC_FIXED); + g_sigpendingirqsignalalloc = sig_allocatependingsignalblock(&g_sigpendingirqsignal, NUM_INT_SIGNALS_PENDING, @@ -238,11 +245,12 @@ void sig_initialize(void) } /************************************************************************ - * Function: sig_allocateactionblock + * Name: sig_allocateactionblock * * Description: * Allocate a block of signal actions and place them * on the free list. + * ************************************************************************/ void sig_allocateactionblock(void) @@ -261,5 +269,3 @@ void sig_allocateactionblock(void) sq_addlast((FAR sq_entry_t*)sigact++, &g_sigfreeaction); } } - - diff --git a/nuttx/sched/sig_internal.h b/nuttx/sched/sig_internal.h index 877400b1b..6c0641742 100644 --- a/nuttx/sched/sig_internal.h +++ b/nuttx/sched/sig_internal.h @@ -2,7 +2,7 @@ * sched/sig_internal.h * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __SIG_INTERNAL_H -#define __SIG_INTERNAL_H +#ifndef __SCHED_SIG_INTERNAL_H +#define __SCHED_SIG_INTERNAL_H /**************************************************************************** * Included Files @@ -84,10 +84,10 @@ struct sigactq }; typedef struct sigactq sigactq_t; -/* The following defines the queue structure within each TCB - * to hold pending signals received by the task. These are signals that - * cannot be processed because: (1) the task is not waiting for them, or - * (2) the task has no action associated with the signal. +/* The following defines the queue structure within each TCB to hold pending + * signals received by the task. These are signals that cannot be processed + * because: (1) the task is not waiting for them, or (2) the task has no + * action associated with the signal. */ struct sigpendq @@ -98,8 +98,8 @@ struct sigpendq }; typedef struct sigpendq sigpendq_t; -/* The following defines the queue structure within each TCB - * to hold queued signal actions that need action by the task +/* The following defines the queue structure within each TCB to hold queued + * signal actions that need action by the task */ struct sigq_s @@ -110,7 +110,7 @@ struct sigq_s void (*sighandler)(int signo, siginfo_t *info, void *context); } action; /* Signal action */ sigset_t mask; /* Additional signals to mask while the - * the signal-catching functin executes */ + * the signal-catching function executes */ siginfo_t info; /* Signal information */ uint8_t type; /* (Used to manage allocations) */ }; @@ -158,34 +158,33 @@ extern sq_queue_t g_sigpendingirqsignal; /* sig_intialize.c */ -extern void weak_function sig_initialize(void); -extern void sig_allocateactionblock(void); +void weak_function sig_initialize(void); +void sig_allocateactionblock(void); /* sig_action.c */ -extern void sig_releaseaction(FAR sigactq_t *sigact); +void sig_releaseaction(FAR sigactq_t *sigact); /* sig_pending.c */ -extern sigset_t sig_pendingset(FAR _TCB *stcb); +sigset_t sig_pendingset(FAR _TCB *stcb); /* In files of the same name */ -extern FAR sigq_t *sig_allocatependingsigaction(void); -extern void sig_cleanup(FAR _TCB *stcb); -extern void sig_deliver(FAR _TCB *stcb); -extern FAR sigactq_t *sig_findaction(FAR _TCB *stcb, int signo); -extern int sig_lowest(sigset_t *set); +FAR sigq_t *sig_allocatependingsigaction(void); +void sig_cleanup(FAR _TCB *stcb); +void sig_deliver(FAR _TCB *stcb); +FAR sigactq_t *sig_findaction(FAR _TCB *stcb, int signo); +int sig_lowest(FAR sigset_t *set); #ifdef CONFIG_CAN_PASS_STRUCTS -extern int sig_mqnotempty(int tid, int signo, union sigval value); +int sig_mqnotempty(int tid, int signo, union sigval value); #else -extern int sig_mqnotempty(int tid, int signo, - void *sival_ptr); +int sig_mqnotempty(int tid, int signo, FAR void *sival_ptr); #endif -extern int sig_received(FAR _TCB *stcb, siginfo_t *info); -extern void sig_releasependingsigaction(FAR sigq_t *sigq); -extern void sig_releasependingsignal(FAR sigpendq_t *sigpend); -extern FAR sigpendq_t *sig_removependingsignal(FAR _TCB *stcb, int signo); -extern void sig_unmaskpendingsignal(void); +int sig_received(FAR _TCB *stcb, FAR siginfo_t *info); +void sig_releasependingsigaction(FAR sigq_t *sigq); +void sig_releasependingsignal(FAR sigpendq_t *sigpend); +FAR sigpendq_t *sig_removependingsignal(FAR _TCB *stcb, int signo); +void sig_unmaskpendingsignal(void); -#endif /* __SIG_INTERNAL_H */ +#endif /* __SCHED_SIG_INTERNAL_H */ diff --git a/nuttx/sched/sig_kill.c b/nuttx/sched/sig_kill.c index 1573a17a9..17921015f 100644 --- a/nuttx/sched/sig_kill.c +++ b/nuttx/sched/sig_kill.c @@ -52,29 +52,25 @@ ************************************************************************/ /************************************************************************ - * Function: kill + * Name: kill * * Description: - * The kill() system call can be used to send any signal to - * any task. + * The kill() system call can be used to send any signal to any task. * - * Limitation: Sending of signals to 'process groups' is - * not supported in NuttX + * Limitation: Sending of signals to 'process groups' is not + * supported in NuttX * * Parameters: - * pid - The id of the task to receive the signal. The - * POSIX kill specification encodes process group - * information as zero and negative pid values. Only - * positive, non-zero values of pid are supported by this - * implementation. - * signo - The signal number to send. If signo is zero, - * no signal is sent, but all error checking is performed. + * pid - The id of the task to receive the signal. The POSIX kill + * specification encodes process group information as zero and + * negative pid values. Only positive, non-zero values of pid are + * supported by this implementation. + * signo - The signal number to send. If signo is zero, no signal is + * sent, but all error checking is performed. * - * - * Return Value: - * On success (at least one signal was sent), zero is - * returned. On error, -1 is returned, and errno is set - * appropriately. + * Returned Value: + * On success (at least one signal was sent), zero is returned. On + * error, -1 is returned, and errno is set appropriately: * * EINVAL An invalid signal was specified. * EPERM The process does not have permission to send the diff --git a/nuttx/sched/sig_lowest.c b/nuttx/sched/sig_lowest.c index cb009a706..f5654eb47 100644 --- a/nuttx/sched/sig_lowest.c +++ b/nuttx/sched/sig_lowest.c @@ -2,7 +2,7 @@ * sched/sig_lowest.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -68,9 +68,10 @@ ************************************************************************/ /************************************************************************ - * Function: sig_lowest + * Name: sig_lowest * * Description: + * Return the lowest signal number that is a member of a set of signals. * ************************************************************************/ diff --git a/nuttx/sched/sig_mqnotempty.c b/nuttx/sched/sig_mqnotempty.c index a9f05e28b..9a1fd7243 100644 --- a/nuttx/sched/sig_mqnotempty.c +++ b/nuttx/sched/sig_mqnotempty.c @@ -2,7 +2,7 @@ * sched/sig_mqnotempty.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -72,14 +72,13 @@ ****************************************************************************/ /**************************************************************************** - * Function: sig_mqnotempty + * Name: sig_mqnotempty * * Description: - * This function is equivalent to sigqueue(), but supports - * the messaging system's requirement to signal a task when - * a message queue becomes non-empty. It is identical to - * sigqueue(), except that it sets the si_code field in - * the siginfo structure to SI_MESGQ rather than SI_QUEUE. + * This function is equivalent to sigqueue(), but supports the messaging + * system's requirement to signal a task when a message queue becomes + * non-empty. It is identical to sigqueue(), except that it sets the + * si_code field in the siginfo structure to SI_MESGQ rather than SI_QUEUE. * ****************************************************************************/ @@ -118,10 +117,11 @@ int sig_mqnotempty (int pid, int signo, void *sival_ptr) /* Verify that we can perform the signalling operation */ if ((stcb) && (GOOD_SIGNO(signo))) - { - /* Process the receipt of the signal */ - ret = sig_received(stcb, &info); - } + { + /* Process the receipt of the signal */ + + ret = sig_received(stcb, &info); + } sched_unlock(); return ret; diff --git a/nuttx/sched/sig_pending.c b/nuttx/sched/sig_pending.c index 1c6021050..eaabbff6b 100644 --- a/nuttx/sched/sig_pending.c +++ b/nuttx/sched/sig_pending.c @@ -2,7 +2,7 @@ * sched/sig_pending.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -70,7 +70,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sigpending + * Name: sigpending * * Description: * This function stores the returns the set of signals that are blocked @@ -96,13 +96,13 @@ int sigpending(FAR sigset_t *set) { *set = sig_pendingset(rtcb); ret = OK; - } + } return ret; } /**************************************************************************** - * Function: sig_pendingset + * Name: sig_pendingset * * Description: * Convert the list of pending signals into a signal set @@ -123,6 +123,7 @@ sigset_t sig_pendingset(FAR _TCB *stcb) { sigaddset(&sigpendset, sigpend->info.si_signo); } + irqrestore(saved_state); return sigpendset; diff --git a/nuttx/sched/sig_procmask.c b/nuttx/sched/sig_procmask.c index 00ef53904..c67159589 100644 --- a/nuttx/sched/sig_procmask.c +++ b/nuttx/sched/sig_procmask.c @@ -2,7 +2,7 @@ * sched/sig_procmask.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -77,7 +77,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sigprocmask + * Name: sigprocmask * * Description: * This function allows the calling process to examine and/or change its @@ -167,6 +167,7 @@ int sigprocmask(int how, FAR const sigset_t *set, FAR sigset_t *oset) ret = ERROR; break; } + irqrestore(saved_state); /* Now, process any pending signals that were just unmasked */ diff --git a/nuttx/sched/sig_queue.c b/nuttx/sched/sig_queue.c index 3bb35c564..dee1c798a 100644 --- a/nuttx/sched/sig_queue.c +++ b/nuttx/sched/sig_queue.c @@ -2,7 +2,7 @@ * sched/sig_queue.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -44,6 +44,7 @@ #include #include #include + #include "os_internal.h" #include "sig_internal.h" @@ -72,20 +73,18 @@ ****************************************************************************/ /**************************************************************************** - * Function: sigqueue + * Name: sigqueue * * Description: - * This function sends the signal specified by signo with - * the signal parameter value to the process specified by - * pid. + * This function sends the signal specified by signo with the signal + * parameter value to the process specified by pid. * - * If the receiving process has the signal blocked via the - * sigprocmask, the signal will pend until it is unmasked. - * Only one pending signal (per signo) is retained. This - * is consistent with POSIX which states, "If a subsequent - * occurrence of a pending signal is generated, it is - * implementation defined as to whether the signal is - * delivered more than once." + * If the receiving process has the signal blocked via the sigprocmask, + * the signal will pend until it is unmasked. Only one pending signal (per + * signo) is retained. This is consistent with POSIX which states, "If + * a subsequent occurrence of a pending signal is generated, it is + * implementation defined as to whether the signal is delivered more than + * once." * * Parameters: * pid - Process ID of task to receive signal @@ -93,9 +92,8 @@ * value - Value to pass to task with signal * * Return Value: - * On success (at least one signal was sent), zero is - * returned. On error, -1 is returned, and errno is set - * appropriately. + * On success (at least one signal was sent), zero is returned. On + * error, -1 is returned, and errno is set appropriately: * * EGAIN The limit of signals which may be queued has been reached. * EINVAL sig was invalid. @@ -117,11 +115,11 @@ int sigqueue(int pid, int signo, void *sival_ptr) siginfo_t info; int ret = ERROR; - /* sanity checks */ + /* Sanity checks */ if (!GOOD_SIGNO(signo)) { - *get_errno_ptr() = EINVAL; + set_errno(EINVAL); return ERROR; } @@ -137,7 +135,7 @@ int sigqueue(int pid, int signo, void *sival_ptr) #endif if (pid == 0 || !stcb) { - *get_errno_ptr() = ESRCH; + set_errno(ESRCH); sched_unlock(); return ERROR; } diff --git a/nuttx/sched/sig_received.c b/nuttx/sched/sig_received.c index f92e07146..cf4d00165 100644 --- a/nuttx/sched/sig_received.c +++ b/nuttx/sched/sig_received.c @@ -74,7 +74,7 @@ ************************************************************************/ /************************************************************************ - * Function: sig_queueaction + * Name: sig_queueaction * * Description: * Queue a signal action for delivery to a task. @@ -127,7 +127,7 @@ static int sig_queueaction(FAR _TCB *stcb, siginfo_t *info) } /************************************************************************ - * Function: sig_findpendingsignal + * Name: sig_findpendingsignal * * Description: * Find a specified element in the pending signal list @@ -159,7 +159,7 @@ static FAR sigpendq_t *sig_findpendingsignal(FAR _TCB *stcb, int signo) } /************************************************************************ - * Function: sig_allocatependingsignal + * Name: sig_allocatependingsignal * * Description: * Allocate a pending signal list entry @@ -224,16 +224,18 @@ static FAR sigpendq_t *sig_allocatependingsignal(void) } /************************************************************************ - * Function: sig_addpendingsignal + * Name: sig_addpendingsignal * * Description: - * Add the specified signal to the signal pending list. - * NOTE: This function will queue only one entry for each - * pending signal. This was done intentionally so that a - * run-away sender cannot consume all of memory. + * Add the specified signal to the signal pending list. NOTE: This + * function will queue only one entry for each pending signal. This + * was done intentionally so that a run-away sender cannot consume + * all of memory. + * ************************************************************************/ -static FAR sigpendq_t *sig_addpendingsignal(FAR _TCB *stcb, siginfo_t *info) +static FAR sigpendq_t *sig_addpendingsignal(FAR _TCB *stcb, + siginfo_t *info) { FAR sigpendq_t *sigpend; irqstate_t saved_state; @@ -277,12 +279,11 @@ static FAR sigpendq_t *sig_addpendingsignal(FAR _TCB *stcb, siginfo_t *info) ************************************************************************/ /************************************************************************ - * Function: sig_received + * Name: sig_received * * Description: - * All signals received the task (whatever the source) go - * through this function to be processed. This function - * is responsible for: + * All signals received the task (whatever the source) go through this + * function to be processed. This function is responsible for: * * - Determining if the signal is blocked. * - Queuing and dispatching signal actions diff --git a/nuttx/sched/sig_releasependingsigaction.c b/nuttx/sched/sig_releasependingsigaction.c index f486bf708..69252f284 100644 --- a/nuttx/sched/sig_releasependingsigaction.c +++ b/nuttx/sched/sig_releasependingsigaction.c @@ -2,7 +2,7 @@ * sched/sig_releasependingsigaction.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -69,7 +69,7 @@ ************************************************************************/ /************************************************************************ - * Function: sig_releasependingsigaction + * Name: sig_releasependingsigaction * * Description: * Deallocate a pending signal action Q entry @@ -106,7 +106,7 @@ void sig_releasependingsigaction(FAR sigq_t *sigq) saved_state = irqsave(); sq_addlast((FAR sq_entry_t*)sigq, &g_sigpendingirqaction); irqrestore(saved_state); - } + } /* Otherwise, deallocate it. Note: interrupt handlers * will never deallocate signals because they will not diff --git a/nuttx/sched/sig_releasependingsignal.c b/nuttx/sched/sig_releasependingsignal.c index 4059b9bbe..5b847bc64 100644 --- a/nuttx/sched/sig_releasependingsignal.c +++ b/nuttx/sched/sig_releasependingsignal.c @@ -2,7 +2,7 @@ * sched/sig_releasependingsignal.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -46,8 +46,10 @@ #include #include #include + #include #include + #include "os_internal.h" #include "sig_internal.h" @@ -76,10 +78,11 @@ ************************************************************************/ /************************************************************************ - * Function: sig_releasependingsignal + * Name: sig_releasependingsignal * * Description: * Deallocate a pending signal list entry + * ************************************************************************/ void sig_releasependingsignal(FAR sigpendq_t *sigpend) @@ -93,7 +96,8 @@ void sig_releasependingsignal(FAR sigpendq_t *sigpend) if (sigpend->type == SIG_ALLOC_FIXED) { /* Make sure we avoid concurrent access to the free - * list from interrupt handlers. */ + * list from interrupt handlers. + */ saved_state = irqsave(); sq_addlast((FAR sq_entry_t*)sigpend, &g_sigpendingsignal); @@ -113,11 +117,12 @@ void sig_releasependingsignal(FAR sigpendq_t *sigpend) saved_state = irqsave(); sq_addlast((FAR sq_entry_t*)sigpend, &g_sigpendingirqsignal); irqrestore(saved_state); - } + } /* Otherwise, deallocate it. Note: interrupt handlers * will never deallocate signals because they will not - * receive them. */ + * receive them. + */ else if (sigpend->type == SIG_ALLOC_DYN) { diff --git a/nuttx/sched/sig_removependingsignal.c b/nuttx/sched/sig_removependingsignal.c index 37c829dfe..c82bf983b 100644 --- a/nuttx/sched/sig_removependingsignal.c +++ b/nuttx/sched/sig_removependingsignal.c @@ -2,7 +2,7 @@ * sched/sig_removependingsignal.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -46,8 +46,10 @@ #include #include #include + #include #include + #include "os_internal.h" #include "sig_internal.h" @@ -76,10 +78,11 @@ ************************************************************************/ /************************************************************************ - * Function: sig_removependingsignal + * Name: sig_removependingsignal * * Description: - * Remove the specified signal from the signal pending list + * Remove the specified signal from the signal pending list + * ************************************************************************/ FAR sigpendq_t *sig_removependingsignal(FAR _TCB *stcb, int signo) @@ -89,9 +92,11 @@ FAR sigpendq_t *sig_removependingsignal(FAR _TCB *stcb, int signo) irqstate_t saved_state; saved_state = irqsave(); + for (prevsig = NULL, currsig = (FAR sigpendq_t*)stcb->sigpendingq.head; (currsig && currsig->info.si_signo != signo); prevsig = currsig, currsig = currsig->flink); + if (currsig) { if (prevsig) @@ -103,6 +108,7 @@ FAR sigpendq_t *sig_removependingsignal(FAR _TCB *stcb, int signo) sq_remfirst(&stcb->sigpendingq); } } + irqrestore(saved_state); return currsig; diff --git a/nuttx/sched/sig_suspend.c b/nuttx/sched/sig_suspend.c index 4b6190266..09f47dee9 100644 --- a/nuttx/sched/sig_suspend.c +++ b/nuttx/sched/sig_suspend.c @@ -2,7 +2,7 @@ * sched/sig_suspend.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -43,7 +43,9 @@ #include #include #include + #include + #include "os_internal.h" #include "sig_internal.h" @@ -72,7 +74,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sigsuspend + * Name: sigsuspend * * Description: * @@ -139,9 +141,10 @@ int sigsuspend(FAR const sigset_t *set) unblocksigno = sig_lowest(&intersection); sigpend = sig_removependingsignal(rtcb, unblocksigno); if (!sigpend) - { - PANIC(OSERR_FAILEDTOREMOVESIGNAL); - } + { + PANIC(OSERR_FAILEDTOREMOVESIGNAL); + } + sig_releasependingsignal(sigpend); irqrestore(saved_state); } @@ -171,7 +174,7 @@ int sigsuspend(FAR const sigset_t *set) sig_unmaskpendingsignal(); } - sched_unlock(); + sched_unlock(); return ERROR; } diff --git a/nuttx/sched/sig_timedwait.c b/nuttx/sched/sig_timedwait.c index c0b4d802a..1b8dfd162 100644 --- a/nuttx/sched/sig_timedwait.c +++ b/nuttx/sched/sig_timedwait.c @@ -82,7 +82,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sig_timeout + * Name: sig_timeout * * Description: * A timeout elapsed while waiting for signals to be queued. @@ -128,7 +128,7 @@ static void sig_timeout(int argc, uint32_t itcb) ****************************************************************************/ /**************************************************************************** - * Function: sigtimedwait + * Name: sigtimedwait * * Description: * This function selects the pending signal set specified by the argument @@ -328,7 +328,7 @@ int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *info, } irqrestore(saved_state); } - sched_unlock(); + sched_unlock(); return ret; } diff --git a/nuttx/sched/sig_unmaskpendingsignal.c b/nuttx/sched/sig_unmaskpendingsignal.c index 27b405b5b..a7bcc7a29 100644 --- a/nuttx/sched/sig_unmaskpendingsignal.c +++ b/nuttx/sched/sig_unmaskpendingsignal.c @@ -2,7 +2,7 @@ * sched/sig_unmaskpendingsignal.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -69,13 +69,13 @@ ************************************************************************/ /************************************************************************ - * Function: sig_unmaskpendingsignal + * Name: sig_unmaskpendingsignal * * Description: - * Based upon the current setting of the sigprocmask, this - * function unmasks and processes any pending signals. This - * function should be called whenever the sigprocmask is - * changed. + * Based upon the current setting of the sigprocmask, this function + * unmasks and processes any pending signals. This function should + * be called whenever the sigprocmask is changed. + * ************************************************************************/ void sig_unmaskpendingsignal(void) diff --git a/nuttx/sched/sig_waitinfo.c b/nuttx/sched/sig_waitinfo.c index 50f06a136..0172ec47d 100644 --- a/nuttx/sched/sig_waitinfo.c +++ b/nuttx/sched/sig_waitinfo.c @@ -2,7 +2,7 @@ * sched/sig_waitinfo.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -65,7 +65,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sigwaitinfo + * Name: sigwaitinfo * * Description: * This function is equivalent to sigtimedwait with a NULL timeout diff --git a/nuttx/sched/sleep.c b/nuttx/sched/sleep.c index 7df922c61..03884a5b6 100644 --- a/nuttx/sched/sleep.c +++ b/nuttx/sched/sleep.c @@ -70,7 +70,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: sleep + * Name: sleep * * Description: * The sleep() function will cause the calling thread to be suspended from diff --git a/nuttx/sched/task_activate.c b/nuttx/sched/task_activate.c index 8e4b8b080..bae2856a1 100644 --- a/nuttx/sched/task_activate.c +++ b/nuttx/sched/task_activate.c @@ -2,7 +2,7 @@ * sched/task_activate.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -41,6 +41,7 @@ #include #include + #include /**************************************************************************** @@ -75,16 +76,14 @@ * Name: task_activate * * Description: - * This function activates tasks initialized by - * task_schedsetup(). Without activation, a task is - * ineligible for execution by the scheduler. + * This function activates tasks initialized by task_schedsetup(). Without + * activation, a task is ineligible for execution by the scheduler. * * Input Parameters: - * tcb - The TCB for the task for the task (same as the - * task_init argument. + * tcb - The TCB for the task for the task (same as the task_init argument). * * Return Value: - * Always returns OK + * Always returns OK * ****************************************************************************/ diff --git a/nuttx/sched/task_create.c b/nuttx/sched/task_create.c index 23478c810..4d92c9bb0 100644 --- a/nuttx/sched/task_create.c +++ b/nuttx/sched/task_create.c @@ -2,7 +2,7 @@ * sched/task_create.c * * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -76,8 +76,8 @@ * Description: * This function creates and activates a new thread of the specified type * with a specified priority and returns its system-assigned ID. It is the - * internal, commn implementation of task_create() and kernel_thread(). See - * comments with task_create() for further information. + * internal, commn implementation of task_create() and kernel_thread(). + * See comments with task_create() for further information. * * Input Parameters: * name - Name of the new task @@ -85,13 +85,11 @@ * priority - Priority of the new task * stack_size - size (in bytes) of the stack needed * entry - Entry point of a new task - * arg - A pointer to an array of input parameters. - * Up to CONFIG_MAX_TASK_ARG parameters may - * be provided. If fewer than CONFIG_MAX_TASK_ARG - * parameters are passed, the list should be - * terminated with a NULL argv[] value. - * If no parameters are required, argv may be - * NULL. + * arg - A pointer to an array of input parameters. Up to + * CONFIG_MAX_TASK_ARG parameters may be provided. If fewer + * than CONFIG_MAX_TASK_ARG parameters are passed, the list + * should be terminated with a NULL argv[] value. If no + * parameters are required, argv may be NULL. * * Return Value: * Returns the non-zero process ID of the new task or ERROR if memory is @@ -193,31 +191,28 @@ errout: * Name: task_create * * Description: - * This function creates and activates a new task with a - * specified priority and returns its system-assigned ID. + * This function creates and activates a new task with a specified + * priority and returns its system-assigned ID. * - * The entry address entry is the address of the "main" - * function of the task. This function will be called once - * the C environment has been set up. The specified - * function will be called with four arguments. Should - * the specified routine return, a call to exit() will + * The entry address entry is the address of the "main" function of the + * task. This function will be called once the C environment has been + * set up. The specified function will be called with four arguments. + * Should the specified routine return, a call to exit() will * automatically be made. * - * Note that four (and only four) arguments must be passed for - * the spawned functions. + * Note that four (and only four) arguments must be passed for the spawned + * functions. * * Input Parameters: * name - Name of the new task * priority - Priority of the new task * stack_size - size (in bytes) of the stack needed * entry - Entry point of a new task - * arg - A pointer to an array of input parameters. - * Up to CONFIG_MAX_TASK_ARG parameters may - * be provided. If fewer than CONFIG_MAX_TASK_ARG - * parameters are passed, the list should be - * terminated with a NULL argv[] value. - * If no parameters are required, argv may be - * NULL. + * arg - A pointer to an array of input parameters. Up to + * CONFIG_MAX_TASK_ARG parameters may be provided. If fewer + * than CONFIG_MAX_TASK_ARG parameters are passed, the list + * should be terminated with a NULL argv[] value. If no + * parameters are required, argv may be NULL. * * Return Value: * Returns the non-zero process ID of the new task or ERROR if memory is diff --git a/nuttx/sched/task_delete.c b/nuttx/sched/task_delete.c index a77bf80dd..ea0e251db 100644 --- a/nuttx/sched/task_delete.c +++ b/nuttx/sched/task_delete.c @@ -117,17 +117,17 @@ int task_delete(pid_t pid) irqstate_t saved_state; int ret = ERROR; - /* Check if the task to delete is the calling task */ + /* Check if the task to delete is the calling task */ - rtcb = (FAR _TCB*)g_readytorun.head; - if (pid == 0 || pid == rtcb->pid) - { - /* If it is, then what we really wanted to do was exit. Note that we - * don't bother to unlock the TCB since it will be going away. - */ + rtcb = (FAR _TCB*)g_readytorun.head; + if (pid == 0 || pid == rtcb->pid) + { + /* If it is, then what we really wanted to do was exit. Note that we + * don't bother to unlock the TCB since it will be going away. + */ - exit(EXIT_SUCCESS); - } + exit(EXIT_SUCCESS); + } /* Make sure the task does not become ready-to-run while we are futzing with * its TCB by locking ourselves as the executing task. @@ -137,14 +137,14 @@ int task_delete(pid_t pid) /* Find for the TCB associated with matching pid */ - dtcb = sched_gettcb(pid); - if (!dtcb) - { - /* This pid does not correspond to any known task */ + dtcb = sched_gettcb(pid); + if (!dtcb) + { + /* This pid does not correspond to any known task */ - sched_unlock(); - return ERROR; - } + sched_unlock(); + return ERROR; + } /* Verify our internal sanity */ diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c index 500129382..8fa3bde05 100644 --- a/nuttx/sched/task_exithook.c +++ b/nuttx/sched/task_exithook.c @@ -78,7 +78,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: task_hook + * Name: task_hook * * Description: * This function implements some of the internal logic of exit() and diff --git a/nuttx/sched/task_init.c b/nuttx/sched/task_init.c index 98b12fb5c..31fc5ef70 100644 --- a/nuttx/sched/task_init.c +++ b/nuttx/sched/task_init.c @@ -2,7 +2,7 @@ * sched/task_init.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -148,6 +148,7 @@ int task_init(FAR _TCB *tcb, const char *name, int priority, (void)task_argsetup(tcb, name, argv); } + return ret; } diff --git a/nuttx/sched/task_restart.c b/nuttx/sched/task_restart.c index c70a2e945..6d9b84917 100644 --- a/nuttx/sched/task_restart.c +++ b/nuttx/sched/task_restart.c @@ -76,23 +76,21 @@ * Name: task_restart * * Description: - * This function "restarts" a task. The task is first - * terminated and then reinitialized with same ID, priority, - * original entry point, stack size, and parameters it had - * when it was first started. + * This function "restarts" a task. The task is first terminated and then + * reinitialized with same ID, priority, original entry point, stack size, + * and parameters it had when it was first started. * * Inputs: - * pid - The task ID of the task to delete. An ID of zero - * signifies the calling task. + * pid - The task ID of the task to delete. An ID of zero signifies the + * calling task. * * Return Value: * OK on sucess; ERROR on failure. * * This function can fail if: - * (1) A pid of zero or the pid of the calling task is - * provided (functionality not implemented) - * (2) The pid is not associated with any task known to - * the system. + * (1) A pid of zero or the pid of the calling task is provided + * (functionality not implemented) + * (2) The pid is not associated with any task known to the system. * ****************************************************************************/ @@ -107,79 +105,79 @@ int task_restart(pid_t pid) * we are futzing with its TCB */ - sched_lock(); + sched_lock(); - /* Check if the task to restart is the calling task */ + /* Check if the task to restart is the calling task */ - rtcb = (FAR _TCB*)g_readytorun.head; - if ((pid == 0) || (pid == rtcb->pid)) - { - /* Not implemented */ + rtcb = (FAR _TCB*)g_readytorun.head; + if ((pid == 0) || (pid == rtcb->pid)) + { + /* Not implemented */ - return ERROR; - } + return ERROR; + } - /* We are restarting some other task than ourselves */ + /* We are restarting some other task than ourselves */ - else - { - /* Find for the TCB associated with matching pid */ + else + { + /* Find for the TCB associated with matching pid */ - tcb = sched_gettcb(pid); - if (!tcb) - { - /* There is no TCB with this pid */ + tcb = sched_gettcb(pid); + if (!tcb) + { + /* There is no TCB with this pid */ - return ERROR; - } + return ERROR; + } - /* Remove the TCB from whatever list it is in. At this point, the - * TCB should no longer be accessible to the system - */ + /* Remove the TCB from whatever list it is in. At this point, the + * TCB should no longer be accessible to the system + */ - state = irqsave(); - dq_rem((FAR dq_entry_t*)tcb, (dq_queue_t*)g_tasklisttable[tcb->task_state].list); - tcb->task_state = TSTATE_TASK_INVALID; - irqrestore(state); + state = irqsave(); + dq_rem((FAR dq_entry_t*)tcb, (dq_queue_t*)g_tasklisttable[tcb->task_state].list); + tcb->task_state = TSTATE_TASK_INVALID; + irqrestore(state); - /* Deallocate anything left in the TCB's queues */ + /* Deallocate anything left in the TCB's queues */ - sig_cleanup(tcb); /* Deallocate Signal lists */ + sig_cleanup(tcb); /* Deallocate Signal lists */ - /* Reset the current task priority */ + /* Reset the current task priority */ - tcb->sched_priority = tcb->init_priority; + tcb->sched_priority = tcb->init_priority; - /* Reset the base task priority and the number of pending reprioritizations */ + /* Reset the base task priority and the number of pending reprioritizations */ #ifdef CONFIG_PRIORITY_INHERITANCE - tcb->base_priority = tcb->init_priority; + tcb->base_priority = tcb->init_priority; # if CONFIG_SEM_NNESTPRIO > 0 - tcb->npend_reprio = 0; + tcb->npend_reprio = 0; # endif #endif - /* Re-initialize the processor-specific portion of the TCB - * This will reset the entry point and the start-up parameters - */ + /* Re-initialize the processor-specific portion of the TCB + * This will reset the entry point and the start-up parameters + */ - up_initial_state(tcb); + up_initial_state(tcb); - /* Add the task to the inactive task list */ + /* Add the task to the inactive task list */ - dq_addfirst((FAR dq_entry_t*)tcb, (dq_queue_t*)&g_inactivetasks); - tcb->task_state = TSTATE_TASK_INACTIVE; + dq_addfirst((FAR dq_entry_t*)tcb, (dq_queue_t*)&g_inactivetasks); + tcb->task_state = TSTATE_TASK_INACTIVE; - /* Activate the task */ + /* Activate the task */ - status = task_activate(tcb); - if (status != OK) - { - dq_rem((FAR dq_entry_t*)tcb, (dq_queue_t*)&g_inactivetasks); - sched_releasetcb(tcb); - return ERROR; - } - } + status = task_activate(tcb); + if (status != OK) + { + dq_rem((FAR dq_entry_t*)tcb, (dq_queue_t*)&g_inactivetasks); + sched_releasetcb(tcb); + return ERROR; + } + } sched_unlock(); return OK; diff --git a/nuttx/sched/task_setup.c b/nuttx/sched/task_setup.c index 2cbd6daba..a37fb165a 100644 --- a/nuttx/sched/task_setup.c +++ b/nuttx/sched/task_setup.c @@ -147,7 +147,7 @@ static int task_assignpid(FAR _TCB *tcb) } /**************************************************************************** - * Function: task_dupdspace + * Name: task_dupdspace * * Description: * When a new task or thread is created from a PIC module, then that diff --git a/nuttx/sched/task_start.c b/nuttx/sched/task_start.c index 5d1e74180..a9cc38dfc 100644 --- a/nuttx/sched/task_start.c +++ b/nuttx/sched/task_start.c @@ -2,7 +2,7 @@ * sched/task_start.c * * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -77,10 +77,9 @@ * Name: task_start * * Description: - * This function is the low level entry point - * into the main thread of execution of a task. It receives - * initial control when the task is started and calls main - * entry point of the newly started task. + * This function is the low level entry point into the main thread of + * execution of a task. It receives initial control when the task is + * started and calls main entry point of the newly started task. * * Inputs: * None @@ -99,12 +98,12 @@ void task_start(void) for (argc = 1; argc <= CONFIG_MAX_TASK_ARGS; argc++) { - /* The first non-null argument terminates the list */ + /* The first non-null argument terminates the list */ - if (!tcb->argv[argc]) - { - break; - } + if (!tcb->argv[argc]) + { + break; + } } /* Call the 'main' entry point passing argc and argv. If/when diff --git a/nuttx/sched/timer_create.c b/nuttx/sched/timer_create.c index b1ad142c7..edfb01080 100644 --- a/nuttx/sched/timer_create.c +++ b/nuttx/sched/timer_create.c @@ -2,7 +2,7 @@ * sched/timer_create.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -69,7 +69,7 @@ ********************************************************************************/ /******************************************************************************** - * Function: timer_allocate + * Name: timer_allocate * * Description: * Allocate one POSIX timer and place it into the allocated timer list. @@ -128,7 +128,7 @@ static struct posix_timer_s *timer_allocate(void) ********************************************************************************/ /******************************************************************************** - * Function: timer_create + * Name: timer_create * * Description: * The timer_create() function creates per-thread timer using the specified diff --git a/nuttx/sched/timer_delete.c b/nuttx/sched/timer_delete.c index e89dd15a1..c497c414e 100644 --- a/nuttx/sched/timer_delete.c +++ b/nuttx/sched/timer_delete.c @@ -2,7 +2,7 @@ * timer_delete.c * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -67,13 +67,14 @@ ********************************************************************************/ /******************************************************************************** - * Function: timer_delete + * Name: timer_delete * * Description: * The timer_delete() function deletes the specified timer, timerid, previously * created by the timer_create() function. If the timer is armed when * timer_delete() is called, the timer will be automatically disarmed before - * removal. The disposition of pending signals for the deleted timer is unspecified. + * removal. The disposition of pending signals for the deleted timer is + * unspecified. * * Parameters: * timerid - The per-thread timer, previously created by the call to @@ -81,7 +82,8 @@ * * Return Value: * If the call succeeds, timer_create() will return 0 (OK). Otherwise, the - * function will return a value of -1 (ERROR) and set errno to indicate the error. + * function will return a value of -1 (ERROR) and set errno to indicate the + * error. * * EINVAL - The timer specified timerid is not valid. * @@ -94,9 +96,10 @@ int timer_delete(timer_t timerid) int ret = timer_release((FAR struct posix_timer_s *)timerid); if (ret < 0) { - *get_errno_ptr() = -ret; - return ERROR; + set_errno(-ret); + return ERROR; } + return OK; } diff --git a/nuttx/sched/timer_getoverrun.c b/nuttx/sched/timer_getoverrun.c index 6f8c87672..6d5a47465 100644 --- a/nuttx/sched/timer_getoverrun.c +++ b/nuttx/sched/timer_getoverrun.c @@ -2,7 +2,7 @@ * timer_getoverrun.c * * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,8 +38,10 @@ ********************************************************************************/ #include + #include #include + #include "timer_internal.h" #ifndef CONFIG_DISABLE_POSIX_TIMERS @@ -65,7 +67,7 @@ ********************************************************************************/ /******************************************************************************** - * Function: timer_getoverrun + * Name: timer_getoverrun * * Description: * Only a single signal will be queued to the process for a given timer at any diff --git a/nuttx/sched/timer_gettime.c b/nuttx/sched/timer_gettime.c index 49c65ddf8..7598dbec5 100644 --- a/nuttx/sched/timer_gettime.c +++ b/nuttx/sched/timer_gettime.c @@ -2,7 +2,7 @@ * timer_gettime.c * * Copyright (C) 2007 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,8 +38,10 @@ ********************************************************************************/ #include + #include #include + #include "clock_internal.h" #include "timer_internal.h" @@ -66,7 +68,7 @@ ********************************************************************************/ /******************************************************************************** - * Function: timer_gettime + * Name: timer_gettime * * Description: * The timer_gettime() function will store the amount of time until the @@ -103,7 +105,7 @@ int timer_gettime(timer_t timerid, FAR struct itimerspec *value) if (!timer || !value) { - *get_errno_ptr() = EINVAL; + set_errno(EINVAL); return ERROR; } diff --git a/nuttx/sched/timer_initialize.c b/nuttx/sched/timer_initialize.c index 10856d800..05980bb1a 100644 --- a/nuttx/sched/timer_initialize.c +++ b/nuttx/sched/timer_initialize.c @@ -2,7 +2,7 @@ * timer_initialize.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -89,7 +89,7 @@ volatile sq_queue_t g_alloctimers; ********************************************************************************/ /******************************************************************************** - * Function: timer_initialize + * Name: timer_initialize * * Description: * Boot up configuration of the POSIX timer facility. @@ -126,7 +126,7 @@ void weak_function timer_initialize(void) } /******************************************************************************** - * Function: timer_deleteall + * Name: timer_deleteall * * Description: * This function is called whenever a thread exits. Any timers owned by that @@ -161,6 +161,7 @@ void weak_function timer_deleteall(pid_t pid) timer_delete((timer_t)timer); } } + irqrestore(flags); } diff --git a/nuttx/sched/timer_internal.h b/nuttx/sched/timer_internal.h index 1b6daffec..71dfb59a3 100644 --- a/nuttx/sched/timer_internal.h +++ b/nuttx/sched/timer_internal.h @@ -2,7 +2,7 @@ * timer_internal.h * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,8 +33,8 @@ * ********************************************************************************/ -#ifndef __TIMER_INTERNAL_H -#define __TIMER_INTERNAL_H +#ifndef __SCHED_TIMER_INTERNAL_H +#define __SCHED_TIMER_INTERNAL_H /******************************************************************************** * Included Files @@ -95,8 +95,8 @@ extern volatile sq_queue_t g_alloctimers; * Public Function Prototypes ********************************************************************************/ -extern void weak_function timer_initialize(void); -extern void weak_function timer_deleteall(pid_t pid); -extern int timer_release(FAR struct posix_timer_s *timer); +void weak_function timer_initialize(void); +void weak_function timer_deleteall(pid_t pid); +int timer_release(FAR struct posix_timer_s *timer); -#endif /* __TIMER_INTERNAL_H */ +#endif /* __SCHED_TIMER_INTERNAL_H */ diff --git a/nuttx/sched/timer_release.c b/nuttx/sched/timer_release.c index 83f86954b..ed83b5f53 100644 --- a/nuttx/sched/timer_release.c +++ b/nuttx/sched/timer_release.c @@ -2,7 +2,7 @@ * timer_release.c * * Copyright (C) 2008 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -65,7 +65,7 @@ ********************************************************************************/ /******************************************************************************** - * Function: timer_free + * Name: timer_free * * Description: * Remove the timer from the allocated timer list and free it or return it to @@ -106,7 +106,7 @@ static inline void timer_free(struct posix_timer_s *timer) ********************************************************************************/ /******************************************************************************** - * Function: timer_release + * Name: timer_release * * Description: * timer_release implements the heart of timer_delete. It is private to the diff --git a/nuttx/sched/timer_settime.c b/nuttx/sched/timer_settime.c index 035852315..1814ba898 100644 --- a/nuttx/sched/timer_settime.c +++ b/nuttx/sched/timer_settime.c @@ -2,7 +2,7 @@ * sched/timer_settime.c * * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -76,7 +76,7 @@ static void timer_timeout(int argc, uint32_t itimer); ********************************************************************************/ /******************************************************************************** - * Function: timer_sigqueue + * Name: timer_sigqueue * * Description: * This function basically reimplements sigqueue() so that the si_code can @@ -121,7 +121,7 @@ static void inline timer_sigqueue(FAR struct posix_timer_s *timer) } /******************************************************************************** - * Function: timer_restart + * Name: timer_restart * * Description: * If a periodic timer has been selected, then restart the watchdog. @@ -144,16 +144,17 @@ static void inline timer_restart(FAR struct posix_timer_s *timer, uint32_t itime if (timer->pt_delay) { timer->pt_last = timer->pt_delay; - (void)wd_start(timer->pt_wdog, timer->pt_delay, (wdentry_t)timer_timeout, 1, itimer); + (void)wd_start(timer->pt_wdog, timer->pt_delay, (wdentry_t)timer_timeout, + 1, itimer); } } /******************************************************************************** - * Function: timer_timeout + * Name: timer_timeout * * Description: - * This function is called if the timeout elapses before - * the condition is signaled. + * This function is called if the timeout elapses before the condition is + * signaled. * * Parameters: * argc - the number of arguments (should be 1) @@ -234,7 +235,7 @@ static void timer_timeout(int argc, uint32_t itimer) ********************************************************************************/ /******************************************************************************** - * Function: timer_settime + * Name: timer_settime * * Description: * The timer_settime() function sets the time until the next expiration of the @@ -347,27 +348,27 @@ int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value if ((flags & TIMER_ABSTIME) != 0) { #ifdef CONFIG_DISABLE_CLOCK - /* Absolute timing depends upon having access to clock functionality */ + /* Absolute timing depends upon having access to clock functionality */ - errno = ENOSYS; - return ERROR; + errno = ENOSYS; + return ERROR; #else - /* Calculate a delay corresponding to the absolute time in 'value'. - * NOTE: We have internal knowledge the clock_abstime2ticks only - * returns an error if clockid != CLOCK_REALTIME. - */ + /* Calculate a delay corresponding to the absolute time in 'value'. + * NOTE: We have internal knowledge the clock_abstime2ticks only + * returns an error if clockid != CLOCK_REALTIME. + */ - (void)clock_abstime2ticks(CLOCK_REALTIME, &value->it_value, &delay); + (void)clock_abstime2ticks(CLOCK_REALTIME, &value->it_value, &delay); #endif } else { - /* Calculate a delay assuming that 'value' holds the relative time - * to wait. We have internal knowledge that clock_time2ticks always - * returns success. - */ + /* Calculate a delay assuming that 'value' holds the relative time + * to wait. We have internal knowledge that clock_time2ticks always + * returns success. + */ - (void)clock_time2ticks(&value->it_value, &delay); + (void)clock_time2ticks(&value->it_value, &delay); } /* If the time is in the past or now, then set up the next interval @@ -385,7 +386,8 @@ int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value if (delay > 0) { timer->pt_last = delay; - ret = wd_start(timer->pt_wdog, delay, (wdentry_t)timer_timeout, 1, (uint32_t)((uintptr_t)timer)); + ret = wd_start(timer->pt_wdog, delay, (wdentry_t)timer_timeout, + 1, (uint32_t)((uintptr_t)timer)); } irqrestore(state); diff --git a/nuttx/sched/usleep.c b/nuttx/sched/usleep.c index ba2c072c4..21996d788 100644 --- a/nuttx/sched/usleep.c +++ b/nuttx/sched/usleep.c @@ -68,7 +68,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: usleep + * Name: usleep * * Description: * The usleep() function will cause the calling thread to be suspended diff --git a/nuttx/sched/wd_cancel.c b/nuttx/sched/wd_cancel.c index ea686cf92..0bd59cf89 100644 --- a/nuttx/sched/wd_cancel.c +++ b/nuttx/sched/wd_cancel.c @@ -2,7 +2,7 @@ * sched/wd_cancel.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -72,11 +72,11 @@ ****************************************************************************/ /**************************************************************************** - * Function: wd_cancel + * Name: wd_cancel * * Description: - * This function cancels a currently running watchdog timer. - * Watchdog timers may be canceled from the interrupt level. + * This function cancels a currently running watchdog timer. Watchdog + * timers may be canceled from the interrupt level. * * Parameters: * wdid - ID of the watchdog to cancel. @@ -159,6 +159,7 @@ int wd_cancel (WDOG_ID wdid) wdid->active = false; } + irqrestore(saved_state); return ret; } diff --git a/nuttx/sched/wd_create.c b/nuttx/sched/wd_create.c index a383de6a5..d86171bf7 100644 --- a/nuttx/sched/wd_create.c +++ b/nuttx/sched/wd_create.c @@ -2,7 +2,7 @@ * sched/wd_create.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -71,7 +71,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: wd_create + * Name: wd_create * * Description: * The wd_create function will create a watchdog by allocating it from the @@ -104,5 +104,6 @@ WDOG_ID wd_create (void) wdog->next = NULL; wdog->active = false; } + return (WDOG_ID)wdog; } diff --git a/nuttx/sched/wd_delete.c b/nuttx/sched/wd_delete.c index 3f39bf723..16c123e13 100644 --- a/nuttx/sched/wd_delete.c +++ b/nuttx/sched/wd_delete.c @@ -2,7 +2,7 @@ * sched/wd_delete.c * * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -72,23 +72,22 @@ ****************************************************************************/ /**************************************************************************** - * Function: wd_delete + * Name: wd_delete * * Description: - * The wd_delete function will deallocate a watchdog by - * returning it to the free pool of watchdogs. The watchdog - * will be removed from the timer queue if has been started. + * The wd_delete function will deallocate a watchdog by returning it to + * the free pool of watchdogs. The watchdog will be removed from the timer + * queue if has been started. * * Parameters: - * wdId - The watchdog ID to delete. This is actually a - * pointer to a watchdog structure. + * wdId - The watchdog ID to delete. This is actually a pointer to a + * watchdog structure. * * Return Value: * Returns OK or ERROR * * Assumptions: - * The caller has assured that the watchdog is no longer - * in use. + * The caller has assured that the watchdog is no longer in use. * ****************************************************************************/ @@ -100,9 +99,10 @@ int wd_delete(WDOG_ID wdId) if (!wdId) { - *get_errno_ptr() = EINVAL; + set_errno(EINVAL); return ERROR; } + /* The following steps are atomic... the watchdog must not be active when * it is being deallocated. */ diff --git a/nuttx/sched/wd_gettime.c b/nuttx/sched/wd_gettime.c index 0d5a3a470..caa482549 100644 --- a/nuttx/sched/wd_gettime.c +++ b/nuttx/sched/wd_gettime.c @@ -2,7 +2,7 @@ * sched/wd_gettime.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -69,7 +69,7 @@ ********************************************************************************/ /******************************************************************************** - * Function: wd_gettime + * Name: wd_gettime * * Description: * This function returns the time remaining before the specified watchdog diff --git a/nuttx/sched/wd_initialize.c b/nuttx/sched/wd_initialize.c index 8553582e0..db7aba502 100644 --- a/nuttx/sched/wd_initialize.c +++ b/nuttx/sched/wd_initialize.c @@ -2,7 +2,7 @@ * sched/wd_initialize.c * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -57,24 +57,21 @@ * Global Variables ************************************************************************/ -/* The g_wdfreelist data structure is a singly linked list - * of watchdogs available to the system for delayed function - * use. +/* The g_wdfreelist data structure is a singly linked list of watchdogs + * available to the system for delayed function use. */ sq_queue_t g_wdfreelist; -/* g_wdpool is a pointer to a list of pre-allocated watchdogs. - * The number of watchdogs in the pool is a configuration - * item. +/* g_wdpool is a pointer to a list of pre-allocated watchdogs. The number + * of watchdogs in the pool is a configuration item. */ FAR wdog_t *g_wdpool; -/* The g_wdactivelist data structure is a singly linked list - * ordered by watchdog expiration time. When watchdog timers - * expire,the functions on this linked list are removed and - * the function is called. +/* The g_wdactivelist data structure is a singly linked list ordered by + * watchdog expiration time. When watchdog timers expire,the functions on + * this linked list are removed and the function is called. */ sq_queue_t g_wdactivelist; @@ -92,7 +89,7 @@ sq_queue_t g_wdactivelist; ************************************************************************/ /************************************************************************ - * Function: wd_initialize + * Name: wd_initialize * * Description: * This function initalized the watchdog data structures @@ -104,9 +101,9 @@ sq_queue_t g_wdactivelist; * None * * Assumptions: - * This function must be called early in the initialization - * sequence before the timer interrupt is attached and - * before any watchdog services are used. + * This function must be called early in the initialization sequence + * before the timer interrupt is attached and before any watchdog + * services are used. * ************************************************************************/ diff --git a/nuttx/sched/wd_internal.h b/nuttx/sched/wd_internal.h index 4df2a0e65..e63a8bdae 100644 --- a/nuttx/sched/wd_internal.h +++ b/nuttx/sched/wd_internal.h @@ -2,7 +2,7 @@ * sched/d_internal.h * * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -45,6 +45,7 @@ #include #include #include + #include /************************************************************************ @@ -55,8 +56,8 @@ * Public Type Declarations ************************************************************************/ -/* This is the watchdog structure. The WDOG_ID is a pointer to - * a watchdog structure. +/* This is the watchdog structure. The WDOG_ID is a pointer to a + * watchdog structure. */ struct wdog_s @@ -77,24 +78,21 @@ typedef struct wdog_s wdog_t; * Public Variables ************************************************************************/ -/* The g_wdfreelist data structure is a singly linked list - * of watchdogs available to the system for delayed function - * use. +/* The g_wdfreelist data structure is a singly linked list of watchdogs + * available to the system for delayed function use. */ extern sq_queue_t g_wdfreelist; -/* g_wdpool is a pointer to a list of pre-allocated watchdogs. - * The number of watchdogs in the pool is a configuration - * item. +/* g_wdpool is a pointer to a list of pre-allocated watchdogs. The number + * of watchdogs in the pool is a configuration item. */ extern FAR wdog_t *g_wdpool; -/* The g_wdactivelist data structure is a singly linked list - * ordered by watchdog expiration time. When watchdog timers - * expire,the functions on this linked list are removed and - * the function is called. +/* The g_wdactivelist data structure is a singly linked list ordered by + * watchdog expiration time. When watchdog timers expire,the functions on + * this linked list are removed and the function is called. */ extern sq_queue_t g_wdactivelist; diff --git a/nuttx/sched/wd_start.c b/nuttx/sched/wd_start.c index a2f19fbdc..2a69d131a 100644 --- a/nuttx/sched/wd_start.c +++ b/nuttx/sched/wd_start.c @@ -93,24 +93,22 @@ typedef void (*wdentry4_t)(int argc, uint32_t arg1, uint32_t arg2, ****************************************************************************/ /**************************************************************************** - * Function: wd_start + * Name: wd_start * * Description: - * This function adds a watchdog to the timer queue. The - * specified watchdog function will be called from the - * interrupt level after the specified number of ticks has - * elapsed. Watchdog timers may be started from the - * interrupt level. + * This function adds a watchdog to the timer queue. The specified + * watchdog function will be called from the interrupt level after the + * specified number of ticks has elapsed. Watchdog timers may be started + * from the interrupt level. * - * Watchdog timers execute in the address enviroment that - * was in effect when wd_start() is called. + * Watchdog timers execute in the address enviroment that was in effect + * when wd_start() is called. * * Watchdog timers execute only once. * - * To replace either the timeout delay or the function to - * be executed, call wd_start again with the same wdog; only - * the most recent wdStart() on a given watchdog ID has - * any effect. + * To replace either the timeout delay or the function to be executed, + * call wd_start again with the same wdog; only the most recent wdStart() + * on a given watchdog ID has any effect. * * Parameters: * wdog = watchdog ID @@ -122,8 +120,8 @@ typedef void (*wdentry4_t)(int argc, uint32_t arg1, uint32_t arg2, * OK or ERROR * * Assumptions: - * The watchdog routine runs in the context of the timer interrupt - * handler and is subject to all ISR restrictions. + * The watchdog routine runs in the context of the timer interrupt handler + * and is subject to all ISR restrictions. * ****************************************************************************/ @@ -141,7 +139,7 @@ int wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry, int argc, ...) if (!wdog || argc > CONFIG_MAX_WDOGPARMS || delay < 0) { - *get_errno_ptr() = EINVAL; + set_errno(EINVAL); return ERROR; } @@ -275,7 +273,7 @@ int wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry, int argc, ...) } /**************************************************************************** - * Function: wd_timer + * Name: wd_timer * * Description: * This function is called from the timer interrupt handler to determine diff --git a/nuttx/sched/work_cancel.c b/nuttx/sched/work_cancel.c index f110eb4cc..c277f024d 100644 --- a/nuttx/sched/work_cancel.c +++ b/nuttx/sched/work_cancel.c @@ -2,7 +2,7 @@ * sched/work_cancel.c * * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -110,6 +110,7 @@ int work_cancel(struct work_s *work) work->worker = NULL; } + irqrestore(flags); return OK; } diff --git a/nuttx/sched/work_internal.h b/nuttx/sched/work_internal.h index 56f5e5d56..69b7bf547 100644 --- a/nuttx/sched/work_internal.h +++ b/nuttx/sched/work_internal.h @@ -2,7 +2,7 @@ * sched/work_internal.h * * Copyright (C) 2009-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -105,7 +105,7 @@ extern pid_t g_worker; * ****************************************************************************/ -extern int work_thread(int argc, char *argv[]); +int work_thread(int argc, char *argv[]); #endif /* __ASSEMBLY__ */ #endif /* CONFIG_SCHED_WORKQUEUE */ diff --git a/nuttx/sched/work_queue.c b/nuttx/sched/work_queue.c index 4b0380643..beeac168d 100644 --- a/nuttx/sched/work_queue.c +++ b/nuttx/sched/work_queue.c @@ -2,7 +2,7 @@ * sched/work_queue.c * * Copyright (C) 2009-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -128,4 +128,5 @@ int work_queue(struct work_s *work, worker_t worker, FAR void *arg, uint32_t del irqrestore(flags); return OK; } + #endif /* CONFIG_SCHED_WORKQUEUE */