\hypertarget{FPA_8c}{
\section{FPA.c File Reference}
\label{FPA_8c}\index{FPA.c@{FPA.c}}
}
Utility for configuring and allocating a pool of Fixed Sized Packets. 

{\tt \#include \char`\"{}IPBS/FPA.h\char`\"{}}\par
{\tt \#include \char`\"{}IPBS/LI.h\char`\"{}}\par
{\tt \#include \char`\"{}IPBS/LI.ih\char`\"{}}\par


Include dependency graph for FPA.c:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=356pt]{FPA_8c__incl}
\end{center}
\end{figure}
\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct \hyperlink{struct__FPA__fcb}{\_\-FPA\_\-fcb}
\begin{CompactList}\small\item\em Layouts the control structure for managing the list of free packets. This structure is private to the FPA utility. \item\end{CompactList}\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
static \_\-\_\-inline \hyperlink{struct__FPA__pcb}{FPA\_\-pcb} $\ast$ \hyperlink{FPA_8c_a0}{allocate} (\hyperlink{struct__FPA__fcb}{FPA\_\-fcb} $\ast$fcb, int offset)
\begin{CompactList}\small\item\em Basic non-interlocked version of the routine to allocate a packet from the free list. \item\end{CompactList}\item 
int \hyperlink{FPA_8c_a1}{FPA\_\-fcb\_\-sizeof} ()
\begin{CompactList}\small\item\em Returns the size of the Fixed Packet Allocator control block. \item\end{CompactList}\item 
int \hyperlink{FPA_8c_a2}{FPA\_\-init} (\hyperlink{struct__FPA__fcb}{FPA\_\-fcb} $\ast$fcb, \hyperlink{FPA_8h_a1}{FPA\_\-type} type, void $\ast$buffer, int buf\_\-size, int packet\_\-size, int pcb\_\-offset, \hyperlink{FPA_8h_a3}{FPA\_\-init\_\-cb} init\_\-routine, void $\ast$init\_\-parameter)
\begin{CompactList}\small\item\em Configures a user supplied piece of memory as a collection of fixed size packets which can be allocated and deallocated. \item\end{CompactList}\item 
int \hyperlink{FPA_8c_a3}{FPA\_\-destroy} (\hyperlink{struct__FPA__fcb}{FPA\_\-fcb} $\ast$fcb)
\begin{CompactList}\small\item\em Releases any resources gathered at initialization time. \item\end{CompactList}\item 
void \_\-\_\-inline $\ast$ \hyperlink{FPA_8c_a4}{FPA\_\-get} (\hyperlink{struct__FPA__fcb}{FPA\_\-fcb} $\ast$fcb)
\begin{CompactList}\small\item\em Get or allocate a packet from the free list. \item\end{CompactList}\item 
void $\ast$ \hyperlink{FPA_8c_a5}{FPA\_\-get\-W} (\hyperlink{struct__FPA__fcb}{FPA\_\-fcb} $\ast$fcb)
\begin{CompactList}\small\item\em Get or allocate a packet from the free list with a indefinite blocking. \item\end{CompactList}\item 
void $\ast$ \hyperlink{FPA_8c_a6}{FPA\_\-get\-W\_\-toc} (\hyperlink{struct__FPA__fcb}{FPA\_\-fcb} $\ast$fcb, const \hyperlink{struct__TOC}{TOC} $\ast$toc)
\begin{CompactList}\small\item\em Get or allocate a packet from the free list using the timeout specified by TOC. \item\end{CompactList}\item 
int \hyperlink{FPA_8c_a7}{FPA\_\-free} (\hyperlink{struct__FPA__fcb}{FPA\_\-fcb} $\ast$fcb, void $\ast$packet)
\begin{CompactList}\small\item\em Returns a previously allocated packet to the free list. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Utility for configuring and allocating a pool of Fixed Sized Packets. 

\begin{Desc}
\item[Author:]JJRussell - \href{mailto:russell@slac.stanford.edu}{\tt russell@slac.stanford.edu}\end{Desc}


\footnotesize\begin{verbatim}   CVS $Id: FPA.c,v 1.1.1.1 2006/02/10 21:45:33 saxton Exp $
   
\end{verbatim}
\normalsize


\subsection{Function Documentation}
\hypertarget{FPA_8c_a0}{
\index{FPA.c@{FPA.c}!allocate@{allocate}}
\index{allocate@{allocate}!FPA.c@{FPA.c}}
\subsubsection[allocate]{\setlength{\rightskip}{0pt plus 5cm}\hyperlink{struct__FPA__pcb}{FPA\_\-pcb} $\ast$ allocate (\hyperlink{struct__FPA__fcb}{FPA\_\-fcb} $\ast$ {\em fcb}, int {\em offset})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{FPA_8c_a0}


Basic non-interlocked version of the routine to allocate a packet from the free list. 

\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em NULL,on}]failure (empty free list) \item[{\em Pointer}]to the allocated packet, on success\end{description}
\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em fcb}]The FPA handle \item[{\em offset}]Byte offset from the node links to the top of the packet.\end{description}
\end{Desc}
\hypertarget{FPA_8c_a3}{
\index{FPA.c@{FPA.c}!FPA_destroy@{FPA\_\-destroy}}
\index{FPA_destroy@{FPA\_\-destroy}!FPA.c@{FPA.c}}
\subsubsection[FPA\_\-destroy]{\setlength{\rightskip}{0pt plus 5cm}int FPA\_\-destroy (\hyperlink{struct__FPA__fcb}{FPA\_\-fcb} $\ast$ {\em fcb})}}
\label{FPA_8c_a3}


