kern/thread.h File Reference

Thread management. More...

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


Functions

void init_thread (void)
void start_sched (void)
void schedule (void)
void suspend (void)
void resume (struct thread *t)
void pause (uint16_t ms)
void yield (void)
void exit (int)
uint8_t create_thread (int(*func)(), uint16_t stacksize, uint8_t priority, char *name)
void halt (void)
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:
func Entry point of thread.
stacksize Size (in bytes) of new thread.
priority Priority of new thread. 0 = highest, 255 = lowest
name Name of thread, used for debugging.
Returns:
Thread ID of the new thread.

void dump_threadstates (  ) 

Output to the UART the state of every thread.

void 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).

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 ( uint16_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:
ms Milliseconds to pause.

void resume ( struct thread *  t  ) 

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

Parameters:
t Thread to be run.

void schedule ( void   ) 

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

void start_sched ( void   ) 

Jump to scheduler, nuke the kstack. Should not be called by user.

void suspend ( void   ) 

Suspend the current thread and call the scheduler. Should not be called by user.

void yield ( void   ) 

Give up the processor to another thread until rescheduled.