\hypertarget{locks_8h}{
\section{libthreads/include/locks.h File Reference}
\label{locks_8h}\index{libthreads/include/locks.h@{libthreads/include/locks.h}}
}
\subsection*{Data Structures}
\begin{DoxyCompactItemize}
\item 
struct \hyperlink{structsemaphore__t}{semaphore\_\-t}
\item 
struct \hyperlink{structmutex__t}{mutex\_\-t}
\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{structsemaphore__t}{semaphore\_\-t} \hyperlink{locks_8h_a55a2e672851b1f33c8cb4321b2374333}{semaphores\_\-create} (int count)
\begin{DoxyCompactList}\small\item\em Creates a semaphore. \item\end{DoxyCompactList}\item 
void \hyperlink{locks_8h_aef6a139318c0f56e568397f3bdb06948}{semaphores\_\-lock} (\hyperlink{structsemaphore__t}{semaphore\_\-t} $\ast$s)
\begin{DoxyCompactList}\small\item\em Locks a semaphore. \item\end{DoxyCompactList}\item 
int \hyperlink{locks_8h_a1636a1158a7c69abfbf1852103d89e73}{semaphores\_\-lock\_\-noblock} (\hyperlink{structsemaphore__t}{semaphore\_\-t} $\ast$s)
\begin{DoxyCompactList}\small\item\em Locks a semaphore. \item\end{DoxyCompactList}\item 
void \hyperlink{locks_8h_a95879dba230182cbb6a693ce11c0b3ad}{semaphores\_\-unlock} (\hyperlink{structsemaphore__t}{semaphore\_\-t} $\ast$s)
\begin{DoxyCompactList}\small\item\em Unlocks a semaphore. \item\end{DoxyCompactList}\item 
\hyperlink{structmutex__t}{mutex\_\-t} \hyperlink{locks_8h_aad14d7e621c4c8daef10f5740f3495b3}{mutexes\_\-create} (void)
\begin{DoxyCompactList}\small\item\em Creates a mutex. \item\end{DoxyCompactList}\item 
void \hyperlink{locks_8h_ad4d978fcc9504098f532684728a24a15}{mutexes\_\-lock} (\hyperlink{structmutex__t}{mutex\_\-t} $\ast$m)
\begin{DoxyCompactList}\small\item\em Locks a mutex. \item\end{DoxyCompactList}\item 
int \hyperlink{locks_8h_ac3afe45dcc07faf2087cdaf281e983e7}{mutexes\_\-lock\_\-noblock} (\hyperlink{structmutex__t}{mutex\_\-t} $\ast$m)
\begin{DoxyCompactList}\small\item\em Locks a mutex. \item\end{DoxyCompactList}\item 
void \hyperlink{locks_8h_acac486ef4270e706c8853ad0b3c53039}{mutexes\_\-unlock} (\hyperlink{structmutex__t}{mutex\_\-t} $\ast$m)
\begin{DoxyCompactList}\small\item\em Unlocks a mutex. \item\end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Locking API for libthreads. \begin{Desc}
\item[\hyperlink{todo__todo000005}{Todo}]Semaphores and mutexes should have a queue of threads that are waiting for a lock, then wake one whenever the lock is unlocked. (thanks tueidj) \end{Desc}


\subsection{Function Documentation}
\hypertarget{locks_8h_aad14d7e621c4c8daef10f5740f3495b3}{
\index{locks.h@{locks.h}!mutexes\_\-create@{mutexes\_\-create}}
\index{mutexes\_\-create@{mutexes\_\-create}!locks.h@{locks.h}}
\subsubsection[{mutexes\_\-create}]{\setlength{\rightskip}{0pt plus 5cm}{\bf mutex\_\-t} mutexes\_\-create (void)}}
\label{locks_8h_aad14d7e621c4c8daef10f5740f3495b3}


Creates a mutex. 

