\hypertarget{RNG_8h}{
\section{RNG.h File Reference}
\label{RNG_8h}\index{RNG.h@{RNG.h}}
}
Ring Bufffer memory manager, configures and manages a pool of memory as a ring buffer.  


{\tt \#include $<$IPBS/RW\_\-type.h$>$}\par
{\tt \#include $<$IPBS/TOC\_\-comdefs.h$>$}\par
{\tt \#include $<$IPBS/TOV.h$>$}\par
\subsection*{Classes}
\begin{CompactItemize}
\item 
struct \hyperlink{struct__RNG__dsc}{\_\-RNG\_\-dsc}
\begin{CompactList}\small\item\em This describes all the static properties of the ring buffer. \item\end{CompactList}\end{CompactItemize}
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define \hyperlink{RNG_8h_ea52453c05a2187ecfad198c569662ba}{RNG\_\-K\_\-PTR\_\-ERROR}~(1)
\begin{CompactList}\small\item\em Returned by either the \hyperlink{RNG_8c_7eb9d93dacebca57597fd7d5ae13b89b}{RNG\_\-get()} or RNG\_\-grab routines when an internal error is detected. \item\end{CompactList}\item 
\#define \hyperlink{RNG_8h_7941ca836c2b4c51d41674256696bf80}{RNG\_\-PTR\_\-IS\_\-VALID}(ptr)~( (unsigned int)ptr  $>$ RNG\_\-K\_\-PTR\_\-ERROR)
\begin{CompactList}\small\item\em Checks that the returned pointer is valid. \item\end{CompactList}\item 
\#define \hyperlink{RNG_8h_22f3f9e0204323f000fcd4747efb03dc}{RNG\_\-PTR\_\-IS\_\-ERROR}(ptr)~( (unsigned int)ptr == RNG\_\-K\_\-PTR\_\-ERROR)
\begin{CompactList}\small\item\em Checks if the pointer is indicates failure to allocate because of an error. \item\end{CompactList}\end{CompactItemize}
\subsection*{Typedefs}
\begin{CompactItemize}
\item 
typedef enum \hyperlink{RNG_8h_2e18c7b27fb832276a7c6d62e58a28d7}{\_\-RNG\_\-type} \hyperlink{RNG_8h_52116d0d178137dce5c244108e7137de}{RNG\_\-type}
\begin{CompactList}\small\item\em Typedef for enum {\em \_\-RNG\_\-type\/}. \item\end{CompactList}\item 
typedef struct \hyperlink{struct__RNG__dsc}{\_\-RNG\_\-dsc} \hyperlink{RNG_8h_4b2fa2295a8453181e9fcc118ff7c3cc}{RNG\_\-dsc}
\begin{CompactList}\small\item\em Typedef for struct {\em \hyperlink{struct__RNG__dsc}{\_\-RNG\_\-dsc}\/}. \item\end{CompactList}\end{CompactItemize}
\subsection*{Enumerations}
\begin{CompactItemize}
\item 
enum \hyperlink{RNG_8h_2e18c7b27fb832276a7c6d62e58a28d7}{\_\-RNG\_\-type} \{ \par
\hyperlink{RNG_8h_2e18c7b27fb832276a7c6d62e58a28d796e4c7eab12250cd42d9cca1501e2e59}{RNG\_\-K\_\-TYPE\_\-LOCKING\_\-ONLY} =  RW\_\-K\_\-TYPE\_\-LOCKING\_\-ONLY, 
\par
\hyperlink{RNG_8h_2e18c7b27fb832276a7c6d62e58a28d7cf6f2dd417c269dc951df81107d55895}{RNG\_\-K\_\-TYPE\_\-PENDING} =  RW\_\-K\_\-TYPE\_\-PENDING, 
\par
\hyperlink{RNG_8h_2e18c7b27fb832276a7c6d62e58a28d79155fd2cff69479d487237cd3c658bcf}{RNG\_\-K\_\-TYPE\_\-PENDING\_\-WTO} =  RW\_\-K\_\-TYPE\_\-PENDING\_\-WTO
 \}
\begin{CompactList}\small\item\em An enumeration of the types of ring buffers that can be created. \item\end{CompactList}\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
const \hyperlink{struct__RNG__dsc}{RNG\_\-dsc} $\ast$ \hyperlink{RNG_8h_5e5f9a19fdb00058690af2e77a64d3f8}{RNG\_\-dsc\_\-get} (const \hyperlink{struct__RNG__rcb}{RNG\_\-rcb} $\ast$rcb)
\begin{CompactList}\small\item\em Query routine to return a pointer to the ring buffer description structure. \item\end{CompactList}\item 
int \hyperlink{RNG_8h_c80e4f1211c6b5088206f17ca5def911}{RNG\_\-sizeof\_\-rcb} (void)
\begin{CompactList}\small\item\em Returns the size of the Ring Contol Block. \item\end{CompactList}\item 
int \hyperlink{RNG_8h_0ed0848baae9c884b9d2106b25677b91}{RNG\_\-init} (\hyperlink{struct__RNG__rcb}{RNG\_\-rcb} $\ast$rcb, \hyperlink{RNG_8h_52116d0d178137dce5c244108e7137de}{RNG\_\-type} type, void $\ast$buffer, int size, int underflow, int overflow, int alignment)
\begin{CompactList}\small\item\em Initializes the control structure for a Ring buffer. \item\end{CompactList}\item 
int \hyperlink{RNG_8h_86977c6d750a56f00a5703ecd19a0dce}{RNG\_\-destroy} (\hyperlink{struct__RNG__rcb}{RNG\_\-rcb} $\ast$rcb)
\begin{CompactList}\small\item\em Returns any resources associated with this ring buffer. \item\end{CompactList}\item 
void $\ast$ \hyperlink{RNG_8h_5d3a8a1fd09ff8ece10f4ee4e4efc204}{RNG\_\-get} (\hyperlink{struct__RNG__rcb}{RNG\_\-rcb} $\ast$rcb, int request, const void $\ast$write)
\begin{CompactList}\small\item\em Non-blocking allocation request for a specified amount of memory. \item\end{CompactList}\item 
void $\ast$ \hyperlink{RNG_8h_ea2a72a8219a2f62cc5db0e7d771714e}{RNG\_\-getW} (\hyperlink{struct__RNG__rcb}{RNG\_\-rcb} $\ast$rcb, int request, const void $\ast$write)
\begin{CompactList}\small\item\em Blocking allocation request for a specified amount of memory. \item\end{CompactList}\item 
void $\ast$ \hyperlink{RNG_8h_1240143f58e4d1a5860cc205f5afdc1b}{RNG\_\-getW\_\-toc} (\hyperlink{struct__RNG__rcb}{RNG\_\-rcb} $\ast$rcb, int request, const void $\ast$check\_\-Wr, const \hyperlink{struct__TOC}{TOC} $\ast$toc)
\begin{CompactList}\small\item\em Blocking allocation request for a specified amount of memory, with timeout. \item\end{CompactList}\item 
void $\ast$ \hyperlink{RNG_8h_f82a9b40f9aea1b8c8a92947f2f16792}{RNG\_\-grab} (\hyperlink{struct__RNG__rcb}{RNG\_\-rcb} $\ast$rcb, int minimum, const void $\ast$write, int $\ast$allocated)
\begin{CompactList}\small\item\em Non-blocking allocation request for all the remaining contigious memory, {\em i.e\/}. a greedy form of {\em RNG\_\-get\/}. \item\end{CompactList}\item 
void $\ast$ \hyperlink{RNG_8h_227850f72e2441e7f6f288b38b19cc66}{RNG\_\-grabW} (\hyperlink{struct__RNG__rcb}{RNG\_\-rcb} $\ast$rcb, int minimum, const void $\ast$write, int $\ast$allocated)
\begin{CompactList}\small\item\em Blocking allocation request for all the remaining contigious memory, {\em i.e\/}. a greedy form of {\em RNG\_\-getW\/}. \item\end{CompactList}\item 
void $\ast$ \hyperlink{RNG_8h_bb0821bfe11ba895c676aff79b5299fb}{RNG\_\-grabW\_\-toc} (\hyperlink{struct__RNG__rcb}{RNG\_\-rcb} $\ast$rcb, int minimum, const void $\ast$check\_\-wr, int $\ast$allocated, const \hyperlink{struct__TOC}{TOC} $\ast$toc)
\begin{CompactList}\small\item\em Blocking allocation request for all the remaining contigious memory with a timeout, {\em i.e\/}. a greedy form of {\em RNG\_\-getWtos\/}. \item\end{CompactList}\item 
int \hyperlink{RNG_8h_1e10c3bd68ac6512304315a2bd4b77ef}{RNG\_\-free} (\hyperlink{struct__RNG__rcb}{RNG\_\-rcb} $\ast$rcb, const void $\ast$packet, int amount)
\begin{CompactList}\small\item\em Frees the requested amount of memory from the specified address. \item\end{CompactList}\item 
void $\ast$ \hyperlink{RNG_8h_e7fbc0f5c2db158c283ad5abaa3db779}{RNG\_\-shrink} (\hyperlink{struct__RNG__rcb}{RNG\_\-rcb} $\ast$rcb, const void $\ast$write, int left)
\begin{CompactList}\small\item\em Shrinks the previously allocated packet back to the specified address. \item\end{CompactList}\item 
int \hyperlink{RNG_8h_32df1742166e2e9e1f8bbeb538ad4cf4}{RNG\_\-reset} (\hyperlink{struct__RNG__rcb}{RNG\_\-rcb} $\ast$rcb)
\begin{CompactList}\small\item\em If the ring buffer is empty, reset the read and write pointers to their initial positions. This can only be called if the user knows that the buffer is empty. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Ring Bufffer memory manager, configures and manages a pool of memory as a ring buffer. 

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


\footnotesize\begin{verbatim}
  
   CVS $Id: RNG.h,v 1.2 2011/03/25 21:15:01 saxton Exp $
\end{verbatim}
\normalsize


{\bf SYNOPSIS} \par
 Implements a set of routines for managing a {\bf single} {\bf writer} / {\bf single} {\bf reader} ring buffer. The routines are thread and interrupt level safe, although one should {\em not\/} use the blocking forms \hyperlink{RNG_8c_bf8cf1a5f370ad7c82ead0ea80bc0c1a}{RNG\_\-getW()} and \hyperlink{RNG_8c_7e0f196d11838c419ee4532e559928d0}{RNG\_\-grabW()} nor any of their timeout variations in interrupt routines. While nothing in the code prohibits multiple writers and readers, using a ring buffer in this fashion runs is not natural. Ring buffers are really just a software implementation of a FIFO, which, by its nature, is a single writer, single reader object. 

\subsection{Define Documentation}
\hypertarget{RNG_8h_ea52453c05a2187ecfad198c569662ba}{
\index{RNG.h@{RNG.h}!RNG\_\-K\_\-PTR\_\-ERROR@{RNG\_\-K\_\-PTR\_\-ERROR}}
\index{RNG\_\-K\_\-PTR\_\-ERROR@{RNG\_\-K\_\-PTR\_\-ERROR}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-K\_\-PTR\_\-ERROR}]{\setlength{\rightskip}{0pt plus 5cm}\#define RNG\_\-K\_\-PTR\_\-ERROR~(1)}}
\label{RNG_8h_ea52453c05a2187ecfad198c569662ba}


Returned by either the \hyperlink{RNG_8c_7eb9d93dacebca57597fd7d5ae13b89b}{RNG\_\-get()} or RNG\_\-grab routines when an internal error is detected. 

\begin{Desc}
\item[Warning:]The caller should not use this value directly, rather the macros RNG\_\-GET\_\-IS\_\-VALID(ptr) and RNG\_\-GET\_\-IS\_\-ERROR(ptr) should be used. \end{Desc}


Referenced by rng\_\-allocate().\hypertarget{RNG_8h_22f3f9e0204323f000fcd4747efb03dc}{
\index{RNG.h@{RNG.h}!RNG\_\-PTR\_\-IS\_\-ERROR@{RNG\_\-PTR\_\-IS\_\-ERROR}}
\index{RNG\_\-PTR\_\-IS\_\-ERROR@{RNG\_\-PTR\_\-IS\_\-ERROR}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-PTR\_\-IS\_\-ERROR}]{\setlength{\rightskip}{0pt plus 5cm}\#define RNG\_\-PTR\_\-IS\_\-ERROR(ptr)~( (unsigned int)ptr == RNG\_\-K\_\-PTR\_\-ERROR)}}
\label{RNG_8h_22f3f9e0204323f000fcd4747efb03dc}


Checks if the pointer is indicates failure to allocate because of an error. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ptr}]The pointer to check \end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0,the}]pointer is not an error condition pointer \item[{\em 1,the}]pointer is an error condition pointer\end{description}
\end{Desc}
This macro checks if the pointer is an error condition pointer. Currently there is only one error condition pointer. This occurs when the next allocation pointer, as provided by the user does not match the expected value. Note that a NULL pointer means what it has always traditionally meant, {\em i.e\/}. out of memory \hypertarget{RNG_8h_7941ca836c2b4c51d41674256696bf80}{
\index{RNG.h@{RNG.h}!RNG\_\-PTR\_\-IS\_\-VALID@{RNG\_\-PTR\_\-IS\_\-VALID}}
\index{RNG\_\-PTR\_\-IS\_\-VALID@{RNG\_\-PTR\_\-IS\_\-VALID}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-PTR\_\-IS\_\-VALID}]{\setlength{\rightskip}{0pt plus 5cm}\#define RNG\_\-PTR\_\-IS\_\-VALID(ptr)~( (unsigned int)ptr  $>$ RNG\_\-K\_\-PTR\_\-ERROR)}}
\label{RNG_8h_7941ca836c2b4c51d41674256696bf80}


Checks that the returned pointer is valid. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ptr}]The pointer to check \end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0,if}]the pointer is invalid \item[{\em 1,if}]the pointer is valid\end{description}
\end{Desc}
The returned pointer from the \hyperlink{RNG_8c_7eb9d93dacebca57597fd7d5ae13b89b}{RNG\_\-get()} or \hyperlink{RNG_8c_1edd1a81b197bcb2ffef13a3c28ba008}{RNG\_\-grab()} routines can be invalid for two general reasons.

