\section{src/libsphinxbase/util/sbthread.c File Reference}
\label{sbthread_8c}\index{src/libsphinxbase/util/sbthread.\+c@{src/libsphinxbase/util/sbthread.\+c}}


Simple portable thread functions.  


{\ttfamily \#include $<$string.\+h$>$}\\*
{\ttfamily \#include \char`\"{}sphinxbase/sbthread.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}sphinxbase/ckd\+\_\+alloc.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}sphinxbase/err.\+h\char`\"{}}\\*
{\ttfamily \#include $<$pthread.\+h$>$}\\*
{\ttfamily \#include $<$sys/time.\+h$>$}\\*
\subsection*{Data Structures}
\begin{DoxyCompactItemize}
\item 
struct {\bf sbthread\+\_\+s}
\item 
struct {\bf sbmsgq\+\_\+s}
\item 
struct {\bf sbevent\+\_\+s}
\item 
struct {\bf sbmtx\+\_\+s}
\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
{\bf sbthread\+\_\+t} $\ast$ {\bf sbthread\+\_\+start} ({\bf cmd\+\_\+ln\+\_\+t} $\ast$config, {\bf sbthread\+\_\+main} func, void $\ast$arg)\label{sbthread_8c_a0ba06f52feda5c218dc38373e930017c}

\begin{DoxyCompactList}\small\item\em Start a new thread. \end{DoxyCompactList}\item 
int {\bf sbthread\+\_\+wait} ({\bf sbthread\+\_\+t} $\ast$th)\label{sbthread_8c_ad4cc725834be72ea986f80c4f4ecb24d}

\begin{DoxyCompactList}\small\item\em Wait for a thread to complete. \end{DoxyCompactList}\item 
{\bf sbmsgq\+\_\+t} $\ast$ {\bf sbmsgq\+\_\+init} (size\+\_\+t depth)
\begin{DoxyCompactList}\small\item\em Create a message queue. \end{DoxyCompactList}\item 
void {\bf sbmsgq\+\_\+free} ({\bf sbmsgq\+\_\+t} $\ast$msgq)\label{sbthread_8c_aa8483d06a1456207643abcfebc3b2e0a}

\begin{DoxyCompactList}\small\item\em Free a message queue. \end{DoxyCompactList}\item 
int {\bf sbmsgq\+\_\+send} ({\bf sbmsgq\+\_\+t} $\ast$q, size\+\_\+t len, void const $\ast$data)\label{sbthread_8c_ae6c214bf1fab2f10cb51648b7e736698}

\begin{DoxyCompactList}\small\item\em Post a message to a queue. \end{DoxyCompactList}\item 
void $\ast$ {\bf sbmsgq\+\_\+wait} ({\bf sbmsgq\+\_\+t} $\ast$q, size\+\_\+t $\ast$out\+\_\+len, int sec, int nsec)\label{sbthread_8c_a5ef0a82190db1efc97e5921d2f822535}

\begin{DoxyCompactList}\small\item\em Wait for a message from a queue. \end{DoxyCompactList}\item 
{\bf sbevent\+\_\+t} $\ast$ {\bf sbevent\+\_\+init} (void)\label{sbthread_8c_ad6f018be06301acbfd2b41888ca1d345}

\begin{DoxyCompactList}\small\item\em Initialize an event. \end{DoxyCompactList}\item 
void {\bf sbevent\+\_\+free} ({\bf sbevent\+\_\+t} $\ast$evt)\label{sbthread_8c_abba6d18d863334a98eecbaf5ffe81ab1}

\begin{DoxyCompactList}\small\item\em Free an event. \end{DoxyCompactList}\item 
int {\bf sbevent\+\_\+signal} ({\bf sbevent\+\_\+t} $\ast$evt)\label{sbthread_8c_a89f88d25e27146dc7e4956211e69a6d5}

\begin{DoxyCompactList}\small\item\em Signal an event. \end{DoxyCompactList}\item 
int {\bf sbevent\+\_\+wait} ({\bf sbevent\+\_\+t} $\ast$evt, int sec, int nsec)\label{sbthread_8c_a9f48001ca75395a3b192902b37edd5e0}

\begin{DoxyCompactList}\small\item\em Wait for an event to be signalled. \end{DoxyCompactList}\item 
{\bf sbmtx\+\_\+t} $\ast$ {\bf sbmtx\+\_\+init} (void)\label{sbthread_8c_a690fb21b06b7ef9f958a4a204bc04269}

\begin{DoxyCompactList}\small\item\em Create a mutex. \end{DoxyCompactList}\item 
int {\bf sbmtx\+\_\+trylock} ({\bf sbmtx\+\_\+t} $\ast$mtx)\label{sbthread_8c_aaca10c92363d8979100c8fddeb783f9a}

\begin{DoxyCompactList}\small\item\em Try to acquire a mutex. \end{DoxyCompactList}\item 
int {\bf sbmtx\+\_\+lock} ({\bf sbmtx\+\_\+t} $\ast$mtx)\label{sbthread_8c_a000d9d0610c6b91649edde95e3bafa6c}

\begin{DoxyCompactList}\small\item\em Acquire a mutex. \end{DoxyCompactList}\item 
int {\bf sbmtx\+\_\+unlock} ({\bf sbmtx\+\_\+t} $\ast$mtx)\label{sbthread_8c_ab3fdc55976e2b0581e598bd20187ce3a}

\begin{DoxyCompactList}\small\item\em Release a mutex. \end{DoxyCompactList}\item 
void {\bf sbmtx\+\_\+free} ({\bf sbmtx\+\_\+t} $\ast$mtx)\label{sbthread_8c_af1f9eb876ca9fc93d6c548120af14197}

\begin{DoxyCompactList}\small\item\em Dispose of a mutex. \end{DoxyCompactList}\item 
{\bf cmd\+\_\+ln\+\_\+t} $\ast$ {\bf sbthread\+\_\+config} ({\bf sbthread\+\_\+t} $\ast$th)\label{sbthread_8c_a95c25385f31541c412a458deb9ee94e5}

\begin{DoxyCompactList}\small\item\em Get configuration object from a thread. \end{DoxyCompactList}\item 
void $\ast$ {\bf sbthread\+\_\+arg} ({\bf sbthread\+\_\+t} $\ast$th)\label{sbthread_8c_a94e4cf2b756764e453b1469df79b3140}

\begin{DoxyCompactList}\small\item\em Get argument pointer from a thread. \end{DoxyCompactList}\item 
{\bf sbmsgq\+\_\+t} $\ast$ {\bf sbthread\+\_\+msgq} ({\bf sbthread\+\_\+t} $\ast$th)\label{sbthread_8c_af13e76cf03ad458f48f9604ec4731bdc}

\begin{DoxyCompactList}\small\item\em Get message queue from a thread. \end{DoxyCompactList}\item 
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 
void {\bf sbthread\+\_\+free} ({\bf sbthread\+\_\+t} $\ast$th)\label{sbthread_8c_a2b80d955dab72ff602d9048551dc7489}

\begin{DoxyCompactList}\small\item\em Free a thread object. \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.\+c}.



\subsection{Function Documentation}
\index{sbthread.\+c@{sbthread.\+c}!sbmsgq\+\_\+init@{sbmsgq\+\_\+init}}
\index{sbmsgq\+\_\+init@{sbmsgq\+\_\+init}!sbthread.\+c@{sbthread.\+c}}
\subsubsection[{sbmsgq\+\_\+init}]{\setlength{\rightskip}{0pt plus 5cm}{\bf sbmsgq\+\_\+t}$\ast$ sbmsgq\+\_\+init (
\begin{DoxyParamCaption}
\item[{size\+\_\+t}]{depth}
\end{DoxyParamCaption}
)}\label{sbthread_8c_a76852d201655b6f08ed6c35f6ebf8b4b}


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.\+c@{sbthread.\+c}!sbthread\+\_\+send@{sbthread\+\_\+send}}
\index{sbthread\+\_\+send@{sbthread\+\_\+send}!sbthread.\+c@{sbthread.\+c}}
\subsubsection[{sbthread\+\_\+send}]{\setlength{\rightskip}{0pt plus 5cm}int sbthread\+\_\+send (
\begin{DoxyParamCaption}
\item[{{\bf sbthread\+\_\+t} $\ast$}]{th, }
\item[{size\+\_\+t}]{len, }
\item[{void const $\ast$}]{data}
\end{DoxyParamCaption}
)}\label{sbthread_8c_afae533b302b310a828cf2eed1f2f5995}


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

