\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$>$}\newline
{\ttfamily \#include \char`\"{}sphinxbase/sbthread.\+h\char`\"{}}\newline
{\ttfamily \#include \char`\"{}sphinxbase/ckd\+\_\+alloc.\+h\char`\"{}}\newline
{\ttfamily \#include \char`\"{}sphinxbase/err.\+h\char`\"{}}\newline
{\ttfamily \#include $<$pthread.\+h$>$}\newline
{\ttfamily \#include $<$sys/time.\+h$>$}\newline
\subsection*{Data Structures}
\begin{DoxyCompactItemize}
\item 
struct \textbf{ sbthread\+\_\+s}
\item 
struct \textbf{ sbmsgq\+\_\+s}
\item 
struct \textbf{ sbevent\+\_\+s}
\item 
struct \textbf{ sbmtx\+\_\+s}
\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
\mbox{\label{sbthread_8c_a0ba06f52feda5c218dc38373e930017c}} 
\textbf{ sbthread\+\_\+t} $\ast$ \textbf{ sbthread\+\_\+start} (\textbf{ cmd\+\_\+ln\+\_\+t} $\ast$config, \textbf{ sbthread\+\_\+main} func, void $\ast$arg)
\begin{DoxyCompactList}\small\item\em Start a new thread. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_ad4cc725834be72ea986f80c4f4ecb24d}} 
int \textbf{ sbthread\+\_\+wait} (\textbf{ sbthread\+\_\+t} $\ast$th)
\begin{DoxyCompactList}\small\item\em Wait for a thread to complete. \end{DoxyCompactList}\item 
\textbf{ sbmsgq\+\_\+t} $\ast$ \textbf{ sbmsgq\+\_\+init} (size\+\_\+t depth)
\begin{DoxyCompactList}\small\item\em Create a message queue. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_aa8483d06a1456207643abcfebc3b2e0a}} 
void \textbf{ sbmsgq\+\_\+free} (\textbf{ sbmsgq\+\_\+t} $\ast$msgq)
\begin{DoxyCompactList}\small\item\em Free a message queue. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_ae6c214bf1fab2f10cb51648b7e736698}} 
int \textbf{ sbmsgq\+\_\+send} (\textbf{ sbmsgq\+\_\+t} $\ast$q, size\+\_\+t len, void const $\ast$data)
\begin{DoxyCompactList}\small\item\em Post a message to a queue. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_a5ef0a82190db1efc97e5921d2f822535}} 
void $\ast$ \textbf{ sbmsgq\+\_\+wait} (\textbf{ sbmsgq\+\_\+t} $\ast$q, size\+\_\+t $\ast$out\+\_\+len, int sec, int nsec)
\begin{DoxyCompactList}\small\item\em Wait for a message from a queue. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_ad6f018be06301acbfd2b41888ca1d345}} 
\textbf{ sbevent\+\_\+t} $\ast$ \textbf{ sbevent\+\_\+init} (void)
\begin{DoxyCompactList}\small\item\em Initialize an event. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_abba6d18d863334a98eecbaf5ffe81ab1}} 
void \textbf{ sbevent\+\_\+free} (\textbf{ sbevent\+\_\+t} $\ast$evt)
\begin{DoxyCompactList}\small\item\em Free an event. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_a89f88d25e27146dc7e4956211e69a6d5}} 
int \textbf{ sbevent\+\_\+signal} (\textbf{ sbevent\+\_\+t} $\ast$evt)
\begin{DoxyCompactList}\small\item\em Signal an event. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_a9f48001ca75395a3b192902b37edd5e0}} 
int \textbf{ sbevent\+\_\+wait} (\textbf{ sbevent\+\_\+t} $\ast$evt, int sec, int nsec)
\begin{DoxyCompactList}\small\item\em Wait for an event to be signalled. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_a690fb21b06b7ef9f958a4a204bc04269}} 
\textbf{ sbmtx\+\_\+t} $\ast$ \textbf{ sbmtx\+\_\+init} (void)
\begin{DoxyCompactList}\small\item\em Create a mutex. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_aaca10c92363d8979100c8fddeb783f9a}} 
int \textbf{ sbmtx\+\_\+trylock} (\textbf{ sbmtx\+\_\+t} $\ast$mtx)
\begin{DoxyCompactList}\small\item\em Try to acquire a mutex. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_a000d9d0610c6b91649edde95e3bafa6c}} 
int \textbf{ sbmtx\+\_\+lock} (\textbf{ sbmtx\+\_\+t} $\ast$mtx)
\begin{DoxyCompactList}\small\item\em Acquire a mutex. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_ab3fdc55976e2b0581e598bd20187ce3a}} 
int \textbf{ sbmtx\+\_\+unlock} (\textbf{ sbmtx\+\_\+t} $\ast$mtx)
\begin{DoxyCompactList}\small\item\em Release a mutex. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_af1f9eb876ca9fc93d6c548120af14197}} 
void \textbf{ sbmtx\+\_\+free} (\textbf{ sbmtx\+\_\+t} $\ast$mtx)
\begin{DoxyCompactList}\small\item\em Dispose of a mutex. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_a95c25385f31541c412a458deb9ee94e5}} 
\textbf{ cmd\+\_\+ln\+\_\+t} $\ast$ \textbf{ sbthread\+\_\+config} (\textbf{ sbthread\+\_\+t} $\ast$th)
\begin{DoxyCompactList}\small\item\em Get configuration object from a thread. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_a94e4cf2b756764e453b1469df79b3140}} 
void $\ast$ \textbf{ sbthread\+\_\+arg} (\textbf{ sbthread\+\_\+t} $\ast$th)
\begin{DoxyCompactList}\small\item\em Get argument pointer from a thread. \end{DoxyCompactList}\item 
\mbox{\label{sbthread_8c_af13e76cf03ad458f48f9604ec4731bdc}} 
\textbf{ sbmsgq\+\_\+t} $\ast$ \textbf{ sbthread\+\_\+msgq} (\textbf{ sbthread\+\_\+t} $\ast$th)
\begin{DoxyCompactList}\small\item\em Get message queue from a thread. \end{DoxyCompactList}\item 
int \textbf{ sbthread\+\_\+send} (\textbf{ 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 
\mbox{\label{sbthread_8c_a2b80d955dab72ff602d9048551dc7489}} 
void \textbf{ sbthread\+\_\+free} (\textbf{ sbthread\+\_\+t} $\ast$th)
\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}


\subsection{Function Documentation}
\mbox{\label{sbthread_8c_a76852d201655b6f08ed6c35f6ebf8b4b}} 
\index{sbthread.\+c@{sbthread.\+c}!sbmsgq\+\_\+init@{sbmsgq\+\_\+init}}
\index{sbmsgq\+\_\+init@{sbmsgq\+\_\+init}!sbthread.\+c@{sbthread.\+c}}
\subsubsection{sbmsgq\+\_\+init()}
{\footnotesize\ttfamily \textbf{ sbmsgq\+\_\+t}$\ast$ sbmsgq\+\_\+init (\begin{DoxyParamCaption}\item[{size\+\_\+t}]{depth }\end{DoxyParamCaption})}



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.



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

\mbox{\label{sbthread_8c_afae533b302b310a828cf2eed1f2f5995}} 
\index{sbthread.\+c@{sbthread.\+c}!sbthread\+\_\+send@{sbthread\+\_\+send}}
\index{sbthread\+\_\+send@{sbthread\+\_\+send}!sbthread.\+c@{sbthread.\+c}}
\subsubsection{sbthread\+\_\+send()}
{\footnotesize\ttfamily int sbthread\+\_\+send (\begin{DoxyParamCaption}\item[{\textbf{ sbthread\+\_\+t} $\ast$}]{th,  }\item[{size\+\_\+t}]{len,  }\item[{void const $\ast$}]{data }\end{DoxyParamCaption})}



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

