summaryrefslogtreecommitdiff
path: root/firmware/export
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 /firmware/export
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 'firmware/export')
-rw-r--r--firmware/export/config.h4
-rw-r--r--firmware/export/thread.h27
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 */
717#define HAVE_WAKEUP_EXT_CB 717#define HAVE_WAKEUP_EXT_CB
718 718
719 719
720#if (CONFIG_PLATFORM & PLATFORM_ANDROID) 720#if defined(ASSEMBLER_THREADS) \
721 || defined(HAVE_WIN32_FIBER_THREADS) \
722 || defined(HAVE_SIGALTSTACK_THREADS)
721#define HAVE_PRIORITY_SCHEDULING 723#define HAVE_PRIORITY_SCHEDULING
722#endif 724#endif
723 725
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 @@
84 * We need more stack when we run under a host 84 * We need more stack when we run under a host
85 * maybe more expensive C lib functions? 85 * maybe more expensive C lib functions?
86 * 86 *
87 * simulator doesn't simulate stack usage anyway but well ... */ 87 * simulator (possibly) doesn't simulate stack usage anyway but well ... */
88#if ((CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SIMULATOR)) 88#ifdef HAVE_SIGALTSTACK_THREADS
89#define DEFAULT_STACK_SIZE 0x400 /* Bytes */ 89#include <signal.h>
90#else 90/* MINSIGSTKSZ for the OS to deliver the signal + 0x3000 for us */
91#define DEFAULT_STACK_SIZE (MINSIGSTKSZ+0x3000) /* Bytes */
92#elif (CONFIG_PLATFORM & PLATFORM_ANDROID) || defined(HAVE_WIN32_FIBER_THREADS)
91#define DEFAULT_STACK_SIZE 0x1000 /* Bytes */ 93#define DEFAULT_STACK_SIZE 0x1000 /* Bytes */
94#else /* native threads, sdl threads */
95#define DEFAULT_STACK_SIZE 0x400 /* Bytes */
92#endif 96#endif
93 97
94 98
95#if (CONFIG_PLATFORM & (PLATFORM_NATIVE|PLATFORM_ANDROID)) 99#if defined(ASSEMBLER_THREADS)
96/* Need to keep structures inside the header file because debug_menu 100/* Need to keep structures inside the header file because debug_menu
97 * needs them. */ 101 * needs them. */
98#ifdef CPU_COLDFIRE 102#ifdef CPU_COLDFIRE
@@ -112,7 +116,7 @@ struct regs
112 uint32_t pr; /* 32 - Procedure register */ 116 uint32_t pr; /* 32 - Procedure register */
113 uint32_t start; /* 36 - Thread start address, or NULL when started */ 117 uint32_t start; /* 36 - Thread start address, or NULL when started */
114}; 118};
115#elif defined(CPU_ARM) || (CONFIG_PLATFORM & PLATFORM_ANDROID) 119#elif defined(CPU_ARM)
116struct regs 120struct regs
117{ 121{
118 uint32_t r[8]; /* 0-28 - Registers r4-r11 */ 122 uint32_t r[8]; /* 0-28 - Registers r4-r11 */
@@ -147,6 +151,16 @@ struct regs
147}; 151};
148#endif /* CONFIG_CPU */ 152#endif /* CONFIG_CPU */
149#elif (CONFIG_PLATFORM & PLATFORM_HOSTED) 153#elif (CONFIG_PLATFORM & PLATFORM_HOSTED)
154#ifndef HAVE_SDL_THREADS
155struct regs
156{
157 void (*start)(void); /* thread's entry point, or NULL when started */
158 void* uc; /* host thread handle */
159 uintptr_t sp; /* Stack pointer, unused */
160 size_t stack_size; /* stack size, not always used */
161 uintptr_t stack; /* pointer to start of the stack buffer */
162};
163#else /* SDL threads */
150struct regs 164struct regs
151{ 165{
152 void *t; /* OS thread */ 166 void *t; /* OS thread */
@@ -154,6 +168,7 @@ struct regs
154 void *s; /* Semaphore for blocking and wakeup */ 168 void *s; /* Semaphore for blocking and wakeup */
155 void (*start)(void); /* Start function */ 169 void (*start)(void); /* Start function */
156}; 170};
171#endif
157#endif /* PLATFORM_NATIVE */ 172#endif /* PLATFORM_NATIVE */
158 173
159/* NOTE: The use of the word "queue" may also refer to a linked list of 174/* NOTE: The use of the word "queue" may also refer to a linked list of