\begin{itemize}
\item No memory\item Internal inconsistancy\end{itemize}


This macro checks that the pointer is not one of these values. This attempts to address the age old problem of how to indicate an error condition without resorting to an additional parameter for a status value. 

\subsection{Typedef Documentation}
\hypertarget{RNG_8h_4b2fa2295a8453181e9fcc118ff7c3cc}{
\index{RNG.h@{RNG.h}!RNG\_\-dsc@{RNG\_\-dsc}}
\index{RNG\_\-dsc@{RNG\_\-dsc}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-dsc}]{\setlength{\rightskip}{0pt plus 5cm}{\bf RNG\_\-dsc}}}
\label{RNG_8h_4b2fa2295a8453181e9fcc118ff7c3cc}


Typedef for struct {\em \hyperlink{struct__RNG__dsc}{\_\-RNG\_\-dsc}\/}. 

This structure describes all the static properties of the ring buffer.

The ring buffer composed of three pieces carved out of a user provided block of memory. The three pieces are



\footnotesize\begin{verbatim}
     Underflow area
     Main pool
     Overflow area
  \end{verbatim}
\normalsize


Picturally the ring buffer looks like



\footnotesize\begin{verbatim}

      +---------------+  beg
      |               |
      |   Underflow   |
      |               |
      +---------------+ rbeg
      |               |
      |   Main        |
      |   Ring        |
      |   Buffer      |
      |               |
      +---------------+ rend
      |               |
      |   Underflow   |
      |               |
      +---------------+  end
      
  \end{verbatim}