Releases any resources gathered at initialization time. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em fcb}]The handle of the Fixed Packet Allocator \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]Status\end{Desc}
Releases any resources gathered at initialization time. Note that this does not include either releasing the user supplied memory buffer or the control structure itself. Both of those are property of the user and are the responsibility of the user to release them as appropriate.\hypertarget{FPA_8c_a1}{
\index{FPA.c@{FPA.c}!FPA_fcb_sizeof@{FPA\_\-fcb\_\-sizeof}}
\index{FPA_fcb_sizeof@{FPA\_\-fcb\_\-sizeof}!FPA.c@{FPA.c}}
\subsubsection[FPA\_\-fcb\_\-sizeof]{\setlength{\rightskip}{0pt plus 5cm}int FPA\_\-fcb\_\-sizeof (void)}}
\label{FPA_8c_a1}


Returns the size of the Fixed Packet Allocator control block. 

\begin{Desc}
\item[Returns:]The size, in bytes of a Fixed Packet Allocator control block.\end{Desc}
This routine is the first step in creating a FPA pool. The user first enquires about the size of the control block and then allocates it either from existing piece of memory or from some other allocator like {\em \hyperlink{MBA_8h_a3}{MBA\_\-alloc()}\/}.

This call is for modularity reasons. The user can learn the size of memory needed by the FPA utility to manage a pool of packets without needing to know the details of how it is laid out. This could have also been achieved by having the FPA initialization routine allocate the control block, but this takes away the freedom of the user to control his own allocation and deallocation\hypertarget{FPA_8c_a7}{
\index{FPA.c@{FPA.c}!FPA_free@{FPA\_\-free}}
\index{FPA_free@{FPA\_\-free}!FPA.c@{FPA.c}}
\subsubsection[FPA\_\-free]{\setlength{\rightskip}{0pt plus 5cm}int FPA\_\-free (\hyperlink{struct__FPA__fcb}{FPA\_\-fcb} $\ast$ {\em fcb}, void $\ast$ {\em packet})}}
\label{FPA_8c_a7}


Returns a previously allocated packet to the free list. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em fcb}]The handle of the Fixed Packet Allocator. \item[{\em packet}]The packet to be freed. \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The number of outstanding packets\end{Desc}
This routine frees, or returns a previously allocated packet to the free list.\hypertarget{FPA_8c_a4}{
\index{FPA.c@{FPA.c}!FPA_get@{FPA\_\-get}}
\index{FPA_get@{FPA\_\-get}!FPA.c@{FPA.c}}
\subsubsection[FPA\_\-get]{\setlength{\rightskip}{0pt plus 5cm}void \_\-\_\-inline$\ast$ FPA\_\-get (\hyperlink{struct__FPA__fcb}{FPA\_\-fcb} $\ast$ {\em fcb})}}
\label{FPA_8c_a4}


Get or allocate a packet from the free list. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em fcb}]The handle of the Fixed Packet Allocator \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]If successful, the address of the allocated packet, else NULL if no packets where available.\end{Desc}
This is a non-blocking allocation. See \hyperlink{FPA_8h_a15}{FPA\_\-get\-W()} for a blocking version. While this call is non-blocking, the allocation is fully interlocked.\hypertarget{FPA_8c_a5}{
\index{FPA.c@{FPA.c}!FPA_getW@{FPA\_\-getW}}
\index{FPA_getW@{FPA\_\-getW}!FPA.c@{FPA.c}}
\subsubsection[FPA\_\-getW]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ FPA\_\-get\-W (\hyperlink{struct__FPA__fcb}{FPA\_\-fcb} $\ast$ {\em fcb})}}
\label{FPA_8c_a5}


