summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/sdl/thread-sdl.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/sdl/thread-sdl.c')
-rw-r--r--firmware/target/hosted/sdl/thread-sdl.c80
1 files changed, 8 insertions, 72 deletions
diff --git a/firmware/target/hosted/sdl/thread-sdl.c b/firmware/target/hosted/sdl/thread-sdl.c
index e117a4e3b6..fda877e0f5 100644
--- a/firmware/target/hosted/sdl/thread-sdl.c
+++ b/firmware/target/hosted/sdl/thread-sdl.c
@@ -28,10 +28,7 @@
28#include <setjmp.h> 28#include <setjmp.h>
29#include "system-sdl.h" 29#include "system-sdl.h"
30#include "thread-sdl.h" 30#include "thread-sdl.h"
31#include "system.h" 31#include "../kernel-internal.h"
32#include "kernel.h"
33#include "thread.h"
34#include "debug.h"
35#include "core_alloc.h" 32#include "core_alloc.h"
36 33
37/* Define this as 1 to show informational messages that are not errors. */ 34/* Define this as 1 to show informational messages that are not errors. */
@@ -165,6 +162,7 @@ static struct thread_entry * find_empty_thread_slot(void)
165/* Initialize SDL threading */ 162/* Initialize SDL threading */
166void init_threads(void) 163void init_threads(void)
167{ 164{
165 static uintptr_t main_stack[] = { DEADBEEF, 0 };
168 struct thread_entry *thread; 166 struct thread_entry *thread;
169 int n; 167 int n;
170 168
@@ -187,8 +185,8 @@ void init_threads(void)
187 then create the SDL thread - it is possible to have a quick, early 185 then create the SDL thread - it is possible to have a quick, early
188 shutdown try to access the structure. */ 186 shutdown try to access the structure. */
189 thread = &threads[0]; 187 thread = &threads[0];
190 thread->stack = (uintptr_t *)" "; 188 thread->stack = main_stack;
191 thread->stack_size = 8; 189 thread->stack_size = sizeof (main_stack);
192 thread->name = "main"; 190 thread->name = "main";
193 thread->state = STATE_RUNNING; 191 thread->state = STATE_RUNNING;
194 thread->context.s = SDL_CreateSemaphore(0); 192 thread->context.s = SDL_CreateSemaphore(0);
@@ -439,23 +437,6 @@ unsigned int wakeup_thread_(struct thread_entry **list)
439 return THREAD_NONE; 437 return THREAD_NONE;
440} 438}
441 439
442unsigned int thread_queue_wake(struct thread_entry **list)
443{
444 unsigned int result = THREAD_NONE;
445
446 for (;;)
447 {
448 unsigned int rc = wakeup_thread_(list);
449
450 if (rc == THREAD_NONE)
451 break;
452
453 result |= rc;
454 }
455
456 return result;
457}
458
459void thread_thaw(unsigned int thread_id) 440void thread_thaw(unsigned int thread_id)
460{ 441{
461 struct thread_entry *thread = thread_id_entry(thread_id); 442 struct thread_entry *thread = thread_id_entry(thread_id);
@@ -542,6 +523,10 @@ unsigned int create_thread(void (*function)(void),
542 return 0; 523 return 0;
543 } 524 }
544 525
526 unsigned int stack_words = stack_size / sizeof (uintptr_t);
527 for (unsigned int i = stack_words; i-- > 0;)
528 ((uintptr_t *)stack)[i] = DEADBEEF;
529
545 thread->stack = stack; 530 thread->stack = stack;
546 thread->stack_size = stack_size; 531 thread->stack_size = stack_size;
547 thread->name = name; 532 thread->name = name;
@@ -557,11 +542,7 @@ unsigned int create_thread(void (*function)(void),
557 return thread->id; 542 return thread->id;
558} 543}
559 544
560#ifndef ALLOW_REMOVE_THREAD
561static void remove_thread(unsigned int thread_id) 545static void remove_thread(unsigned int thread_id)
562#else
563void remove_thread(unsigned int thread_id)
564#endif
565{ 546{
566 struct thread_entry *current = cores[CURRENT_CORE].running; 547 struct thread_entry *current = cores[CURRENT_CORE].running;
567 struct thread_entry *thread = thread_id_entry(thread_id); 548 struct thread_entry *thread = thread_id_entry(thread_id);
@@ -657,41 +638,6 @@ void thread_wait(unsigned int thread_id)
657 } 638 }
658} 639}
659 640
660int thread_stack_usage(const struct thread_entry *thread)
661{
662 return 50;
663 (void)thread;
664}
665
666/* Return name if one or ID if none */
667void thread_get_name(char *buffer, int size,
668 struct thread_entry *thread)
669{
670 if (size <= 0)
671 return;
672
673 *buffer = '\0';
674
675 if (thread)
676 {
677 /* Display thread name if one or ID if none */
678 bool named = thread->name && *thread->name;
679 const char *fmt = named ? "%s" : "%04lX";
680 intptr_t name = named ?
681 (intptr_t)thread->name : (intptr_t)thread->id;
682 snprintf(buffer, size, fmt, name);
683 }
684}
685
686/* Unless otherwise defined, do nothing */
687#ifndef YIELD_KERNEL_HOOK
688#define YIELD_KERNEL_HOOK() false
689#endif
690#ifndef SLEEP_KERNEL_HOOK
691#define SLEEP_KERNEL_HOOK(ticks) false
692#endif
693
694
695/*--------------------------------------------------------------------------- 641/*---------------------------------------------------------------------------
696 * Suspends a thread's execution for at least the specified number of ticks. 642 * Suspends a thread's execution for at least the specified number of ticks.
697 * 643 *
@@ -707,11 +653,6 @@ void thread_get_name(char *buffer, int size,
707 */ 653 */
708unsigned sleep(unsigned ticks) 654unsigned sleep(unsigned ticks)
709{ 655{
710 /* In certain situations, certain bootloaders in particular, a normal
711 * threading call is inappropriate. */
712 if (SLEEP_KERNEL_HOOK(ticks))
713 return 0; /* Handled */
714
715 disable_irq(); 656 disable_irq();
716 sleep_thread(ticks); 657 sleep_thread(ticks);
717 switch_thread(); 658 switch_thread();
@@ -725,10 +666,5 @@ unsigned sleep(unsigned ticks)
725 */ 666 */
726void yield(void) 667void yield(void)
727{ 668{
728 /* In certain situations, certain bootloaders in particular, a normal
729 * threading call is inappropriate. */
730 if (YIELD_KERNEL_HOOK())
731 return; /* handled */
732
733 switch_thread(); 669 switch_thread();
734} 670}