\normalsize


As is common practice, the pointers to the beginning of the areas point at the real beginning and the pointers to the ending of the areas point one past the actual last address so that sizes are trivially calculated.

As a convenience the address of the initial buffer, its size and the requested ring buffer type are also kept in this structure. This may be useful to the user when he later attempts to free this memory.

Note that due to alignment rounding the initial buffer address and size may not match the ring buffer's beginning address and size. \hypertarget{RNG_8h_52116d0d178137dce5c244108e7137de}{
\index{RNG.h@{RNG.h}!RNG\_\-type@{RNG\_\-type}}
\index{RNG\_\-type@{RNG\_\-type}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-type}]{\setlength{\rightskip}{0pt plus 5cm}{\bf RNG\_\-type}}}
\label{RNG_8h_52116d0d178137dce5c244108e7137de}


Typedef for enum {\em \_\-RNG\_\-type\/}. 

This determines how the ring allocators, \hyperlink{RNG_8c_bf8cf1a5f370ad7c82ead0ea80bc0c1a}{RNG\_\-getW()} and \hyperlink{RNG_8c_7e0f196d11838c419ee4532e559928d0}{RNG\_\-grabW()}, calls will behave when an allocation is attempted on an empty pool. One can specify non-blocking or blocking and with and without timeouts.

Note that there is no choice as to the blocking types as one sees in the LLI facility. This is because the blocking type affects only the behavior when multiple tasks are being blocked. Given the single writer / single reader nature of the ring buffer, the issue what to do when multiple tasking are pending never comes up.

If a non-blocking type is requested, common practice would be to use the simpler {\em \hyperlink{RNG_8c_7eb9d93dacebca57597fd7d5ae13b89b}{RNG\_\-get()}\/} routine, since it never waits. The {\em RNG\_\-getWxxx\/} and {\em RNG\_\-grabWxxx\/} should not be used in this case, although their behavior is currently defined to degenerate to the {\em RNG\_\-get\/} and {\em RNG\_\-grab\/}, respectively. 

