\hypertarget{threads_8h}{
\section{libthreads/include/threads.h File Reference}
\label{threads_8h}\index{libthreads/include/threads.h@{libthreads/include/threads.h}}
}
\subsection*{Data Structures}
\begin{DoxyCompactItemize}
\item 
struct \hyperlink{structthread__t}{thread\_\-t}
\end{DoxyCompactItemize}
\subsection*{Defines}
\begin{DoxyCompactItemize}
\item 
\hypertarget{threads_8h_ae8eba064f7e56cc70a264127f64f9e5c}{
\#define {\bfseries TICK2US}(x)~(((x) $\ast$ 4) / 243)}
\label{threads_8h_ae8eba064f7e56cc70a264127f64f9e5c}

\item 
\hypertarget{threads_8h_aea3e195da02cccc3aca9e626b18f773b}{
\#define {\bfseries US2TICK}(x)~(((x) $\ast$ 243) / 4)}
\label{threads_8h_aea3e195da02cccc3aca9e626b18f773b}

\item 
\hypertarget{threads_8h_a54defdc5f0d5fdc0ab9ccd680da13559}{
\#define {\bfseries DEC\_\-TIMER}~(100)}
\label{threads_8h_a54defdc5f0d5fdc0ab9ccd680da13559}

\end{DoxyCompactItemize}
\subsection*{Enumerations}
\begin{DoxyCompactItemize}
\item 
enum {\bfseries thread\_\-state\_\-t} \{ {\bfseries THREAD\_\-EXITED} =  -\/2, 
{\bfseries THREAD\_\-UNRUNNABLE} =  -\/1, 
{\bfseries THREAD\_\-RUNNABLE} =  0
 \}
\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
int \hyperlink{threads_8h_accc41e9fe830a79496a05ff47b7d9dba}{threads\_\-initialize} (void)
\begin{DoxyCompactList}\small\item\em Initialize the threading subsystem. \item\end{DoxyCompactList}\item 
int \hyperlink{threads_8h_a653ec0a011c51c37f6f5f8967014c6b4}{threads\_\-shutdown} (void)
\begin{DoxyCompactList}\small\item\em Shut down the threading subsystem. \item\end{DoxyCompactList}\item 
int \hyperlink{threads_8h_a66d45776cc6d7e48f08244cce5605105}{threads\_\-create} (int priority, thread\_\-state\_\-t state, void $\ast$stack, u32 stacksize, void $\ast$pc)
\begin{DoxyCompactList}\small\item\em Create a thread. \item\end{DoxyCompactList}\item 
int \hyperlink{threads_8h_a47ba2b063e83833a943de59cabaea8cc}{threads\_\-create\_\-adv} (int priority, thread\_\-state\_\-t state, void $\ast$stack, void $\ast$pc, u32 msr, u32 ctr, u32 xer, u32 cr, u32 lr, u32 fpscr, u32 gprs\mbox{[}32\mbox{]}, u64 fprs\mbox{[}32\mbox{]})
\begin{DoxyCompactList}\small\item\em Create a thread. \item\end{DoxyCompactList}\item 
int \hyperlink{threads_8h_a037c42abd03b9e094ef04f6ee44b3252}{threads\_\-get\_\-pid} (void)
\begin{DoxyCompactList}\small\item\em Get's the PID of the current thread. \item\end{DoxyCompactList}\item 
int \hyperlink{threads_8h_a6e116d399b6368351a3a78142e8f749e}{threads\_\-destroy} (int pid)
\begin{DoxyCompactList}\small\item\em Destroy a thread. \item\end{DoxyCompactList}\item 
void \hyperlink{threads_8h_a6663973a2d6fc9c51ee60dfb06ad7766}{threads\_\-exit} (int code)
\begin{DoxyCompactList}\small\item\em Exits the current thread. \item\end{DoxyCompactList}\item 
int \hyperlink{threads_8h_a313c552ad3710ef207e12c440084c122}{threads\_\-state} (int pid)
\begin{DoxyCompactList}\small\item\em Get the state of a thread. \item\end{DoxyCompactList}\item 
int \hyperlink{threads_8h_a5123b953177f7cd770dcff340cb7044c}{threads\_\-exitcode} (int pid)
\begin{DoxyCompactList}\small\item\em Get the exit code of a thread. \item\end{DoxyCompactList}\item 
void \hyperlink{threads_8h_a4271e197c02bc45fccfe892cce168351}{threads\_\-yield} (void)
\begin{DoxyCompactList}\small\item\em Yield the current thread to the scheduler. \item\end{DoxyCompactList}\item 
int \hyperlink{threads_8h_abc896cb1753c100e660ea0853ecdbd95}{threads\_\-freeze} (void)
\begin{DoxyCompactList}\small\item\em Freeze the scheduler. \item\end{DoxyCompactList}\item 
void \hyperlink{threads_8h_aab353dcfd825efa1143689533afa5e22}{threads\_\-unfreeze} (int frz)
\begin{DoxyCompactList}\small\item\em Unfreeze the scheduler. \item\end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
A threading API written specifically for the Wii for mini-\/broadway. 

\subsection{Function Documentation}
\hypertarget{threads_8h_a66d45776cc6d7e48f08244cce5605105}{
\index{threads.h@{threads.h}!threads\_\-create@{threads\_\-create}}
\index{threads\_\-create@{threads\_\-create}!threads.h@{threads.h}}
\subsubsection[{threads\_\-create}]{\setlength{\rightskip}{0pt plus 5cm}int threads\_\-create (int {\em priority}, \/  thread\_\-state\_\-t {\em state}, \/  void $\ast$ {\em stack}, \/  u32 {\em stacksize}, \/  void $\ast$ {\em pc})}}
\label{threads_8h_a66d45776cc6d7e48f08244cce5605105}


Create a thread. 

A simple method to create a thread. 
\begin{DoxyParams}{Parameters}
\item[{\em priority}]the priority level of the thread. Range from -\/5 to 5. \item[{\em state}]the beginning state of the thread. \item[{\em stack}]a pointer to a section of memory to be used as the thread's stack. \item[{\em stacksize}]the size of the stack for the thread. \item[{\em pc}]a function to be executed by the thread. \end{DoxyParams}
\begin{DoxyReturn}{Returns}
The PID of the new thread, or 0 if thread creation failed. 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{threads_8h_a47ba2b063e83833a943de59cabaea8cc}{threads\_\-create\_\-adv()} 
\end{DoxySeeAlso}
\hypertarget{threads_8h_a47ba2b063e83833a943de59cabaea8cc}{
\index{threads.h@{threads.h}!threads\_\-create\_\-adv@{threads\_\-create\_\-adv}}
\index{threads\_\-create\_\-adv@{threads\_\-create\_\-adv}!threads.h@{threads.h}}
\subsubsection[{threads\_\-create\_\-adv}]{\setlength{\rightskip}{0pt plus 5cm}int threads\_\-create\_\-adv (int {\em priority}, \/  thread\_\-state\_\-t {\em state}, \/  void $\ast$ {\em stack}, \/  void $\ast$ {\em pc}, \/  u32 {\em msr}, \/  u32 {\em ctr}, \/  u32 {\em xer}, \/  u32 {\em cr}, \/  u32 {\em lr}, \/  u32 {\em fpscr}, \/  u32 {\em gprs}\mbox{[}32\mbox{]}, \/  u64 {\em fprs}\mbox{[}32\mbox{]})}}
\label{threads_8h_a47ba2b063e83833a943de59cabaea8cc}


Create a thread. 

A complex method to create a thread. 
\begin{DoxyParams}{Parameters}
\item[{\em priority}]the priority level of the thread. Range from -\/5 to 5. \item[{\em state}]the beginning state of the thread. \item[{\em stack}]a pointer to a section of memory to be used as the thread's stack. \item[{\em pc}]a function to be executed by the thread. \item[{\em msr}]the MSR of the new thread. \item[{\em ctr}]the CTR of the new thread. \item[{\em xer}]the XER of the new thread. \item[{\em cr}]the CR of the new thread. \item[{\em lr}]the LR of the new thread. \item[{\em fpscr}]the FPSCR of the new thread. \item[{\em 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. \item[{\em fprs}]the FPRs of the new thread. \end{DoxyParams}
\begin{DoxyReturn}{Returns}
The PID of the new thread, or 0 if thread creation failed. 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{threads_8h_a66d45776cc6d7e48f08244cce5605105}{threads\_\-create()} 
\end{DoxySeeAlso}
\hypertarget{threads_8h_a6e116d399b6368351a3a78142e8f749e}{
\index{threads.h@{threads.h}!threads\_\-destroy@{threads\_\-destroy}}
\index{threads\_\-destroy@{threads\_\-destroy}!threads.h@{threads.h}}
\subsubsection[{threads\_\-destroy}]{\setlength{\rightskip}{0pt plus 5cm}int threads\_\-destroy (int {\em pid})}}
\label{threads_8h_a6e116d399b6368351a3a78142e8f749e}


Destroy a thread. 

Ends execution of a thread with specified PID, and removes it from the queue. 
\begin{DoxyParams}{Parameters}
\item[{\em pid}]the PID of the thread to destroy. \end{DoxyParams}
\begin{DoxyReturn}{Returns}
If thread was destroyed, returns 1. Otherwise 0. 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{threads_8h_a66d45776cc6d7e48f08244cce5605105}{threads\_\-create()}, \hyperlink{threads_8h_a47ba2b063e83833a943de59cabaea8cc}{threads\_\-create\_\-adv()} 
\end{DoxySeeAlso}
\hypertarget{threads_8h_a6663973a2d6fc9c51ee60dfb06ad7766}{
\index{threads.h@{threads.h}!threads\_\-exit@{threads\_\-exit}}
\index{threads\_\-exit@{threads\_\-exit}!threads.h@{threads.h}}
\subsubsection[{threads\_\-exit}]{\setlength{\rightskip}{0pt plus 5cm}void threads\_\-exit (int {\em code})}}
\label{threads_8h_a6663973a2d6fc9c51ee60dfb06ad7766}


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 \hyperlink{threads_8h_a6e116d399b6368351a3a78142e8f749e}{threads\_\-destroy()}. 
\begin{DoxyParams}{Parameters}
\item[{\em code}]the exit code for the thread to go out on. \end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{threads_8h_a66d45776cc6d7e48f08244cce5605105}{threads\_\-create()}, \hyperlink{threads_8h_a47ba2b063e83833a943de59cabaea8cc}{threads\_\-create\_\-adv()}, \hyperlink{threads_8h_a6e116d399b6368351a3a78142e8f749e}{threads\_\-destroy()} 
\end{DoxySeeAlso}
\hypertarget{threads_8h_a5123b953177f7cd770dcff340cb7044c}{
\index{threads.h@{threads.h}!threads\_\-exitcode@{threads\_\-exitcode}}
\index{threads\_\-exitcode@{threads\_\-exitcode}!threads.h@{threads.h}}
\subsubsection[{threads\_\-exitcode}]{\setlength{\rightskip}{0pt plus 5cm}int threads\_\-exitcode (int {\em pid})}}
\label{threads_8h_a5123b953177f7cd770dcff340cb7044c}


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. 
\begin{DoxyParams}{Parameters}
\item[{\em pid}]the PID of the thread to get the exit code of. \end{DoxyParams}
\begin{DoxyReturn}{Returns}
Exit code of the thread if found. Otherwise -\/1. 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{threads_8h_a66d45776cc6d7e48f08244cce5605105}{threads\_\-create()}, \hyperlink{threads_8h_a47ba2b063e83833a943de59cabaea8cc}{threads\_\-create\_\-adv()}, \hyperlink{threads_8h_a6663973a2d6fc9c51ee60dfb06ad7766}{threads\_\-exit()} 
\end{DoxySeeAlso}
\hypertarget{threads_8h_abc896cb1753c100e660ea0853ecdbd95}{
\index{threads.h@{threads.h}!threads\_\-freeze@{threads\_\-freeze}}
\index{threads\_\-freeze@{threads\_\-freeze}!threads.h@{threads.h}}
\subsubsection[{threads\_\-freeze}]{\setlength{\rightskip}{0pt plus 5cm}int threads\_\-freeze (void)}}
\label{threads_8h_abc896cb1753c100e660ea0853ecdbd95}


Freeze the scheduler. 

{\bfseries BE EXTREMELY CAREFUL WITH THIS FUNCTION, AS IMPROPER USE {\itshape WILL\/} LEAD TO A COMPLETE LOCKUP.} Freeze the scheduler and disable external interrupts in order to provide a safe area for no scheduler disruptions. \begin{DoxyReturn}{Returns}
A cookie to be passed to \hyperlink{threads_8h_aab353dcfd825efa1143689533afa5e22}{threads\_\-unfreeze()} at the end of the block. 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{threads_8h_aab353dcfd825efa1143689533afa5e22}{threads\_\-unfreeze()} 
\end{DoxySeeAlso}
\hypertarget{threads_8h_a037c42abd03b9e094ef04f6ee44b3252}{
\index{threads.h@{threads.h}!threads\_\-get\_\-pid@{threads\_\-get\_\-pid}}
\index{threads\_\-get\_\-pid@{threads\_\-get\_\-pid}!threads.h@{threads.h}}
\subsubsection[{threads\_\-get\_\-pid}]{\setlength{\rightskip}{0pt plus 5cm}int threads\_\-get\_\-pid (void)}}
\label{threads_8h_a037c42abd03b9e094ef04f6ee44b3252}


Get's the PID of the current thread. 

\begin{DoxyReturn}{Returns}
The PID of the current thread. 
\end{DoxyReturn}
\hypertarget{threads_8h_accc41e9fe830a79496a05ff47b7d9dba}{
\index{threads.h@{threads.h}!threads\_\-initialize@{threads\_\-initialize}}
\index{threads\_\-initialize@{threads\_\-initialize}!threads.h@{threads.h}}
\subsubsection[{threads\_\-initialize}]{\setlength{\rightskip}{0pt plus 5cm}int threads\_\-initialize (void)}}
\label{threads_8h_accc41e9fe830a79496a05ff47b7d9dba}


Initialize the threading subsystem. 

Initializes the threading subsystem, registers the handler for the decrementer and performs all other required initialization tasks. \begin{DoxyReturn}{Returns}
If initialization was successful, returns 1. Otherwise 0. 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{threads_8h_a653ec0a011c51c37f6f5f8967014c6b4}{threads\_\-shutdown()} 
\end{DoxySeeAlso}
\hypertarget{threads_8h_a653ec0a011c51c37f6f5f8967014c6b4}{
\index{threads.h@{threads.h}!threads\_\-shutdown@{threads\_\-shutdown}}
\index{threads\_\-shutdown@{threads\_\-shutdown}!threads.h@{threads.h}}
\subsubsection[{threads\_\-shutdown}]{\setlength{\rightskip}{0pt plus 5cm}int threads\_\-shutdown (void)}}
\label{threads_8h_a653ec0a011c51c37f6f5f8967014c6b4}


Shut down the threading subsystem. 

Shuts down the threading subsystem, unregisters the handler for the decrementer and performs all other required shut down tasks. \begin{DoxyReturn}{Returns}
If shut down was successful, returns 1. Otherwise 0. 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{threads_8h_accc41e9fe830a79496a05ff47b7d9dba}{threads\_\-initialize()} 
\end{DoxySeeAlso}
\hypertarget{threads_8h_a313c552ad3710ef207e12c440084c122}{
\index{threads.h@{threads.h}!threads\_\-state@{threads\_\-state}}
\index{threads\_\-state@{threads\_\-state}!threads.h@{threads.h}}
\subsubsection[{threads\_\-state}]{\setlength{\rightskip}{0pt plus 5cm}int threads\_\-state (int {\em pid})}}
\label{threads_8h_a313c552ad3710ef207e12c440084c122}


Get the state of a thread. 

Returns the state of the thread with the specified PID. 
\begin{DoxyParams}{Parameters}
\item[{\em pid}]the PID of the thread to get the state of. \end{DoxyParams}
\begin{DoxyReturn}{Returns}
State of the thread if found. Otherwise -\/3. 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{threads_8h_a66d45776cc6d7e48f08244cce5605105}{threads\_\-create()}, \hyperlink{threads_8h_a47ba2b063e83833a943de59cabaea8cc}{threads\_\-create\_\-adv()} 
\end{DoxySeeAlso}
\hypertarget{threads_8h_aab353dcfd825efa1143689533afa5e22}{
\index{threads.h@{threads.h}!threads\_\-unfreeze@{threads\_\-unfreeze}}
\index{threads\_\-unfreeze@{threads\_\-unfreeze}!threads.h@{threads.h}}
\subsubsection[{threads\_\-unfreeze}]{\setlength{\rightskip}{0pt plus 5cm}void threads\_\-unfreeze (int {\em frz})}}
\label{threads_8h_aab353dcfd825efa1143689533afa5e22}


Unfreeze the scheduler. 

Unfreeze the scheduler and re-\/enable external interrupts if they were as such before the freeze that the cookie corresponds to. 
\begin{DoxyParams}{Parameters}
\item[{\em frz}]the cookie returned from the corresponding \hyperlink{threads_8h_abc896cb1753c100e660ea0853ecdbd95}{threads\_\-freeze()} call. \end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{threads_8h_abc896cb1753c100e660ea0853ecdbd95}{threads\_\-freeze()} 
\end{DoxySeeAlso}
\hypertarget{threads_8h_a4271e197c02bc45fccfe892cce168351}{
\index{threads.h@{threads.h}!threads\_\-yield@{threads\_\-yield}}
\index{threads\_\-yield@{threads\_\-yield}!threads.h@{threads.h}}
\subsubsection[{threads\_\-yield}]{\setlength{\rightskip}{0pt plus 5cm}void threads\_\-yield (void)}}
\label{threads_8h_a4271e197c02bc45fccfe892cce168351}


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. 