Get or allocate a packet from the free list with a indefinite blocking. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em fcb}]The handle of the Fixed Packet Allocator \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]If successful, the address of the allocated packet. NULL is returned on error.\end{Desc}
This is a blocking allocation, ie if the pool is exhausted, then the routine blocks indefinitely.\hypertarget{FPA_8c_a6}{
\index{FPA.c@{FPA.c}!FPA_getW_toc@{FPA\_\-getW\_\-toc}}
\index{FPA_getW_toc@{FPA\_\-getW\_\-toc}!FPA.c@{FPA.c}}
\subsubsection[FPA\_\-getW\_\-toc]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ FPA\_\-get\-W\_\-toc (\hyperlink{struct__FPA__fcb}{FPA\_\-fcb} $\ast$ {\em fcb}, const \hyperlink{struct__TOC}{TOC} $\ast$ {\em toc})}}
\label{FPA_8c_a6}


Get or allocate a packet from the free list using the timeout specified by TOC. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em fcb}]The handle of the Fixed Packet Allocator. \item[{\em toc}]The timeout control structute. \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]If successful, the address of the allocated packet. NULL is returned on error or timeout.\end{Desc}
This is a blocking allocation, ie if the pool is exhausted, then the routine blocks until a packet becomes available or the timeout period expires.\hypertarget{FPA_8c_a2}{
\index{FPA.c@{FPA.c}!FPA_init@{FPA\_\-init}}
\index{FPA_init@{FPA\_\-init}!FPA.c@{FPA.c}}
\subsubsection[FPA\_\-init]{\setlength{\rightskip}{0pt plus 5cm}int FPA\_\-init (\hyperlink{struct__FPA__fcb}{FPA\_\-fcb} $\ast$ {\em fcb}, \hyperlink{FPA_8h_a1}{FPA\_\-type} {\em type}, void $\ast$ {\em buffer}, int {\em buf\_\-size}, int {\em packet\_\-size}, int {\em pcb\_\-offset}, \hyperlink{FPA_8h_a3}{FPA\_\-init\_\-cb} {\em init\_\-routine}, void $\ast$ {\em init\_\-parameter})}}
\label{FPA_8c_a2}


Configures a user supplied piece of memory as a collection of fixed size packets which can be allocated and deallocated. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em fcb}]The handle of the Fixed Packet Allocator to be initialized. The user is responsible for supplying the memory for the control structure.\item[{\em type}]The type of blocking to be used\item[{\em buffer}]A pointer to the user-supplied buffer. This buffer must be 32-bit aligned. The packets will be carved from this memory.\item[{\em buf\_\-size}]The size, in bytes, of the user-supplied buffer.\item[{\em packet\_\-size}]The size, in bytes, of the packets. This number must be an integral number of 32-bit words. This ensures that all packets will be properly aligned.\item[{\em pcb\_\-offset}]Offset, in bytes, to the packet control block. This block is necessary for managing the packet while it is on in the free pool, but is free for the user to do with as he wishes when once the packet has been allocated. This parameter allows the user to control the placement of the control block. This offset is generally specified as 0, in which case the control structure is at the top of the packet, or -1, in which case the links are at the bottom of the packet. The latter case is especially useful if one wishes to initialize the top portion of the packet with a static header of some sort, while the bottom of the packet contains data to be filled in later when the packet is allocated.\item[{\em init\_\-routine}]The address of the entry point of a user supplied routine which is called as each new packet is placed on the free list. This parameter may be NULL if no initialization routine is needed. It is the user's responsibility not so use the control area. This is possible, since the user knows the size and controls its placement in the packet. Set FPA\_\-init\_\-cb for the definition of the callback signature.\item[{\em init\_\-parameter}]A user supplied parameter which is passed to the callback routine.\end{description}
\end{Desc}
This routine is responsible for configuring a user-supplied piece of memory for use as a source of fixed sized packets. As each packet is placed on the free list, an optionally supplied user callback routine allows user initialization of the packets.

Various options allow the user to place where the control structure lives within the packet and determine the blocking style. The most usual choice for the placement of the packet control structure is at the beginning {\em pcb\_\-offset\/} = 0, or at the end {\em pcb\_\-offset\/} = -1, although the user is allowed to specify any offset, provided it is within the packet. The usual blocking style is FPA\_\-K\_\-TYPE\_\-FIFO\_\-BLOCKING.

\begin{Desc}
\item[Warning:]Note that while this Packet Control Block offset {\em pcb\_\-offset\/} is specified in bytes it {\em must\/} {\em be\/} 4 byte aligned.\end{Desc}