\subsection{Enumeration Type Documentation}
\hypertarget{RNG_8h_2e18c7b27fb832276a7c6d62e58a28d7}{
\index{RNG.h@{RNG.h}!\_\-RNG\_\-type@{\_\-RNG\_\-type}}
\index{\_\-RNG\_\-type@{\_\-RNG\_\-type}!RNG.h@{RNG.h}}
\subsubsection[{\_\-RNG\_\-type}]{\setlength{\rightskip}{0pt plus 5cm}enum {\bf \_\-RNG\_\-type}}}
\label{RNG_8h_2e18c7b27fb832276a7c6d62e58a28d7}


An enumeration of the types of ring buffers that can be created. 

\begin{Desc}
\item[Enumerator: ]\par
\begin{description}
\index{RNG\_\-K\_\-TYPE\_\-LOCKING\_\-ONLY@{RNG\_\-K\_\-TYPE\_\-LOCKING\_\-ONLY}!RNG.h@{RNG.h}}\index{RNG.h@{RNG.h}!RNG\_\-K\_\-TYPE\_\-LOCKING\_\-ONLY@{RNG\_\-K\_\-TYPE\_\-LOCKING\_\-ONLY}}\item[{\em 
\hypertarget{RNG_8h_2e18c7b27fb832276a7c6d62e58a28d796e4c7eab12250cd42d9cca1501e2e59}{
RNG\_\-K\_\-TYPE\_\-LOCKING\_\-ONLY}
\label{RNG_8h_2e18c7b27fb832276a7c6d62e58a28d796e4c7eab12250cd42d9cca1501e2e59}
}]Locking mechanism only, no blocking mechanism available \index{RNG\_\-K\_\-TYPE\_\-PENDING@{RNG\_\-K\_\-TYPE\_\-PENDING}!RNG.h@{RNG.h}}\index{RNG.h@{RNG.h}!RNG\_\-K\_\-TYPE\_\-PENDING@{RNG\_\-K\_\-TYPE\_\-PENDING}}\item[{\em 
\hypertarget{RNG_8h_2e18c7b27fb832276a7c6d62e58a28d7cf6f2dd417c269dc951df81107d55895}{
RNG\_\-K\_\-TYPE\_\-PENDING}
\label{RNG_8h_2e18c7b27fb832276a7c6d62e58a28d7cf6f2dd417c269dc951df81107d55895}
}]Enable blocking when the pool is exhausted \index{RNG\_\-K\_\-TYPE\_\-PENDING\_\-WTO@{RNG\_\-K\_\-TYPE\_\-PENDING\_\-WTO}!RNG.h@{RNG.h}}\index{RNG.h@{RNG.h}!RNG\_\-K\_\-TYPE\_\-PENDING\_\-WTO@{RNG\_\-K\_\-TYPE\_\-PENDING\_\-WTO}}\item[{\em 
\hypertarget{RNG_8h_2e18c7b27fb832276a7c6d62e58a28d79155fd2cff69479d487237cd3c658bcf}{
RNG\_\-K\_\-TYPE\_\-PENDING\_\-WTO}
\label{RNG_8h_2e18c7b27fb832276a7c6d62e58a28d79155fd2cff69479d487237cd3c658bcf}
}]Enable blocking with timeouts when the pool is exhausted, \end{description}
\end{Desc}



\subsection{Function Documentation}
\hypertarget{RNG_8h_86977c6d750a56f00a5703ecd19a0dce}{
\index{RNG.h@{RNG.h}!RNG\_\-destroy@{RNG\_\-destroy}}
\index{RNG\_\-destroy@{RNG\_\-destroy}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-destroy}]{\setlength{\rightskip}{0pt plus 5cm}int RNG\_\-destroy ({\bf RNG\_\-rcb} $\ast$ {\em rcb})}}
\label{RNG_8h_86977c6d750a56f00a5703ecd19a0dce}


Returns any resources associated with this ring buffer. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em rcb}]The Ring Control Block \end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em Status}]Frees any internally gathered resources associated with the specified ring buffer. The {\em rcb\/} is no longer usable as ring buffer after this call.\end{description}
\end{Desc}
\begin{Desc}
\item[Warning:]It is the user's responsibility to dispose of the memory associated with the buffer that was being managed and the memory containing the Ring Control Block. \end{Desc}


References \_\-RNG\_\-rcb::rw, and RW\_\-destroy().\hypertarget{RNG_8h_5e5f9a19fdb00058690af2e77a64d3f8}{
\index{RNG.h@{RNG.h}!RNG\_\-dsc\_\-get@{RNG\_\-dsc\_\-get}}
\index{RNG\_\-dsc\_\-get@{RNG\_\-dsc\_\-get}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-dsc\_\-get}]{\setlength{\rightskip}{0pt plus 5cm}const {\bf RNG\_\-dsc}$\ast$ RNG\_\-dsc\_\-get (const {\bf RNG\_\-rcb} $\ast$ {\em rcb})}}
\label{RNG_8h_5e5f9a19fdb00058690af2e77a64d3f8}


Query routine to return a pointer to the ring buffer description structure. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em rcb}]The ring control block \end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em A}]pointer to ring buffer description\end{description}
\end{Desc}
Returns a pointer to the ring buffer description structure. This structure contains all the static information about the ring buffer. Because these properties are static, the user may cache a pointer to this structure or the value of any of its elements. They will not change from the time the ring buffer is initialized until it is destroyed.

Here is a overview of the elements and there use.

{\em beg\/} This a pointer to the top of the underflow portion of the buffer. If if there is no underflow area, this will be the same as {\em rbeg\/}. Because of alignment reason, this pointer may or may not agree with the original buffer pointer passed in by the user.

{\em rbeg\/} Pointer to the top of the ring buffer proper.

{\em rend\/} Pointer to the bottom of the ring buffer proper. Also, by definition, the start of the overflow area.

{\em end\/} Pointer to the bottom of the overflow area.

{\em msk\/} The alignment mask, for shorts = 1, ints = 3, long long = 7

