\section{include/sphinxbase/sbthread.h File Reference}
\label{sbthread_8h}\index{include/sphinxbase/sbthread.\+h@{include/sphinxbase/sbthread.\+h}}


Simple portable thread functions.  


{\ttfamily \#include $<$sphinx\+\_\+config.\+h$>$}\\*
{\ttfamily \#include $<$sphinxbase/sphinxbase\+\_\+export.\+h$>$}\\*
{\ttfamily \#include $<$sphinxbase/cmd\+\_\+ln.\+h$>$}\\*
\subsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
typedef struct {\bf sbthread\+\_\+s} {\bf sbthread\+\_\+t}\label{sbthread_8h_a068f6028c760eee1e4eb4655ac7e7424}

\begin{DoxyCompactList}\small\item\em Thread object. \end{DoxyCompactList}\item 
typedef struct {\bf sbmsgq\+\_\+s} {\bf sbmsgq\+\_\+t}\label{sbthread_8h_aad7adcc2e5f2fd6d2f429c25a52356ef}

\begin{DoxyCompactList}\small\item\em Asynchronous message queue object. \end{DoxyCompactList}\item 
typedef struct {\bf sbmtx\+\_\+s} {\bf sbmtx\+\_\+t}\label{sbthread_8h_a21bc1100c4336693a6f25cdeec40cbec}

\begin{DoxyCompactList}\small\item\em Mutex (critical section) object. \end{DoxyCompactList}\item 
typedef struct {\bf sbevent\+\_\+s} {\bf sbevent\+\_\+t}\label{sbthread_8h_a312dae368aa1662b07f199ea802cdefa}

\begin{DoxyCompactList}\small\item\em Event object. \end{DoxyCompactList}\item 
typedef int($\ast$ {\bf sbthread\+\_\+main} )({\bf sbthread\+\_\+t} $\ast$th)\label{sbthread_8h_acb30b2ddcf70058f8bd38d68920be777}

\begin{DoxyCompactList}\small\item\em Entry point for a thread. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf sbthread\+\_\+t} $\ast$ {\bf sbthread\+\_\+start} ({\bf cmd\+\_\+ln\+\_\+t} $\ast$config, {\bf sbthread\+\_\+main} func, void $\ast$arg)\label{sbthread_8h_abfe1f703f4e17a2940c88d86d1987a8f}

\begin{DoxyCompactList}\small\item\em Start a new thread. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int {\bf sbthread\+\_\+wait} ({\bf sbthread\+\_\+t} $\ast$th)\label{sbthread_8h_a09c5c428b02b743c99d20bb2b11d964b}

\begin{DoxyCompactList}\small\item\em Wait for a thread to complete. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T void {\bf sbthread\+\_\+free} ({\bf sbthread\+\_\+t} $\ast$th)\label{sbthread_8h_aa7827b760dfa47d95141f4896698e5c5}

\begin{DoxyCompactList}\small\item\em Free a thread object. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf cmd\+\_\+ln\+\_\+t} $\ast$ {\bf sbthread\+\_\+config} ({\bf sbthread\+\_\+t} $\ast$th)\label{sbthread_8h_ab03c2f299f3e94b9f53aac1c1eaa0695}

\begin{DoxyCompactList}\small\item\em Get configuration object from a thread. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T void $\ast$ {\bf sbthread\+\_\+arg} ({\bf sbthread\+\_\+t} $\ast$th)\label{sbthread_8h_a130f2273128498e0f1d875cf6c0c2928}

\begin{DoxyCompactList}\small\item\em Get argument pointer from a thread. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf sbmsgq\+\_\+t} $\ast$ {\bf sbthread\+\_\+msgq} ({\bf sbthread\+\_\+t} $\ast$th)\label{sbthread_8h_a5dfe1b7bb9c8d9aea7339e99a89307af}

\begin{DoxyCompactList}\small\item\em Get message queue from a thread. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int {\bf sbthread\+\_\+send} ({\bf sbthread\+\_\+t} $\ast$th, size\+\_\+t len, void const $\ast$data)
\begin{DoxyCompactList}\small\item\em Send an asynchronous message to a thread. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf sbmsgq\+\_\+t} $\ast$ {\bf sbmsgq\+\_\+init} (size\+\_\+t depth)
\begin{DoxyCompactList}\small\item\em Create a message queue. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T void {\bf sbmsgq\+\_\+free} ({\bf sbmsgq\+\_\+t} $\ast$q)\label{sbthread_8h_ab1ab59934422a5fac90ce0c4b66ffcc8}

\begin{DoxyCompactList}\small\item\em Free a message queue. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int {\bf sbmsgq\+\_\+send} ({\bf sbmsgq\+\_\+t} $\ast$q, size\+\_\+t len, void const $\ast$data)\label{sbthread_8h_ab0591b5cb626be52dd22edf8fa13a3e3}

\begin{DoxyCompactList}\small\item\em Post a message to a queue. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T void $\ast$ {\bf sbmsgq\+\_\+wait} ({\bf sbmsgq\+\_\+t} $\ast$q, size\+\_\+t $\ast$out\+\_\+len, int sec, int nsec)\label{sbthread_8h_ab3a421d172a92ef5ad371442a66767b5}

