diff options
author | Thomas Martitz <kugel@rockbox.org> | 2011-02-18 22:46:01 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2011-02-18 22:46:01 +0000 |
commit | 6d85de341928aef8178465c60122f3cbe76f5dd6 (patch) | |
tree | ff86c384a574ac20d3418c1b904ed4d0de1f6980 /firmware/export | |
parent | 3926c30705cc7235122e2f2e35ab506b53238cdf (diff) | |
download | rockbox-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 'firmware/export')
-rw-r--r-- | firmware/export/config.h | 4 | ||||
-rw-r--r-- | firmware/export/thread.h | 27 |
2 files changed, 24 insertions, 7 deletions
diff --git a/firmware/export/config.h b/firmware/export/config.h index 3063e1f06d..a870e5d815 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -717,7 +717,9 @@ Lyre prototype 1 */ #define HAVE_WAKEUP_EXT_CB -#if (CONFIG_PLATFORM & PLATFORM_ANDROID) +#if defined(ASSEMBLER_THREADS) \ + || defined(HAVE_WIN32_FIBER_THREADS) \ + || defined(HAVE_SIGALTSTACK_THREADS) #define HAVE_PRIORITY_SCHEDULING #endif diff --git a/firmware/export/thread.h b/firmware/export/thread.h index 3cce78444c..4f7631cebd 100644 --- a/firmware/export/thread.h +++ b/firmware/export/thread.h @@ -84,15 +84,19 @@ * We need more stack when we run under a host * maybe more expensive C lib functions? * - * simulator doesn't simulate stack usage anyway but well ... */ -#if ((CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SIMULATOR)) -#define DEFAULT_STACK_SIZE 0x400 /* Bytes */ -#else + * simulator (possibly) doesn't simulate stack usage anyway but well ... */ +#ifdef HAVE_SIGALTSTACK_THREADS +#include <signal.h> +/* MINSIGSTKSZ for the OS to deliver the signal + 0x3000 for us */ +#define DEFAULT_STACK_SIZE (MINSIGSTKSZ+0x3000) /* Bytes */ +#elif (CONFIG_PLATFORM & PLATFORM_ANDROID) || defined(HAVE_WIN32_FIBER_THREADS) #define DEFAULT_STACK_SIZE 0x1000 /* Bytes */ +#else /* native threads, sdl threads */ +#define DEFAULT_STACK_SIZE 0x400 /* Bytes */ #endif -#if (CONFIG_PLATFORM & (PLATFORM_NATIVE|PLATFORM_ANDROID)) +#if defined(ASSEMBLER_THREADS) /* Need to keep structures inside the header file because debug_menu * needs them. */ #ifdef CPU_COLDFIRE @@ -112,7 +116,7 @@ struct regs uint32_t pr; /* 32 - Procedure register */ uint32_t start; /* 36 - Thread start address, or NULL when started */ }; -#elif defined(CPU_ARM) || (CONFIG_PLATFORM & PLATFORM_ANDROID) +#elif defined(CPU_ARM) struct regs { uint32_t r[8]; /* 0-28 - Registers r4-r11 */ @@ -147,6 +151,16 @@ struct regs }; #endif /* CONFIG_CPU */ #elif (CONFIG_PLATFORM & PLATFORM_HOSTED) +#ifndef HAVE_SDL_THREADS +struct regs +{ + void (*start)(void); /* thread's entry point, or NULL when started */ + void* uc; /* host thread handle */ + uintptr_t sp; /* Stack pointer, unused */ + size_t stack_size; /* stack size, not always used */ + uintptr_t stack; /* pointer to start of the stack buffer */ +}; +#else /* SDL threads */ struct regs { void *t; /* OS thread */ @@ -154,6 +168,7 @@ struct regs void *s; /* Semaphore for blocking and wakeup */ void (*start)(void); /* Start function */ }; +#endif #endif /* PLATFORM_NATIVE */ /* NOTE: The use of the word "queue" may also refer to a linked list of |