{\em buf\/} The original buffer pointer passed into RCB\_\-init by the user. This routine along with {\em bufsize\/} allows the user to recover the original address and size of the pool of memory the RNG utilities where requested to manage. This may be useful when closing the ring buffer, allowing the user to return the managed memory to where ever it came from.

{\em bufsize\/} The size of the original buffer 

References \_\-RNG\_\-rcb::dsc.\hypertarget{RNG_8h_1e10c3bd68ac6512304315a2bd4b77ef}{
\index{RNG.h@{RNG.h}!RNG\_\-free@{RNG\_\-free}}
\index{RNG\_\-free@{RNG\_\-free}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-free}]{\setlength{\rightskip}{0pt plus 5cm}int RNG\_\-free ({\bf RNG\_\-rcb} $\ast$ {\em rcb}, \/  const void $\ast$ {\em packet}, \/  int {\em amount})}}
\label{RNG_8h_1e10c3bd68ac6512304315a2bd4b77ef}


Frees the requested amount of memory from the specified address. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em rcb}]The Ring Control Block \item[{\em packet}]The pointer where the free begins \item[{\em amount}]The amount of memory to free \end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]Successful \item[{\em -1}]Packet being freed is not contigous with the previous packet being freed \item[{\em -2}]Packet being freed extended into the shard area. Since this area is owned by the ring buffer and cannot belong to the user, this is a user specification error.\end{description}
\end{Desc}
Frees the requested {\em amount\/} of memory beginning at {\em ptr\/}. Note that, unlike many other allocators, RNG\_\-free allows partial freeing. One is not obligated to match allocations and deallocations. The only restriction is that the free {\em ptr\/} must be consistent with the next location to be freed by the Ring Buffer utilities, and that one frees only that which is allocated.

If fails, the current read pointer is returned. The only practical reason for failing is that the packet being freed is does not match the current read pointer. Currently there is no sanity check to prevent the user from freeing more memory than is actually allocated. That is fairly expensive and, the thought is, if one does this, the next free is going to fail. This is a little dicey, but see how this works. If it doesn't will add the proper sanity check.

There is one case where overfreeing is detected, that is when the packet being freed extends into the user area. As compared with detecting an arbritary overfree, this one is relatively cheap, so it is done. 

References \_\-RNG\_\-dsc::beg, \_\-RNG\_\-rcb::dsc, \_\-RNG\_\-rcb::dyn, \_\-RNG\_\-dsc::end, \_\-RNG\_\-dsc::msk, \_\-RNG\_\-dyn::que, \_\-RNG\_\-dyn::rd, \_\-RNG\_\-dyn::rdx, \_\-RNG\_\-dsc::rend, ROUND\_\-TO, \_\-RNG\_\-rcb::rw, RW\_\-\_\-wake(), \_\-RNG\_\-rcb::size, and \_\-RNG\_\-dyn::wr.\hypertarget{RNG_8h_5d3a8a1fd09ff8ece10f4ee4e4efc204}{
\index{RNG.h@{RNG.h}!RNG\_\-get@{RNG\_\-get}}
\index{RNG\_\-get@{RNG\_\-get}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-get}]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ RNG\_\-get ({\bf RNG\_\-rcb} $\ast$ {\em rcb}, \/  int {\em request}, \/  const void $\ast$ {\em write})}}
\label{RNG_8h_5d3a8a1fd09ff8ece10f4ee4e4efc204}


Non-blocking allocation request for a specified amount of memory. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em rcb}]The Ring Control Block\item[{\em request}]The size of the request, in bytes.\item[{\em write}]The end of the previously allocated block. Given the loose nature of ring buffers, this is used as an integrity check. If one is feeling brave, this may be specified as NULL. Doing this will skip the integrity checking.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]If successful, a pointer to the allocated memory, else NULL.\end{Desc}
Attempts to allocate the requested amount of memory. If insufficient memory is available or the {\em write\/} pointer is inconsistent with the internal write pointer, NULL is returned. The user can distinguish these two cases by calling {\em RNG\_\-wr()\/}, to fetch the current value of the write pointer. The user may also live dangerously and specify NULL for the {\em write\/} argument, in which case the consistency check is bypassed. No check is made to see if the request is for more memory than can ever be satisfied.

\begin{Desc}
\item[Special Cases]If the request is for 0 bytes, the next write pointer is returned. This allows the user to refresh where in the buffer the next write will come from. Alternatively, the user can use this value to check his own prejudice on the value of the next write pointer.\end{Desc}
\begin{Desc}
\item[Note:]Remember, this is used as an integrity check. In some cases, the value of the returned write pointer will not match this value because of the wrap-around nature of ring buffers. Effectively all values of the write pointer past the end of the ring buffer proper must be remapped to the beginning of the ring buffer. Maybe a better way to thing of the {\em write\/} pointer is as the value at the end of the last allocation. It only so happens that a large fraction of the time this value is also the value of returned by the next get. \end{Desc}


References \_\-RNG\_\-rcb::dyn, rng\_\-allocate(), TOC\_\-NOWAIT, and \_\-RNG\_\-dyn::wrx.\hypertarget{RNG_8h_ea2a72a8219a2f62cc5db0e7d771714e}{
\index{RNG.h@{RNG.h}!RNG\_\-getW@{RNG\_\-getW}}
\index{RNG\_\-getW@{RNG\_\-getW}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-getW}]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ RNG\_\-getW ({\bf RNG\_\-rcb} $\ast$ {\em rcb}, \/  int {\em request}, \/  const void $\ast$ {\em write})}}
\label{RNG_8h_ea2a72a8219a2f62cc5db0e7d771714e}


Blocking allocation request for a specified amount of memory. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em rcb}]The Ring Control Block\item[{\em request}]The size of the request, in bytes.\item[{\em write}]The end of the previously allocated block. Given the loose nature of ring buffers, this is used as an integrity check. If one is feeling brave, this may be specified as NULL. Doing this will skip the integrity checking.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]If successful, a pointer to the allocated memory, else NULL.\end{Desc}
Attempts to allocate the requested amount of memory. If insufficient memory is available {\em RNG\_\-getW\/} blocks until the requested amount is available. No check is made to see if the request is for more memory than can every be satisfied.