\begin{DoxyReturn}{Returns}
A mutex object. 
\end{DoxyReturn}
\hypertarget{locks_8h_ad4d978fcc9504098f532684728a24a15}{
\index{locks.h@{locks.h}!mutexes\_\-lock@{mutexes\_\-lock}}
\index{mutexes\_\-lock@{mutexes\_\-lock}!locks.h@{locks.h}}
\subsubsection[{mutexes\_\-lock}]{\setlength{\rightskip}{0pt plus 5cm}void mutexes\_\-lock ({\bf mutex\_\-t} $\ast$ {\em m})}}
\label{locks_8h_ad4d978fcc9504098f532684728a24a15}


Locks a mutex. 

This call is {\itshape BLOCKING\/}, using sleep mode. Do not use this function inside of an interrupt handler, nor within a \hyperlink{threads_8h_abc896cb1753c100e660ea0853ecdbd95}{threads\_\-freeze()} block. 
\begin{DoxyParams}{Parameters}
\item[{\em m}]a pointer to the mutex to lock. \end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{locks_8h_ac3afe45dcc07faf2087cdaf281e983e7}{mutexes\_\-lock\_\-noblock()}, \hyperlink{locks_8h_acac486ef4270e706c8853ad0b3c53039}{mutexes\_\-unlock()} 
\end{DoxySeeAlso}
\hypertarget{locks_8h_ac3afe45dcc07faf2087cdaf281e983e7}{
\index{locks.h@{locks.h}!mutexes\_\-lock\_\-noblock@{mutexes\_\-lock\_\-noblock}}
\index{mutexes\_\-lock\_\-noblock@{mutexes\_\-lock\_\-noblock}!locks.h@{locks.h}}
\subsubsection[{mutexes\_\-lock\_\-noblock}]{\setlength{\rightskip}{0pt plus 5cm}int mutexes\_\-lock\_\-noblock ({\bf mutex\_\-t} $\ast$ {\em m})}}
\label{locks_8h_ac3afe45dcc07faf2087cdaf281e983e7}


Locks a mutex. 

This call is nonblocking, thus it is safe to use within an interrupt handler or a \hyperlink{threads_8h_abc896cb1753c100e660ea0853ecdbd95}{threads\_\-freeze()} block. It will return no matter whether it succeeded or failed. 
\begin{DoxyParams}{Parameters}
\item[{\em m}]a pointer to the mutex to lock. \end{DoxyParams}
\begin{DoxyReturn}{Returns}
1 if the mutex was able to be locked, 0 if it was not. 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{locks_8h_ad4d978fcc9504098f532684728a24a15}{mutexes\_\-lock()}, \hyperlink{locks_8h_acac486ef4270e706c8853ad0b3c53039}{mutexes\_\-unlock()} 
\end{DoxySeeAlso}
\hypertarget{locks_8h_acac486ef4270e706c8853ad0b3c53039}{
\index{locks.h@{locks.h}!mutexes\_\-unlock@{mutexes\_\-unlock}}
\index{mutexes\_\-unlock@{mutexes\_\-unlock}!locks.h@{locks.h}}
\subsubsection[{mutexes\_\-unlock}]{\setlength{\rightskip}{0pt plus 5cm}void mutexes\_\-unlock ({\bf mutex\_\-t} $\ast$ {\em m})}}
\label{locks_8h_acac486ef4270e706c8853ad0b3c53039}


Unlocks a mutex. 


\begin{DoxyParams}{Parameters}
\item[{\em m}]a pointer to the mutex to unlock. \end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{locks_8h_ac3afe45dcc07faf2087cdaf281e983e7}{mutexes\_\-lock\_\-noblock()}, \hyperlink{locks_8h_ad4d978fcc9504098f532684728a24a15}{mutexes\_\-lock()} 
\end{DoxySeeAlso}
\hypertarget{locks_8h_a55a2e672851b1f33c8cb4321b2374333}{
\index{locks.h@{locks.h}!semaphores\_\-create@{semaphores\_\-create}}
\index{semaphores\_\-create@{semaphores\_\-create}!locks.h@{locks.h}}
\subsubsection[{semaphores\_\-create}]{\setlength{\rightskip}{0pt plus 5cm}{\bf semaphore\_\-t} semaphores\_\-create (int {\em count})}}
\label{locks_8h_a55a2e672851b1f33c8cb4321b2374333}


