summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-02-18 22:46:01 +0000
committerThomas Martitz <kugel@rockbox.org>2011-02-18 22:46:01 +0000
commit6d85de341928aef8178465c60122f3cbe76f5dd6 (patch)
treeff86c384a574ac20d3418c1b904ed4d0de1f6980 /tools
parent3926c30705cc7235122e2f2e35ab506b53238cdf (diff)
downloadrockbox-6d85de341928aef8178465c60122f3cbe76f5dd6.tar.gz
rockbox-6d85de341928aef8178465c60122f3cbe76f5dd6.zip
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
Diffstat (limited to 'tools')
-rwxr-xr-xtools/configure78
1 files changed, 77 insertions, 1 deletions
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 <<EOF
+#include <signal.h>
+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 <<EOF
+#include <windows.h>
+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<g" \
-e "s<@config_rtc@<$config_rtc<g" \
-e "s<@have_rtc_alarm@<$have_rtc_alarm<g" \
+ -e "s<@thread_support@<$thread_support<g" \
-e "s<@RBDIR@<${rbdir}<g" \
-e "s<@sharepath@<${sharedir}<g" \
-e "s<@binpath@<${bindir}<g" \
@@ -3362,6 +3435,9 @@ sed > 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@