If the {\em write\/} pointer is inconsistent with the internal write pointer, NULL is returned. The user can distinguish these two cases by calling {\em RNG\_\-wr()\/}, to fetch the current value of the write pointer. The user may also live dangerously and specify NULL for the {\em write\/} argument, in which case the consistency check is bypassed. 

References \_\-RNG\_\-rcb::dyn, rng\_\-allocate(), TOC\_\-FOREVER, and \_\-RNG\_\-dyn::wrx.\hypertarget{RNG_8h_1240143f58e4d1a5860cc205f5afdc1b}{
\index{RNG.h@{RNG.h}!RNG\_\-getW\_\-toc@{RNG\_\-getW\_\-toc}}
\index{RNG\_\-getW\_\-toc@{RNG\_\-getW\_\-toc}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-getW\_\-toc}]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ RNG\_\-getW\_\-toc ({\bf RNG\_\-rcb} $\ast$ {\em rcb}, \/  int {\em request}, \/  const void $\ast$ {\em write}, \/  const {\bf TOC} $\ast$ {\em toc})}}
\label{RNG_8h_1240143f58e4d1a5860cc205f5afdc1b}


Blocking allocation request for a specified amount of memory, with timeout. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em rcb}]The Ring Control Block\item[{\em request}]The size of the request, in bytes\item[{\em write}]The end of the previously allocated block. Given the loose nature of ring buffers, this is used as an integrity check. If one is feeling brave, this may be specified as NULL. Doing this will skip the integrity checking.\item[{\em toc}]The timeout control structure. This specifies the timeout value. TOC\_\-NOWAIT and TOC\_\-FOREVER may be specified here, although in this case the user should consider using {\em RNG\_\-get\/} or {\em RNG\_\-getW\/}.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]If successful, a pointer to the allocated memory, else NULL.\end{Desc}
Attempts to allocate the requested amount of memory. If insufficient memory is available {\em RNG\_\-getW\/} blocks until the requested amount is available or until the timeout period has expired. No check is made to see if the request is for more memory than can every be satisfied.

If the {\em write\/} pointer is inconsistent with the internal write pointer, NULL is returned. The user can distinguish these two cases by calling {\em RNG\_\-wr()\/}, to fetch the current value of the write pointer. The user may also live dangerously and specify NULL for the {\em write\/} argument, in which case the consistency check is bypassed. 

References \_\-RNG\_\-rcb::dyn, rng\_\-allocate(), and \_\-RNG\_\-dyn::wrx.\hypertarget{RNG_8h_f82a9b40f9aea1b8c8a92947f2f16792}{
\index{RNG.h@{RNG.h}!RNG\_\-grab@{RNG\_\-grab}}
\index{RNG\_\-grab@{RNG\_\-grab}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-grab}]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ RNG\_\-grab ({\bf RNG\_\-rcb} $\ast$ {\em rcb}, \/  int {\em minimum}, \/  const void $\ast$ {\em write}, \/  int $\ast$ {\em allocated})}}
\label{RNG_8h_f82a9b40f9aea1b8c8a92947f2f16792}


Non-blocking allocation request for all the remaining contigious memory, {\em i.e\/}. a greedy form of {\em RNG\_\-get\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em rcb}]The Ring Control Block\item[{\em minimum}]The minimum size requested, in bytes.\item[{\em write}]The end of the previously allocated block. Given the loose nature of ring buffers, this is used as an integrity check. If one is feeling brave, this may be specified as NULL. Doing this will skip the integrity checking.\item[{\em allocated}]Pointer to receive the actual amount, in bytes, that was allocated.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]If successful, a pointer to the allocated memory, else NULL.\end{Desc}
This is a greedy form of allocation. All the contigious memory from the current write pointer on is allocated to the caller provided this amount is larger than the minimum requested. This allows the user to continually fill memory even if does not know at allocation time how much is needed. This routine is often used with \hyperlink{RNG_8c_39c87c1e5d89e1412a8fc0e4856a035b}{RNG\_\-shrink()}. Here one allocates as much as one can with RNG\_\-grab, uses what he wants, then returns the unused portion by calling \hyperlink{RNG_8c_39c87c1e5d89e1412a8fc0e4856a035b}{RNG\_\-shrink()}.

If there is less than the minimum amount of memory in the pool, NULL is returned. 

References rng\_\-allocate(), and TOC\_\-NOWAIT.\hypertarget{RNG_8h_227850f72e2441e7f6f288b38b19cc66}{
\index{RNG.h@{RNG.h}!RNG\_\-grabW@{RNG\_\-grabW}}
\index{RNG\_\-grabW@{RNG\_\-grabW}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-grabW}]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ RNG\_\-grabW ({\bf RNG\_\-rcb} $\ast$ {\em rcb}, \/  int {\em minimum}, \/  const void $\ast$ {\em write}, \/  int $\ast$ {\em allocated})}}
\label{RNG_8h_227850f72e2441e7f6f288b38b19cc66}


Blocking allocation request for all the remaining contigious memory, {\em i.e\/}. a greedy form of {\em RNG\_\-getW\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em rcb}]The Ring Control Block\item[{\em minimum}]The minimum size requested, in bytes.\item[{\em write}]The end of the previously allocated block. Given the loose nature of ring buffers, this is used as an integrity check. If one is feeling brave, this may be specified as NULL. Doing this will skip the integrity checking.\item[{\em allocated}]Pointer to receive the actual amount, in bytes, that was allocated.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]If successful, a pointer to the allocated memory, else NULL.\end{Desc}
This is a greedy form of allocation. All the contigious memory from the current write pointer on is allocated to the caller provided this amount is larger than the minimum requested. This allows the user to continually fill memory even if does not know at allocation time how much is needed. This routine is often used with \hyperlink{RNG_8c_39c87c1e5d89e1412a8fc0e4856a035b}{RNG\_\-shrink()}. Here one allocates as much as one can with RNG\_\-grab, uses what he wants, then returns the unused portion by calling \hyperlink{RNG_8c_39c87c1e5d89e1412a8fc0e4856a035b}{RNG\_\-shrink()}.