Creates a semaphore. 


\begin{DoxyParams}{Parameters}
\item[{\em count}]how many locks the semaphore may take before waiting. \end{DoxyParams}
\begin{DoxyReturn}{Returns}
A semaphore object with the requested specification. 
\end{DoxyReturn}
\hypertarget{locks_8h_aef6a139318c0f56e568397f3bdb06948}{
\index{locks.h@{locks.h}!semaphores\_\-lock@{semaphores\_\-lock}}
\index{semaphores\_\-lock@{semaphores\_\-lock}!locks.h@{locks.h}}
\subsubsection[{semaphores\_\-lock}]{\setlength{\rightskip}{0pt plus 5cm}void semaphores\_\-lock ({\bf semaphore\_\-t} $\ast$ {\em s})}}
\label{locks_8h_aef6a139318c0f56e568397f3bdb06948}


Locks a semaphore. 

This call is {\itshape BLOCKING\/}, using sleep mode. Do not use this function inside of an interrupt handler, nor within a \hyperlink{threads_8h_abc896cb1753c100e660ea0853ecdbd95}{threads\_\-freeze()} block. 
\begin{DoxyParams}{Parameters}
\item[{\em s}]a pointer to the semaphore to lock. \end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{locks_8h_a1636a1158a7c69abfbf1852103d89e73}{semaphores\_\-lock\_\-noblock()}, \hyperlink{locks_8h_a95879dba230182cbb6a693ce11c0b3ad}{semaphores\_\-unlock()} 
\end{DoxySeeAlso}
\hypertarget{locks_8h_a1636a1158a7c69abfbf1852103d89e73}{
\index{locks.h@{locks.h}!semaphores\_\-lock\_\-noblock@{semaphores\_\-lock\_\-noblock}}
\index{semaphores\_\-lock\_\-noblock@{semaphores\_\-lock\_\-noblock}!locks.h@{locks.h}}
\subsubsection[{semaphores\_\-lock\_\-noblock}]{\setlength{\rightskip}{0pt plus 5cm}int semaphores\_\-lock\_\-noblock ({\bf semaphore\_\-t} $\ast$ {\em s})}}
\label{locks_8h_a1636a1158a7c69abfbf1852103d89e73}


Locks a semaphore. 

This call is nonblocking, thus it is safe to use within an interrupt handler or a \hyperlink{threads_8h_abc896cb1753c100e660ea0853ecdbd95}{threads\_\-freeze()} block. It will return no matter whether it succeeded or failed. 
\begin{DoxyParams}{Parameters}
\item[{\em s}]a pointer to the semaphore to lock. \end{DoxyParams}
\begin{DoxyReturn}{Returns}
1 if the semaphore was able to be locked, 0 if it was not. 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{locks_8h_aef6a139318c0f56e568397f3bdb06948}{semaphores\_\-lock()}, \hyperlink{locks_8h_a95879dba230182cbb6a693ce11c0b3ad}{semaphores\_\-unlock()} 
\end{DoxySeeAlso}
\hypertarget{locks_8h_a95879dba230182cbb6a693ce11c0b3ad}{
\index{locks.h@{locks.h}!semaphores\_\-unlock@{semaphores\_\-unlock}}
\index{semaphores\_\-unlock@{semaphores\_\-unlock}!locks.h@{locks.h}}
\subsubsection[{semaphores\_\-unlock}]{\setlength{\rightskip}{0pt plus 5cm}void semaphores\_\-unlock ({\bf semaphore\_\-t} $\ast$ {\em s})}}
\label{locks_8h_a95879dba230182cbb6a693ce11c0b3ad}


Unlocks a semaphore. 

Unlocks a semaphore by a single level. 
\begin{DoxyParams}{Parameters}
\item[{\em s}]a pointer to the semaphore to unlock. \end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{locks_8h_a1636a1158a7c69abfbf1852103d89e73}{semaphores\_\-lock\_\-noblock()}, \hyperlink{locks_8h_aef6a139318c0f56e568397f3bdb06948}{semaphores\_\-lock()} 
\end{DoxySeeAlso}
