threads.h File Reference

Go to the source code of this file.

Data Structures

struct  thread_t

Defines

#define TICK2US(x)   (((x) * 4) / 243)
#define US2TICK(x)   (((x) * 243) / 4)
#define DEC_TIMER   (100)

Enumerations

enum  thread_state_t { THREAD_EXITED = -2, THREAD_UNRUNNABLE = -1, THREAD_RUNNABLE = 0 }

Functions

int threads_initialize (void)
 Initialize the threading subsystem.
int threads_shutdown (void)
 Shut down the threading subsystem.
int threads_create (int priority, thread_state_t state, void *stack, u32 stacksize, void *pc)
 Create a thread.
int threads_create_adv (int priority, thread_state_t state, void *stack, void *pc, u32 msr, u32 ctr, u32 xer, u32 cr, u32 lr, u32 fpscr, u32 gprs[32], u64 fprs[32])
 Create a thread.
int threads_get_pid (void)
 Get's the PID of the current thread.
int threads_destroy (int pid)
 Destroy a thread.
void threads_exit (int code)
 Exits the current thread.
int threads_state (int pid)
 Get the state of a thread.
int threads_exitcode (int pid)
 Get the exit code of a thread.
void threads_yield (void)
 Yield the current thread to the scheduler.
int threads_freeze (void)
 Freeze the scheduler.
void threads_unfreeze (int frz)
 Unfreeze the scheduler.

Detailed Description

A threading API written specifically for the Wii for mini-broadway.


Function Documentation

int threads_create ( int  priority,
thread_state_t  state,
void *  stack,
u32  stacksize,
void *  pc 
)

Create a thread.

A simple method to create a thread.

Parameters:
priority the priority level of the thread. Range from -5 to 5.
state the beginning state of the thread.
stack a pointer to a section of memory to be used as the thread's stack.
stacksize the size of the stack for the thread.
pc a function to be executed by the thread.
Returns:
The PID of the new thread, or 0 if thread creation failed.
See also:
threads_create_adv()
int threads_create_adv ( int  priority,
thread_state_t  state,
void *  stack,
void *  pc,
u32  msr,
u32  ctr,
u32  xer,
u32  cr,
u32  lr,
u32  fpscr,
u32  gprs[32],
u64  fprs[32] 
)

Create a thread.

A complex method to create a thread.

Parameters:
priority the priority level of the thread. Range from -5 to 5.
state the beginning state of the thread.
stack a pointer to a section of memory to be used as the thread's stack.
pc a function to be executed by the thread.
msr the MSR of the new thread.
ctr the CTR of the new thread.
xer the XER of the new thread.
cr the CR of the new thread.
lr the LR of the new thread.
fpscr the FPSCR of the new thread.
gprs the GPRs of the new thread. You must have r1 set to the stack, as this function will not automatically set it for you.
fprs the FPRs of the new thread.
Returns:
The PID of the new thread, or 0 if thread creation failed.
See also:
threads_create()
int threads_destroy ( int  pid  ) 

Destroy a thread.

Ends execution of a thread with specified PID, and removes it from the queue.

Parameters:
pid the PID of the thread to destroy.
Returns:
If thread was destroyed, returns 1. Otherwise 0.
See also:
threads_create(), threads_create_adv()
void threads_exit ( int  code  ) 

Exits the current thread.

Ends execution of the current thread, and disables it from running. The thread still will remain in the queue however, so make sure to destroy it later with threads_destroy().

Parameters:
code the exit code for the thread to go out on.
See also:
threads_create(), threads_create_adv(), threads_destroy()
int threads_exitcode ( int  pid  ) 

Get the exit code of a thread.

Returns the exit code of the thread with the specified PID. If the thread has not yet exited, this value will be 0.

Parameters:
pid the PID of the thread to get the exit code of.
Returns:
Exit code of the thread if found. Otherwise -1.
See also:
threads_create(), threads_create_adv(), threads_exit()
int threads_freeze ( void   ) 

Freeze the scheduler.

BE EXTREMELY CAREFUL WITH THIS FUNCTION, AS IMPROPER USE WILL LEAD TO A COMPLETE LOCKUP. Freeze the scheduler and disable external interrupts in order to provide a safe area for no scheduler disruptions.

Returns:
A cookie to be passed to threads_unfreeze() at the end of the block.
See also:
threads_unfreeze()
int threads_get_pid ( void   ) 

Get's the PID of the current thread.

Returns:
The PID of the current thread.
int threads_initialize ( void   ) 

Initialize the threading subsystem.

Initializes the threading subsystem, registers the handler for the decrementer and performs all other required initialization tasks.

Returns:
If initialization was successful, returns 1. Otherwise 0.
See also:
threads_shutdown()
int threads_shutdown ( void   ) 

Shut down the threading subsystem.

Shuts down the threading subsystem, unregisters the handler for the decrementer and performs all other required shut down tasks.

Returns:
If shut down was successful, returns 1. Otherwise 0.
See also:
threads_initialize()
int threads_state ( int  pid  ) 

Get the state of a thread.

Returns the state of the thread with the specified PID.

Parameters:
pid the PID of the thread to get the state of.
Returns:
State of the thread if found. Otherwise -3.
See also:
threads_create(), threads_create_adv()
void threads_unfreeze ( int  frz  ) 

Unfreeze the scheduler.

Unfreeze the scheduler and re-enable external interrupts if they were as such before the freeze that the cookie corresponds to.

Parameters:
frz the cookie returned from the corresponding threads_freeze() call.
See also:
threads_freeze()
void threads_yield ( void   ) 

Yield the current thread to the scheduler.

The current thread suspends execution and gives the remainder of its time up to the scheduler and other threads.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines
Generated by  doxygen 1.6.3