If there is less than the minimum amount of memory in the pool, {\em RNG\_\-grabW\/} waits until the memory shows up. NULL is only on an internal error. 

References rng\_\-allocate(), and TOC\_\-FOREVER.\hypertarget{RNG_8h_bb0821bfe11ba895c676aff79b5299fb}{
\index{RNG.h@{RNG.h}!RNG\_\-grabW\_\-toc@{RNG\_\-grabW\_\-toc}}
\index{RNG\_\-grabW\_\-toc@{RNG\_\-grabW\_\-toc}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-grabW\_\-toc}]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ RNG\_\-grabW\_\-toc ({\bf RNG\_\-rcb} $\ast$ {\em rcb}, \/  int {\em minimum}, \/  const void $\ast$ {\em write}, \/  int $\ast$ {\em allocated}, \/  const {\bf TOC} $\ast$ {\em toc})}}
\label{RNG_8h_bb0821bfe11ba895c676aff79b5299fb}


Blocking allocation request for all the remaining contigious memory with a timeout, {\em i.e\/}. a greedy form of {\em RNG\_\-getWtos\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em rcb}]The Ring Control Block\item[{\em minimum}]The minimum size of the request, in bytes.\item[{\em write}]The end of the previously allocated block. Given the loose nature of ring buffers, this is used as an integrity check. If one is feeling brave, this may be specified as NULL. Doing this will skip the integrity checking.\item[{\em allocated}]Returned as the amount of memory actually allocated.\item[{\em toc}]The timeout control structure. This specifies the timeout value. TOC\_\-NOWAIT and TOC\_\-FOREVER may be specified here, although in this case the user should consider using {\em RNG\_\-grab\/} or {\em RNG\_\-grabW\/}.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]If successful, a pointer to the allocated memory, else NULL.\end{Desc}
Attempts to allocate the requested amount of memory. If insufficient memory is available {\em RNG\_\-grabW\/} blocks until the requested amount is available or until the timeout period has expired. No check is made to see if the request is for more memory than can every be satisfied.

If the {\em write\/} pointer is inconsistent with the internal write pointer, NULL is returned. The user can distinguish these two cases by calling {\em RNG\_\-wr()\/}, to fetch the current value of the write pointer. The user may also live dangerously and specify NULL for the {\em write\/} argument, in which case the consistency check is bypassed. 

References rng\_\-allocate().\hypertarget{RNG_8h_0ed0848baae9c884b9d2106b25677b91}{
\index{RNG.h@{RNG.h}!RNG\_\-init@{RNG\_\-init}}
\index{RNG\_\-init@{RNG\_\-init}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-init}]{\setlength{\rightskip}{0pt plus 5cm}int RNG\_\-init ({\bf RNG\_\-rcb} $\ast$ {\em rcb}, \/  {\bf RNG\_\-type} {\em type}, \/  void $\ast$ {\em buffer}, \/  int {\em size}, \/  int {\em underflow}, \/  int {\em overflow}, \/  int {\em alignment})}}
\label{RNG_8h_0ed0848baae9c884b9d2106b25677b91}


Initializes the control structure for a Ring buffer. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em rcb}]Pointer to the ring buffer control block structure to be initialized.\item[{\em type}]Indicates the type of ring buffer. This mainly controls the blocking. If insufficient memory is available, the allocation calls will block until it becomes available or a timeout occurs.\item[{\em buffer}]The buffer to be managed\item[{\em size}]The total size of the buffer (in bytes) to be managed\item[{\em underflow}]The size (in bytes) to be assigned to the underflow area. This area is an area immediately preceeding the ring buffer area.\end{description}
\end{Desc}
\begin{Desc}
\item[Warning:]Currently this feature is not implemented and should be specified as 0. It is provided for forward compatibility.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em overflow}]The size (in bytes) to be assigned to the overflow area. This area carved from the end {\em buf\/}. The useful property of the overflow area is that while memory may be allocated from the overflow area, an initial allocation never begins in the overflow area. This allows some continuity when the wrap-around point of the ring buffer is encountered.\end{description}
\end{Desc}
This number may be 0, but must be less than the total size since it taken from the total size.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em alignment}]The byte alignment, expressed in binary powers of 2, eg\begin{itemize}
\item 0 =$>$ 1 byte alignment\item 1 =$>$ 2 byte alignment\item 2 =$>$ 4 byte alignment\item 3 =$>$ 8 byte alignment\end{itemize}
\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em Status}]Initializes a Ring Control Block to manage a pool of memory. The memory is carved into three pieces, an underflow area, a ring buffer area, and an overflow area. The detailed use and meaning of these areas is described elsewhere. \end{description}
\end{Desc}


References \_\-RNG\_\-dsc::beg, \_\-RNG\_\-dsc::buf, \_\-RNG\_\-dsc::bufsize, \_\-RNG\_\-rcb::dsc, \_\-RNG\_\-rcb::dyn, \_\-RNG\_\-dsc::end, \_\-RNG\_\-dsc::msk, \_\-RNG\_\-dyn::que, \_\-RNG\_\-dsc::rbeg, \_\-RNG\_\-dyn::rd, \_\-RNG\_\-dyn::rdx, \_\-RNG\_\-dsc::rend, ROUND\_\-TO, \_\-RNG\_\-rcb::rw, RW\_\-init(), \_\-RNG\_\-rcb::size, \_\-RNG\_\-dsc::type, \_\-RNG\_\-dyn::wr, and \_\-RNG\_\-dyn::wrx.\hypertarget{RNG_8h_32df1742166e2e9e1f8bbeb538ad4cf4}{
\index{RNG.h@{RNG.h}!RNG\_\-reset@{RNG\_\-reset}}
\index{RNG\_\-reset@{RNG\_\-reset}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-reset}]{\setlength{\rightskip}{0pt plus 5cm}int RNG\_\-reset ({\bf RNG\_\-rcb} $\ast$ {\em rcb})}}
\label{RNG_8h_32df1742166e2e9e1f8bbeb538ad4cf4}