\begin{DoxyCompactList}\small\item\em Wait for a message from a queue. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf sbmtx\+\_\+t} $\ast$ {\bf sbmtx\+\_\+init} (void)\label{sbthread_8h_a28067c5be5370074d21668620a68b229}

\begin{DoxyCompactList}\small\item\em Create a mutex. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int {\bf sbmtx\+\_\+trylock} ({\bf sbmtx\+\_\+t} $\ast$mtx)\label{sbthread_8h_a3b86c81160360234944737b4eab73125}

\begin{DoxyCompactList}\small\item\em Try to acquire a mutex. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int {\bf sbmtx\+\_\+lock} ({\bf sbmtx\+\_\+t} $\ast$mtx)\label{sbthread_8h_a6615e839f7c8ef3ebb6b288525f002cd}

\begin{DoxyCompactList}\small\item\em Acquire a mutex. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int {\bf sbmtx\+\_\+unlock} ({\bf sbmtx\+\_\+t} $\ast$mtx)\label{sbthread_8h_af65691258c916c68f1b5d000aaea233f}

\begin{DoxyCompactList}\small\item\em Release a mutex. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T void {\bf sbmtx\+\_\+free} ({\bf sbmtx\+\_\+t} $\ast$mtx)\label{sbthread_8h_aa17a6a93744eb813ca80bf098c69bdba}

\begin{DoxyCompactList}\small\item\em Dispose of a mutex. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf sbevent\+\_\+t} $\ast$ {\bf sbevent\+\_\+init} (void)\label{sbthread_8h_a1b3fa1cf6b82dcd82ab8d4124ab12490}

\begin{DoxyCompactList}\small\item\em Initialize an event. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T void {\bf sbevent\+\_\+free} ({\bf sbevent\+\_\+t} $\ast$evt)\label{sbthread_8h_afe8253a0e804a019ad0d8c540eec75af}

\begin{DoxyCompactList}\small\item\em Free an event. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int {\bf sbevent\+\_\+signal} ({\bf sbevent\+\_\+t} $\ast$evt)\label{sbthread_8h_a7c01e3e70c2ab8e961d59db84aa5fa68}

\begin{DoxyCompactList}\small\item\em Signal an event. \end{DoxyCompactList}\item 
S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int {\bf sbevent\+\_\+wait} ({\bf sbevent\+\_\+t} $\ast$evt, int sec, int nsec)\label{sbthread_8h_ac211760e4dffccf0102db65fb6f2c5b3}

\begin{DoxyCompactList}\small\item\em Wait for an event to be signalled. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Simple portable thread functions. 

\begin{DoxyAuthor}{Author}
David Huggins-\/\+Daines {\tt dhuggins@cs.\+cmu.\+edu} 
\end{DoxyAuthor}


Definition in file {\bf sbthread.\+h}.



\subsection{Function Documentation}
\index{sbthread.\+h@{sbthread.\+h}!sbmsgq\+\_\+init@{sbmsgq\+\_\+init}}
\index{sbmsgq\+\_\+init@{sbmsgq\+\_\+init}!sbthread.\+h@{sbthread.\+h}}
\subsubsection[{sbmsgq\+\_\+init}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T {\bf sbmsgq\+\_\+t}$\ast$ sbmsgq\+\_\+init (
\begin{DoxyParamCaption}
\item[{size\+\_\+t}]{depth}
\end{DoxyParamCaption}
)}\label{sbthread_8h_a535a4d0d3f71c30f32d75b6268cc5e1e}


Create a message queue. 


\begin{DoxyParams}{Parameters}
{\em depth} & Depth of the queue. \\
\hline
\end{DoxyParams}


Definition at line 444 of file sbthread.\+c.



References ckd\+\_\+calloc, and ckd\+\_\+free().



Referenced by sbthread\+\_\+start().

\index{sbthread.\+h@{sbthread.\+h}!sbthread\+\_\+send@{sbthread\+\_\+send}}
\index{sbthread\+\_\+send@{sbthread\+\_\+send}!sbthread.\+h@{sbthread.\+h}}
\subsubsection[{sbthread\+\_\+send}]{\setlength{\rightskip}{0pt plus 5cm}S\+P\+H\+I\+N\+X\+B\+A\+S\+E\+\_\+\+E\+X\+P\+O\+R\+T int sbthread\+\_\+send (
\begin{DoxyParamCaption}
\item[{{\bf sbthread\+\_\+t} $\ast$}]{th, }
\item[{size\+\_\+t}]{len, }
\item[{void const $\ast$}]{data}
\end{DoxyParamCaption}
)}\label{sbthread_8h_a932830409403ab4a03f0ffefe907551e}


Send an asynchronous message to a thread. 

Each thread gets a message queue by default, so this is just a wrapper around \doxyref{sbmsgq\+\_\+send()}{p.}{sbthread_8h_ab0591b5cb626be52dd22edf8fa13a3e3}. 

Definition at line 728 of file sbthread.\+c.



References sbmsgq\+\_\+send().

