From 6d85de341928aef8178465c60122f3cbe76f5dd6 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Fri, 18 Feb 2011 22:46:01 +0000 Subject: Implement cooperative threads on hosted platforms using C code. This replaces SDL threads with real cooperative threads, which are less cpu intensive and allow priority scheduling. The backend for context switching is dependant on the host (sigaltstack/longjmp on Unix, Fibers on Windows). configure has options to force or disallow SDL threads. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29327 a1c6a512-1295-4272-9138-f99709370657 --- tools/configure | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/configure b/tools/configure index bcb7d0a864..889012ab78 100755 --- a/tools/configure +++ b/tools/configure @@ -25,6 +25,7 @@ bindir= libdir= sharedir= +thread_support="ASSEMBLER_THREADS" app_modelname= app_lcd_width= app_lcd_height= @@ -163,6 +164,39 @@ findsdl(){ done } +# check for availability of sigaltstack to support our thread engine +check_sigaltstack() { + cat >$tmpdir/check_threads.c < +int main(int argc, char **argv) +{ + #define NULL (void*)0 + sigaltstack(NULL, NULL); + return 0; +} +EOF + $CC -o $tmpdir/check_threads $tmpdir/check_threads.c 1> /dev/null + result=$? + rm -rf $tmpdir/check_threads* + echo $result +} + +# check for availability of Fiber on Win32 to support our thread engine +check_fiber() { + cat >$tmpdir/check_threads.c < +int main(int argc, char **argv) +{ + ConvertThreadToFiber(NULL); + return 0; +} +EOF + $CC -o $tmpdir/check_threads $tmpdir/check_threads.c 2>/dev/null + result=$? + rm -rf $tmpdir/check_threads* + echo $result +} + simcc () { # default tool setup for native building @@ -175,6 +209,8 @@ simcc () { GCCOPTS="$GCCOPTS -fno-builtin -g" GCCOPTIMIZE='' LDOPTS='-lm' # button-sdl.c uses sqrt() + sigaltstack="" + fibers="" # default output binary name, don't override app_get_platform() if [ "$app_type" != "sdl-app" ]; then @@ -193,6 +229,7 @@ simcc () { CYGWIN*) echo "Cygwin host detected" + fibers=`check_fiber` LDOPTS="$LDOPTS -mconsole" output="$output.exe" winbuild="yes" @@ -201,29 +238,33 @@ simcc () { MINGW*) echo "MinGW host detected" + fibers=`check_fiber` LDOPTS="$LDOPTS -mconsole" output="$output.exe" winbuild="yes" ;; Linux) + sigaltstack=`check_sigaltstack` echo "Linux host detected" LDOPTS="$LDOPTS -ldl" ;; FreeBSD) + sigaltstack=`check_sigaltstack` echo "FreeBSD host detected" LDOPTS="$LDOPTS -ldl" ;; Darwin) + sigaltstack=`check_sigaltstack` echo "Darwin host detected" LDOPTS="$LDOPTS -ldl" - SHARED_FLAG="-dynamiclib -Wl\,-single_module" ;; SunOS) + sigaltstack=`check_sigaltstack` echo "*Solaris host detected" GCCOPTS="$GCCOPTS -fPIC" @@ -319,11 +360,33 @@ EOF # add cross-compiler option(s) prefixtools i586-mingw32msvc- LDOPTS="$LDOPTS -mconsole" + fibers=`check_fiber` output="rockboxui.exe" endian="little" # windows is little endian echo "Enabling MMX support" GCCOPTS="$GCCOPTS -mmmx" fi + + thread_support= + if [ -z "$ARG_THREAD_SUPPORT" ] || [ "$ARG_THREAD_SUPPORT" = "0" ]; then + if [ "$sigaltstack" = "0" ]; then + thread_support="HAVE_SIGALTSTACK_THREADS" + echo "Selected sigaltstack threads" + elif [ "$fibers" = "0" ]; then + thread_support="HAVE_WIN32_FIBER_THREADS" + echo "Selected Win32 Fiber threads" + fi + fi + + if [ -n `echo $app_type | grep "sdl"` ] && [ -z "$thread_support" ] \ + && [ "$ARG_THREAD_SUPPORT" != "0" ]; then + thread_support="HAVE_SDL_THREADS" + if [ "$ARG_THREAD_SUPPORT" = "1" ]; then + echo "Selected SDL threads" + else + echo "WARNING: Falling back to SDL threads" + fi + fi } # @@ -994,6 +1057,11 @@ help() { --thumb Build with -mthumb (for ARM builds) --no-thumb The opposite of --thumb (don't use thumb even for targets where this is the default + --sdl-threads Force use of SDL threads. They have inferior performance, + but are better debuggable with GDB + --no-sdl-threads Disallow use of SDL threads. This prevents the default + behavior of falling back to them if no native thread + support was found. --prefix Target installation directory --help Shows this message (must not be used with other options) @@ -1015,6 +1083,7 @@ ARG_VOICE= ARG_ARM_EABI= ARG_ARM_THUMB= ARG_PREFIX="$PREFIX" +ARG_THREAD_SUPPORT= err= for arg in "$@"; do case "$arg" in @@ -1035,6 +1104,9 @@ for arg in "$@"; do --no-eabi) ARG_ARM_EABI=0;; --thumb) ARG_ARM_THUMB=1;; --no-thumb) ARG_ARM_THUMB=0;; + --sdl-threads)ARG_THREAD_SUPPORT=1;; + --no-sdl-threads) + ARG_THREAD_SUPPORT=0;; --prefix=*) ARG_PREFIX=`echo "$arg" | cut -d = -f 2`;; --help) help;; *) err=1; echo "[ERROR] Option '$arg' unsupported";; @@ -3326,6 +3398,7 @@ sed > autoconf.h \ -e "s<^#undef DO_BOOTCHART<$use_bootchart autoconf.h \ @config_rtc@ @have_rtc_alarm@ +/* the threading backend we use */ +#define @thread_support@ + /* lcd dimensions for application builds from configure */ @lcd_width@ @lcd_height@ -- cgit v1.2.3