Functions
kern/thread.h File Reference

Thread management. More...

#include <setjmp.h>
#include <config.h>
#include <stdint.h>

Functions

void init_thread (void)
void schedule (void) __ATTR_NORETURN__
void resume (struct thread *t) __ATTR_NORETURN__
void pause (uint32_t ms)
void yield (void)
void thread_exit (int) __ATTR_NORETURN__
uint8_t create_thread (int(*func)(), uint16_t stacksize, uint8_t priority, char *name)
void halt (void) __ATTR_NORETURN__
uint32_t get_time (void)
void dump_threadstates ()

Detailed Description

JoyOS includes a round-robbin pre-emptive scheduler, with a system tick of 1ms.


Function Documentation

uint8_t create_thread ( int(*)()  func,
uint16_t  stacksize,
uint8_t  priority,
char *  name 
)

Create a new thread. This routine will setup a new thread that will enter in 'func' and return immediately. When 'func' returns, the new thread will terminate (via exit).

Parameters:
funcEntry point of thread.
stacksizeSize (in bytes) of new thread.
priorityPriority of new thread. 0 = highest, 255 = lowest
nameName of thread, used for debugging.
Returns:
Thread ID of the new thread.

Output to the UART the state of every thread.

uint32_t get_time ( void  )

Return the number of milliseconds elapsed since startup.

void halt ( void  )

Stop everything.

void init_thread ( void  )

Initialize multithreading. Should not be called by user.

void pause ( uint32_t  ms)

Pause a thread for 'ms' milliseconds. The calling thread will give up the processor until time expires. If interrupts are disabled, a busy loop will be used. The pause is best-effort and may last several milliseconds longer than specified. If threads pause frequently for short periods of time (1-4ms, depending) thread starvation may occur.

Parameters:
msMilliseconds to pause.
void resume ( struct thread *  t)

Load a thread and run it. Should not be called by user.

Parameters:
tThread to be run.
void schedule ( void  )

Schedule a thread to run. Should not be called by user.

void thread_exit ( int  )

Terminate and exit the current thread. This will free the thread's stack space, but not any of it's dynamically allocated memory (malloc).

void yield ( void  )

Give up the processor to another thread until rescheduled.