If the ring buffer is empty, reset the read and write pointers to their initial positions. This can only be called if the user knows that the buffer is empty. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em rcb}]The Ring Control Block\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]If 0 is successful else ERROR (-1). The only plausible error is that a reset was requested on a buffer that was not empty.\end{Desc}
Unlike many allocators a Ring Buffer has many states that correspond to the empty state. Consider the initial state, the read pointer is at the bottom of the buffer and the write pointer is at the top. After on allocation the read pointer is at the top of the buffer and the write pointer is at the end of the allocated buffer. If the buffer is now freed, the read pointer advances to the write pointer. The ring buffer is now totally empty, however, it is a different {\em empty\/} state than the original {\em empty\/} state. One consequence of this is that a request on the original state could be as large as the entire ring buffer and succeed. However, the same request on the second empty state would fail. This is because the largest contigious block availabe is from the current write pointer to the end of the buffer. Since the write pointer is not at the top of the buffer, this contigious block is necessarily smaller.

So, one may ask, why not just reset the pointers to the empty state any time the ring buffer is totally empty. The answer is that this destroys any history that the ring buffer may accumulate. Imagine the case where one allocates some memory and then immediately frees it. The current implementation would deliver a different memory block each time. In a debugging mode, one could go back and examine this memory for some clues. If the buffer pointers where to be continually reset, this the memory would always be allocated from the top of the pool, and this debugging feature would be lost.

One possible alternative would be to make this resetting a optional configuration parameter on the ring buffer initialization. That way this would happen automatically. 

References \_\-RNG\_\-dsc::beg, \_\-RNG\_\-rcb::dsc, \_\-RNG\_\-rcb::dyn, \_\-RNG\_\-dsc::end, \_\-RNG\_\-dyn::rd, \_\-RNG\_\-dyn::rdx, \_\-RNG\_\-rcb::size, \_\-RNG\_\-dyn::wr, and \_\-RNG\_\-dyn::wrx.\hypertarget{RNG_8h_e7fbc0f5c2db158c283ad5abaa3db779}{
\index{RNG.h@{RNG.h}!RNG\_\-shrink@{RNG\_\-shrink}}
\index{RNG\_\-shrink@{RNG\_\-shrink}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-shrink}]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ RNG\_\-shrink ({\bf RNG\_\-rcb} $\ast$ {\em rcb}, \/  const void $\ast$ {\em write}, \/  int {\em left})}}
\label{RNG_8h_e7fbc0f5c2db158c283ad5abaa3db779}


Shrinks the previously allocated packet back to the specified address. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em rcb}]The Ring Control Block\item[{\em write}]The address to shrink to. The current write pointer, up to alignment factors, is moved to this address.\item[{\em left}]The unused amount, in bytes, of the previously allocated packet. This value + {\em write\/} addresss must match the current write pointer. If not, error. Note that the amount being returned must be consistent with the alignment factors. Concretely stated, if one demands 8-byte alignment, one cannot return in units less than 8-bytes.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]If successful, the next write pointer. Due to alignment reasons, this may or may not be the same as {\em write\/}. If NULL, error.\end{Desc}
Routine shrinks the previously allocated packet back to the specified address. A check is performed to see if this {\em write\/} pointer plus the number of bytes {\em left\/} in the old allocation is consistent with the Ring Buffer Manager's internal write pointer. If not, NULL is returned.

Typically one would allocate a block of memory, and fill it by advancing the pointer returned and decreasing the amount left. After filling the buffer, one would then call RNG\_\-shrink to return the unused portion. The parameters to {\em RNG\_\-shrink\/} will be the address of the next location to be written and the amount left.

Note also that this has no consequences on waking anyone up who may be waiting for memory. By definition, this is a single allocator system. Since, RNG\_\-shrink is really just extension of the allocation process, no one can be waiting.

{\bf EXAMPLE} \par
 {\bf -------} \par




\begin{Code}\begin{verbatim}      amount = 100;
      ptr    = RNG_get (rcb, amount, prv);
      if (ptr == NULL) perror ("No memory\n");

      *ptr++ = 0xdeadbeef;  amount -= 1;
      *ptr++ = 0xabadbabe;  amount -= 1;

      chk    = RNG_shrink (rcb, ptr, amount);
      if (chk == NULL) perror ("Bad shrink\n");
\end{verbatim}
\end{Code}

 

References \_\-RNG\_\-rcb::dsc, \_\-RNG\_\-rcb::dyn, \_\-RNG\_\-dsc::msk, \_\-RNG\_\-dyn::que, \_\-RNG\_\-dyn::rd, \_\-RNG\_\-dsc::rend, \_\-RNG\_\-rcb::size, \_\-RNG\_\-dyn::wr, and \_\-RNG\_\-dyn::wrx.\hypertarget{RNG_8h_c80e4f1211c6b5088206f17ca5def911}{
\index{RNG.h@{RNG.h}!RNG\_\-sizeof\_\-rcb@{RNG\_\-sizeof\_\-rcb}}
\index{RNG\_\-sizeof\_\-rcb@{RNG\_\-sizeof\_\-rcb}!RNG.h@{RNG.h}}
\subsubsection[{RNG\_\-sizeof\_\-rcb}]{\setlength{\rightskip}{0pt plus 5cm}int RNG\_\-sizeof\_\-rcb (void)}}
\label{RNG_8h_c80e4f1211c6b5088206f17ca5def911}


Returns the size of the Ring Contol Block. 

\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em The}]size of a Ring Control Block\end{description}
\end{Desc}
This routine allows the user to allocate or set aside a block of memory to be used as Ring Control Block. It is the first step when initializing a Ring Control buffer. This routine allows the implementation to hide the internal structure of a Ring Control Block, but still allow the user to control its allocation. 