diff --git a/src/lib/thread.c b/src/lib/thread.c index e2280c63fe..782a63ea52 100644 --- a/src/lib/thread.c +++ b/src/lib/thread.c @@ -9,6 +9,8 @@ #include #include +static bool initialized; + static void idle_thread_init(void); /* There needs to be at least one thread to run the ramstate state machine. */ @@ -40,6 +42,9 @@ static inline struct thread *cpu_info_to_thread(const struct cpu_info *ci) static inline struct thread *current_thread(void) { + if (!initialized) + return NULL; + return cpu_info_to_thread(cpu_info()); } @@ -265,6 +270,8 @@ void threads_initialize(void) free_thread(t); } + initialized = 1; + idle_thread_init(); }