summaryrefslogtreecommitdiff
path: root/firmware/target/hosted
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted')
-rw-r--r--firmware/target/hosted/sdl/thread-sdl.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/firmware/target/hosted/sdl/thread-sdl.c b/firmware/target/hosted/sdl/thread-sdl.c
index fbc26c8a9f..c17e793833 100644
--- a/firmware/target/hosted/sdl/thread-sdl.c
+++ b/firmware/target/hosted/sdl/thread-sdl.c
@@ -682,3 +682,53 @@ void thread_get_name(char *buffer, int size,
682 snprintf(buffer, size, fmt, name); 682 snprintf(buffer, size, fmt, name);
683 } 683 }
684} 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/*---------------------------------------------------------------------------
696 * Suspends a thread's execution for at least the specified number of ticks.
697 *
698 * May result in CPU core entering wait-for-interrupt mode if no other thread
699 * may be scheduled.
700 *
701 * NOTE: sleep(0) sleeps until the end of the current tick
702 * sleep(n) that doesn't result in rescheduling:
703 * n <= ticks suspended < n + 1
704 * n to n+1 is a lower bound. Other factors may affect the actual time
705 * a thread is suspended before it runs again.
706 *---------------------------------------------------------------------------
707 */
708unsigned sleep(unsigned ticks)
709{
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();
716 sleep_thread(ticks);
717 switch_thread();
718 return 0;
719}
720
721/*---------------------------------------------------------------------------
722 * Elects another thread to run or, if no other thread may be made ready to
723 * run, immediately returns control back to the calling thread.
724 *---------------------------------------------------------------------------
725 */
726void yield(void)
727{
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();
734}