\hypertarget{a00683_source}{}\doxysection{AAX\+\_\+\+CAtomic\+Queue.\+h}
\label{a00683_source}\index{AAX\_CAtomicQueue.h@{AAX\_CAtomicQueue.h}}
\mbox{\hyperlink{a00683}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*================================================================================================*/}}
\DoxyCodeLine{00002\ \textcolor{comment}{/*}}
\DoxyCodeLine{00003\ \textcolor{comment}{\ *\ \ Copyright\ 2015,\ 2023-\/2024\ Avid\ Technology,\ Inc.}}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ \ All\ rights\ reserved.}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ \ This\ file\ is\ part\ of\ the\ Avid\ AAX\ SDK.}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ \ The\ AAX\ SDK\ is\ subject\ to\ commercial\ or\ open-\/source\ licensing.}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00010\ \textcolor{comment}{\ *\ \ By\ using\ the\ AAX\ SDK,\ you\ agree\ to\ the\ terms\ of\ both\ the\ Avid\ AAX\ SDK\ License}}
\DoxyCodeLine{00011\ \textcolor{comment}{\ *\ \ Agreement\ and\ Avid\ Privacy\ Policy.}}
\DoxyCodeLine{00012\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00013\ \textcolor{comment}{\ *\ \ AAX\ SDK\ License:\ https://developer.avid.com/aax}}
\DoxyCodeLine{00014\ \textcolor{comment}{\ *\ \ Privacy\ Policy:\ https://www.avid.com/legal/privacy-\/policy-\/statement}}
\DoxyCodeLine{00015\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00016\ \textcolor{comment}{\ *\ \ Or:\ You\ may\ also\ use\ this\ code\ under\ the\ terms\ of\ the\ GPL\ v3\ (see}}
\DoxyCodeLine{00017\ \textcolor{comment}{\ *\ \ www.gnu.org/licenses).}}
\DoxyCodeLine{00018\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00019\ \textcolor{comment}{\ *\ \ THE\ AAX\ SDK\ IS\ PROVIDED\ "{}AS\ IS"{}\ WITHOUT\ ANY\ WARRANTY,\ AND\ ALL\ WARRANTIES,\ WHETHER}}
\DoxyCodeLine{00020\ \textcolor{comment}{\ *\ \ EXPRESSED\ OR\ IMPLIED,\ INCLUDING\ MERCHANTABILITY\ AND\ FITNESS\ FOR\ PURPOSE,\ ARE}}
\DoxyCodeLine{00021\ \textcolor{comment}{\ *\ \ DISCLAIMED.}}
\DoxyCodeLine{00022\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00023\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00024\ }
\DoxyCodeLine{00031\ \textcolor{comment}{/*================================================================================================*/}}
\DoxyCodeLine{00033\ \textcolor{preprocessor}{\#ifndef\ AAX\_CATOMICQUEUE\_H}}
\DoxyCodeLine{00034\ \textcolor{preprocessor}{\#define\ AAX\_CATOMICQUEUE\_H}}
\DoxyCodeLine{00036\ }
\DoxyCodeLine{00037\ }
\DoxyCodeLine{00038\ \textcolor{comment}{//\ AAX\ Includes}}
\DoxyCodeLine{00039\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{a00491}{AAX\_IPointerQueue.h}}"{}}}
\DoxyCodeLine{00040\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{a00749}{AAX\_Atomic.h}}"{}}}
\DoxyCodeLine{00041\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{a00443}{AAX\_CMutex.h}}"{}}}
\DoxyCodeLine{00042\ }
\DoxyCodeLine{00043\ \textcolor{comment}{//\ Standard\ Includes}}
\DoxyCodeLine{00044\ \textcolor{preprocessor}{\#include\ <cstring>}}
\DoxyCodeLine{00045\ }
\DoxyCodeLine{00046\ }
\DoxyCodeLine{00064\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T,\ \textcolor{keywordtype}{size\_t}\ S>}
\DoxyCodeLine{00065\ \textcolor{keyword}{class\ }\mbox{\hyperlink{a01810}{AAX\_CAtomicQueue}}\ :\ \textcolor{keyword}{public}\ \mbox{\hyperlink{a02306}{AAX\_IPointerQueue}}<T>}
\DoxyCodeLine{00066\ \{}
\DoxyCodeLine{00067\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00068\ \ \ \ \ \textcolor{keyword}{virtual}\ \mbox{\hyperlink{a01810_a838ca2b3763f10c4e4d9e72b676fd358}{\string~AAX\_CAtomicQueue}}()\ \{\}}
\DoxyCodeLine{00069\ \ \ \ \ \mbox{\hyperlink{a01810_ae048321b8d75f9fa073e6a24088d8260}{AAX\_CAtomicQueue}}();}
\DoxyCodeLine{00070\ \ \ \ \ }
\DoxyCodeLine{00071\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00072\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{a01810_a7040410a6baeae48d153ef44ee0df1f1}{template\_size}}\ =\ S;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00073\ \ \ \ \ }
\DoxyCodeLine{00074\ \ \ \ \ \textcolor{keyword}{typedef}\ \textcolor{keyword}{typename}\ \mbox{\hyperlink{a02306_ae37a600f078ca0ee6f24b9f45aadc254}{AAX\_IPointerQueue<T>::template\_type}}\ \mbox{\hyperlink{a01810_aae36349d9419de62ce8e74b397749c27}{template\_type}};\ \ }
\DoxyCodeLine{00075\ \ \ \ \ \textcolor{keyword}{typedef}\ \textcolor{keyword}{typename}\ \mbox{\hyperlink{a02306_a2d28a2dffe8dc2b7fe218c41b46734e9}{AAX\_IPointerQueue<T>::value\_type}}\ \mbox{\hyperlink{a01810_acbb95bad3be34c7e4c770bc8c455c252}{value\_type}};\ \ \ \ \ \ \ \ }
\DoxyCodeLine{00076\ \ \ \ \ }
\DoxyCodeLine{00077\ \textcolor{keyword}{public}:\ \textcolor{comment}{//\ AAX\_IContainer}}
\DoxyCodeLine{00078\ \ \ \ \ \textcolor{keyword}{virtual}\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{a01810_a9819ff531e285f2acd2c9fd2351617c4}{Clear}}();\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00079\ \ \ \ \ }
\DoxyCodeLine{00080\ \textcolor{keyword}{public}:\ \textcolor{comment}{//\ AAX\_IPointerQueue}}
\DoxyCodeLine{00081\ \ \ \ \ \textcolor{keyword}{virtual}\ \mbox{\hyperlink{a02218_aea020100f0b06636ce7cb25c2fdb0af7}{AAX\_IContainer::EStatus}}\ \mbox{\hyperlink{a01810_a2304d6ba1f1026b6a42de48056ab3050}{Push}}(\mbox{\hyperlink{a01810_acbb95bad3be34c7e4c770bc8c455c252}{value\_type}}\ inElem);\ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00082\ \ \ \ \ \textcolor{keyword}{virtual}\ \mbox{\hyperlink{a01810_acbb95bad3be34c7e4c770bc8c455c252}{value\_type}}\ \mbox{\hyperlink{a01810_a0c64180813c16b4952761f82e32d7edd}{Pop}}();\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00083\ \ \ \ \ \textcolor{keyword}{virtual}\ \mbox{\hyperlink{a01810_acbb95bad3be34c7e4c770bc8c455c252}{value\_type}}\ \mbox{\hyperlink{a01810_a0b732544b0bcdd59acfca7fac5dca984}{Peek}}()\ \textcolor{keyword}{const};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00084\ \ \ \ \ }
\DoxyCodeLine{00085\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00086\ \ \ \ \ \mbox{\hyperlink{a01870}{AAX\_CMutex}}\ mMutex;}
\DoxyCodeLine{00087\ \ \ \ \ uint32\_t\ mReadIdx;}
\DoxyCodeLine{00088\ \ \ \ \ uint32\_t\ mWriteIdx;}
\DoxyCodeLine{00089\ \ \ \ \ \mbox{\hyperlink{a01810_acbb95bad3be34c7e4c770bc8c455c252}{value\_type}}\ mRingBuffer[S];}
\DoxyCodeLine{00090\ \};}
\DoxyCodeLine{00091\ }
\DoxyCodeLine{00092\ }
\DoxyCodeLine{00094\ }
\DoxyCodeLine{00095\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T,\ \textcolor{keywordtype}{size\_t}\ S>}
\DoxyCodeLine{00096\ \textcolor{keyword}{inline}\ \mbox{\hyperlink{a01810_ae048321b8d75f9fa073e6a24088d8260}{AAX\_CAtomicQueue<T,\ S>::AAX\_CAtomicQueue}}()}
\DoxyCodeLine{00097\ :\ \mbox{\hyperlink{a02306}{AAX\_IPointerQueue}}<T>()}
\DoxyCodeLine{00098\ ,\ mMutex()}
\DoxyCodeLine{00099\ ,\ mReadIdx(0)}
\DoxyCodeLine{00100\ ,\ mWriteIdx(0)}
\DoxyCodeLine{00101\ \{}
\DoxyCodeLine{00102\ \ \ \ \ \mbox{\hyperlink{a01810_a9819ff531e285f2acd2c9fd2351617c4}{Clear}}();}
\DoxyCodeLine{00103\ \}}
\DoxyCodeLine{00104\ }
\DoxyCodeLine{00105\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T,\ \textcolor{keywordtype}{size\_t}\ S>}
\DoxyCodeLine{00106\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{a01810_a9819ff531e285f2acd2c9fd2351617c4}{AAX\_CAtomicQueue<T,\ S>::Clear}}()}
\DoxyCodeLine{00107\ \{}
\DoxyCodeLine{00108\ \ \ \ \ std::memset((\textcolor{keywordtype}{void}*)mRingBuffer,\ 0x0,\ \textcolor{keyword}{sizeof}(mRingBuffer));}
\DoxyCodeLine{00109\ \}}
\DoxyCodeLine{00110\ }
\DoxyCodeLine{00111\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T,\ \textcolor{keywordtype}{size\_t}\ S>}
\DoxyCodeLine{00112\ \textcolor{keyword}{inline}\ \mbox{\hyperlink{a02218_aea020100f0b06636ce7cb25c2fdb0af7}{AAX\_IContainer::EStatus}}\ \mbox{\hyperlink{a01810_a2304d6ba1f1026b6a42de48056ab3050}{AAX\_CAtomicQueue<T,\ S>::Push}}(\textcolor{keyword}{typename}\ \mbox{\hyperlink{a01810_acbb95bad3be34c7e4c770bc8c455c252}{AAX\_CAtomicQueue<T,\ S>::value\_type}}\ inElem)}
\DoxyCodeLine{00113\ \{}
\DoxyCodeLine{00114\ \ \ \ \ \textcolor{keywordflow}{if}\ (NULL\ ==\ inElem)}
\DoxyCodeLine{00115\ \ \ \ \ \{}
\DoxyCodeLine{00116\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{a02218_aea020100f0b06636ce7cb25c2fdb0af7a1585c38bb587c4adcadefbe3823ee9f8}{AAX\_IContainer::eStatus\_Unsupported}};}
\DoxyCodeLine{00117\ \ \ \ \ \}}
\DoxyCodeLine{00118\ \ \ \ \ }
\DoxyCodeLine{00119\ \ \ \ \ \mbox{\hyperlink{a02218_aea020100f0b06636ce7cb25c2fdb0af7}{AAX\_IContainer::EStatus}}\ result\ =\ \mbox{\hyperlink{a02218_aea020100f0b06636ce7cb25c2fdb0af7a7586eb60b4cb29ee8ed06aa7c539fe62}{AAX\_IContainer::eStatus\_Unavailable}};}
\DoxyCodeLine{00120\ \ \ \ \ }
\DoxyCodeLine{00121\ \ \ \ \ \mbox{\hyperlink{a01874}{AAX\_StLock\_Guard}}\ guard(mMutex);}
\DoxyCodeLine{00122\ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00123\ \ \ \ \ \textcolor{comment}{//\ Possible\ failure\ case\ without\ mutex\ is\ because\ of\ several\ write\ threads\ try\ to\ modify}}
\DoxyCodeLine{00124\ \ \ \ \ \textcolor{comment}{//\ mWriteIdx\ concurrently}}
\DoxyCodeLine{00125\ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00126\ \ \ \ \ \textcolor{comment}{//\ Example:}}
\DoxyCodeLine{00127\ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00128\ \ \ \ \ \textcolor{comment}{//\ -\/}}
\DoxyCodeLine{00129\ \ \ \ \ \textcolor{comment}{//\ Notation:}}
\DoxyCodeLine{00130\ \ \ \ \ \textcolor{comment}{//\ First\ number\ \ -\/\ write\ thread\ number}}
\DoxyCodeLine{00131\ \ \ \ \ \textcolor{comment}{//\ Second\ number\ -\/\ value\ number}}
\DoxyCodeLine{00132\ \ \ \ \ \textcolor{comment}{//\ 1/15\ -\/\ 1st\ thread\ that\ write\ number\ 15}}
\DoxyCodeLine{00133\ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00134\ \ \ \ \ \textcolor{comment}{//\ -\/}}
\DoxyCodeLine{00135\ \ \ \ \ \textcolor{comment}{//\ Queue\ may\ look\ like\ this:}}
\DoxyCodeLine{00136\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ mReadIdx}}
\DoxyCodeLine{00137\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |}}
\DoxyCodeLine{00138\ \ \ \ \ \textcolor{comment}{//\ |.....\ |\ 4/3\ |\ 4/4\ |\ 1/4\ |\ 1/5\ |\ 2/7\ |\ 2/8\ |\ 2/9\ |\ .....|}}
\DoxyCodeLine{00139\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |}}
\DoxyCodeLine{00140\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ mWriteIdx}}
\DoxyCodeLine{00141\ \ \ \ \ \textcolor{comment}{//\ place\#\ |\ \ 0\ \ |\ \ 1\ \ |\ \ 2\ \ |\ \ 3\ \ |\ \ 4\ \ |\ \ 5\ \ |\ \ 6\ \ |\ .....|}}
\DoxyCodeLine{00142\ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00143\ \ \ \ \ \textcolor{comment}{//\ -\/}}
\DoxyCodeLine{00144\ \ \ \ \ \textcolor{comment}{//\ Possible\ operation\ order\ (w\ stands\ for\ mWriteIdx,\ r\ -\/\ for\ mReadIdx):}}
\DoxyCodeLine{00145\ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00146\ \ \ \ \ \textcolor{comment}{//\ thread\#|\ action\ |\ write\ index\ value\ |\ mWriteIdx\ \ \ \ \ \ \ |}}
\DoxyCodeLine{00147\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ |\ \ \ \ \ \ \ \ |\ internal\ variable\ |\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |}}
\DoxyCodeLine{00148\ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00149\ \ \ \ \ \textcolor{comment}{//\ \ \ \ 5\ \ \ |\ \ \ w++\ \ |\ \ \ \ \ \ \ \ 2\ \ \ \ \ \ \ \ \ \ |\ \ \ \ \ \ \ \ 2\ \ \ \ \ \ \ \ |}}
\DoxyCodeLine{00150\ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00151\ \ \ \ \ \textcolor{comment}{//\ \ \ \ 6\ \ \ |\ \ \ w++\ \ |\ \ \ \ \ \ \ \ 3\ \ \ \ \ \ \ \ \ \ |\ \ \ \ \ \ \ \ 3\ \ \ \ \ \ \ \ |}}
\DoxyCodeLine{00152\ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00153\ \ \ \ \ \textcolor{comment}{//\ \ \ \ 5\ \ \ |\ \ false\ |\ \ \ \ \ \ \ \ -\/\ \ \ \ \ \ \ \ \ \ |\ 2not=3\ =>\ 2-\/-\/=1\ |}}
\DoxyCodeLine{00154\ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00155\ \ \ \ \ \textcolor{comment}{//\ \ read\ \ |\ \ \ r++\ \ |\ \ \ \ \ \ \ \ -\/\ \ \ \ \ \ \ \ \ \ |\ \ \ \ \ \ \ \ -\/\ \ \ \ \ \ \ \ |}}
\DoxyCodeLine{00156\ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00157\ \ \ \ \ \textcolor{comment}{//\ \ read\ \ |\ \ \ r++\ \ |\ \ \ \ \ \ \ \ -\/\ \ \ \ \ \ \ \ \ \ |\ \ \ \ \ \ \ \ -\/\ \ \ \ \ \ \ \ |}}
\DoxyCodeLine{00158\ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00159\ \ \ \ \ \textcolor{comment}{//\ -\/}}
\DoxyCodeLine{00160\ \ \ \ \ \textcolor{comment}{//\ Queue\ state:}}
\DoxyCodeLine{00161\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ mReadIdx}}
\DoxyCodeLine{00162\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |}}
\DoxyCodeLine{00163\ \ \ \ \ \textcolor{comment}{//\ |.....\ |\ 4/3\ |\ \ 0\ \ |\ \ 0\ \ |\ 1/5\ |\ 2/7\ |\ 2/8\ |\ 2/9\ |\ .....|}}
\DoxyCodeLine{00164\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |}}
\DoxyCodeLine{00165\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ mWriteIdx}}
\DoxyCodeLine{00166\ \ \ \ \ \textcolor{comment}{//\ place\#\ |\ \ 0\ \ |\ \ 1\ \ |\ \ 2\ \ |\ \ 3\ \ |\ \ 4\ \ |\ \ 5\ \ |\ \ 6\ \ |\ .....|}}
\DoxyCodeLine{00167\ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00168\ \ \ \ \ \textcolor{comment}{//\ -\/}}
\DoxyCodeLine{00169\ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00170\ \ \ \ \ \textcolor{comment}{//\ \ \ \ 6\ \ \ |\ false\ \ |\ \ \ \ \ \ \ \ -\/\ \ \ \ \ \ \ \ \ \ |\ 3not=1\ =>\ 3-\/-\/=2\ |\ //\ place\ 3\ is\ still\ not\ empty\ to\ write}}
\DoxyCodeLine{00171\ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}}
\DoxyCodeLine{00172\ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00173\ \ \ \ \ \textcolor{comment}{//\ -\/}}
\DoxyCodeLine{00174\ \ \ \ \ \textcolor{comment}{//\ Now,\ some\ other\ thread\ (5,\ for\ example)\ can\ successfully\ write}}
\DoxyCodeLine{00175\ \ \ \ \ \textcolor{comment}{//\ it's\ value\ to\ queue\ and\ move\ mWriteIdx\ forward:}}
\DoxyCodeLine{00176\ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00177\ \ \ \ \ \textcolor{comment}{//\ -\/}}
\DoxyCodeLine{00178\ \ \ \ \ \textcolor{comment}{//\ Queue\ state:}}
\DoxyCodeLine{00179\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ mReadIdx}}
\DoxyCodeLine{00180\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |}}
\DoxyCodeLine{00181\ \ \ \ \ \textcolor{comment}{//\ |.....\ |\ 4/3\ |\ \ 0\ \ |\ 5/1\ |\ 1/5\ |\ 2/7\ |\ 2/8\ |\ 2/9\ |\ .....|}}
\DoxyCodeLine{00182\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |}}
\DoxyCodeLine{00183\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ mWriteIdx}}
\DoxyCodeLine{00184\ \ \ \ \ \textcolor{comment}{//\ place\#\ |\ \ 0\ \ |\ \ 1\ \ |\ \ 2\ \ |\ \ 3\ \ |\ \ 4\ \ |\ \ 5\ \ |\ \ 6\ \ |\ .....|}}
\DoxyCodeLine{00185\ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00186\ \ \ \ \ \textcolor{comment}{//\ -\/}}
\DoxyCodeLine{00187\ \ \ \ \ \textcolor{comment}{//\ Thus,\ we\ have\ one\ place\ with\ NULL\ value\ left.\ In\ the\ next\ round\ mReadIdx\ will}}
\DoxyCodeLine{00188\ \ \ \ \ \textcolor{comment}{//\ stuck\ on\ place\ \#1\ (queue\ thinks\ that\ it's\ empty)\ until\ one\ of\ the\ write\ threads}}
\DoxyCodeLine{00189\ \ \ \ \ \textcolor{comment}{//\ will\ write\ the\ value\ into\ place\ \#1.\ It\ could\ be\ thread\ \#5,\ so\ we\ have:}}
\DoxyCodeLine{00190\ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00191\ \ \ \ \ \textcolor{comment}{//\ -\/}}
\DoxyCodeLine{00192\ \ \ \ \ \textcolor{comment}{//\ Queue\ state:}}
\DoxyCodeLine{00193\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ mReadIdx}}
\DoxyCodeLine{00194\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |}}
\DoxyCodeLine{00195\ \ \ \ \ \textcolor{comment}{//\ |.....\ |\ 9/1\ |\ 5/9\ |\ 5/1\ |\ 1/5\ |\ 2/7\ |\ 2/8\ |\ 2/9\ |\ .....|}}
\DoxyCodeLine{00196\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ |}}
\DoxyCodeLine{00197\ \ \ \ \ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ mWriteIdx}}
\DoxyCodeLine{00198\ \ \ \ \ \textcolor{comment}{//\ place\#\ |\ \ 0\ \ |\ \ 1\ \ |\ \ 2\ \ |\ \ 3\ \ |\ \ 4\ \ |\ \ 5\ \ |\ \ 6\ \ |\ .....|}}
\DoxyCodeLine{00199\ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00200\ \ \ \ \ \textcolor{comment}{//\ -\/}}
\DoxyCodeLine{00201\ \ \ \ \ \textcolor{comment}{//\ And\ we\ will\ read\ 5/9\ before\ 5/1}}
\DoxyCodeLine{00202\ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00203\ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00204\ \ \ \ \ \textcolor{comment}{//\ Note\ that\ read/write\ both\ begin\ at\ index\ 1}}
\DoxyCodeLine{00205\ \ \ \ \ \textcolor{keyword}{const}\ uint32\_t\ idx\ =\ \mbox{\hyperlink{a00749_a56633d7039fae1d31c8984f9baafa17e}{AAX\_Atomic\_IncThenGet\_32}}(mWriteIdx);}
\DoxyCodeLine{00206\ \ \ \ \ \textcolor{keyword}{const}\ uint32\_t\ widx\ =\ idx\ \%\ S;}
\DoxyCodeLine{00207\ \ \ \ \ }
\DoxyCodeLine{00208\ \ \ \ \ \textcolor{comment}{//\ Do\ the\ push.\ If\ the\ value\ at\ the\ current\ write\ index\ is\ non-\/NULL\ then\ we\ have\ filled\ the\ buffer.}}
\DoxyCodeLine{00209\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{bool}\ cxResult\ =\ \mbox{\hyperlink{a00749_ab1c7611e7c95fd61900b8e5a44c36e63}{AAX\_Atomic\_CompareAndExchange\_Pointer}}(mRingBuffer[widx],\ (value\_type)0x0,\ inElem);}
\DoxyCodeLine{00210\ \ \ \ \ }
\DoxyCodeLine{00211\ \ \ \ \ \textcolor{keywordflow}{if}\ (\textcolor{keyword}{false}\ ==\ cxResult)}
\DoxyCodeLine{00212\ \ \ \ \ \{}
\DoxyCodeLine{00213\ \ \ \ \ \ \ \ \ result\ =\ \mbox{\hyperlink{a02218_aea020100f0b06636ce7cb25c2fdb0af7a977319edf1a7a788eeee29dd71982f66}{AAX\_IContainer::eStatus\_Overflow}};}
\DoxyCodeLine{00214\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00215\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ uint32\_t\ ridx\ =\ (0\ ==\ idx)\ ?\ S\ :\ idx-\/1;}
\DoxyCodeLine{00216\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00217\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ Note\ the\ write\ index\ has\ already\ been\ incremented,\ so\ in\ the\ event\ of\ an\ overflow\ we\ must}}
\DoxyCodeLine{00218\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ return\ the\ write\ index\ to\ its\ previous\ location.}}
\DoxyCodeLine{00219\ \ \ \ \ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00220\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ Note:\ if\ multiple\ write\ threads\ encounter\ concurrent\ push\ overflows\ then\ the\ write\ pointer}}
\DoxyCodeLine{00221\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ will\ not\ be\ fully\ decremented\ back\ to\ the\ overflow\ location,\ and\ the\ read\ index\ will\ need}}
\DoxyCodeLine{00222\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ to\ increment\ multiple\ positions\ to\ clear\ the\ overflow\ state.}}
\DoxyCodeLine{00223\ \textcolor{comment}{//\ \ \ \ \ \ const\ bool\ resetResult\ =\ AAX\_Atomic\_CompareAndExchange\_32(mWriteIdx,\ idx,\ ridx);}}
\DoxyCodeLine{00224\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{a00749_a74a2bdb895976193bdfe4cd2fe31e21e}{AAX\_Atomic\_CompareAndExchange\_32}}(mWriteIdx,\ idx,\ ridx);}
\DoxyCodeLine{00225\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00226\ \textcolor{comment}{//\ \ \ \ \ \ printf("{}AAX\_CAtomicQueue:\ overflow\ -\/\ reset:\ \%s,\ idx:\ \%lu,\ widx:\ \%lu,\ inElem:\ \%p\(\backslash\)n"{},}}
\DoxyCodeLine{00227\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ resetResult\ ?\ "{}yes"{}\ :\ "{}\ no"{},}}
\DoxyCodeLine{00228\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ (unsigned\ long)idx,}}
\DoxyCodeLine{00229\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ (unsigned\ long)widx,}}
\DoxyCodeLine{00230\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ inElem);}}
\DoxyCodeLine{00231\ \ \ \ \ \}}
\DoxyCodeLine{00232\ \ \ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{00233\ \ \ \ \ \{}
\DoxyCodeLine{00234\ \ \ \ \ \ \ \ \ result\ =\ \mbox{\hyperlink{a02218_aea020100f0b06636ce7cb25c2fdb0af7add595169a28f04ed79be4f1c5974eb48}{AAX\_IContainer::eStatus\_Success}};}
\DoxyCodeLine{00235\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00236\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ Handle\ wraparound}}
\DoxyCodeLine{00237\ \ \ \ \ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00238\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ There\ may\ be\ multiple\ write\ threads\ pushing\ elements\ at\ the\ same\ time,\ so\ we\ use}}
\DoxyCodeLine{00239\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ (wrapped\ index\ <\ raw\ index)\ instead\ of\ (raw\ index\ ==\ boundary)}}
\DoxyCodeLine{00240\ \ \ \ \ \ \ \ \ \textcolor{comment}{//}}
\DoxyCodeLine{00241\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ This\ assumes\ overhead\ between\ S\ and\ UINT\_32\_MAX\ of\ at\ least\ as\ many\ elements\ as}}
\DoxyCodeLine{00242\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ there\ are\ write\ threads.}}
\DoxyCodeLine{00243\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00244\ \textcolor{comment}{//\ \ \ \ \ \ bool\ exchResult\ =\ false;}}
\DoxyCodeLine{00245\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (widx\ <\ idx)}
\DoxyCodeLine{00246\ \ \ \ \ \ \ \ \ \{}
\DoxyCodeLine{00247\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ exchResult\ =}}
\DoxyCodeLine{00248\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{a00749_a74a2bdb895976193bdfe4cd2fe31e21e}{AAX\_Atomic\_CompareAndExchange\_32}}(mWriteIdx,\ idx,\ widx);}
\DoxyCodeLine{00249\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00250\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00251\ \textcolor{comment}{//\ \ \ \ \ \ printf("{}AAX\_CAtomicQueue:\ pushed\ \ \ \ -\/\ reset:\ \%s,\ idx:\ \%lu,\ widx:\ \%lu,\ inElem:\ \%p\(\backslash\)n"{},}}
\DoxyCodeLine{00252\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ (widx\ <\ idx)\ ?\ exchResult\ ?\ "{}yes"{}\ :\ "{}\ no"{}\ :\ "{}n/a"{},}}
\DoxyCodeLine{00253\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ (unsigned\ long)idx,}}
\DoxyCodeLine{00254\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ (unsigned\ long)widx,}}
\DoxyCodeLine{00255\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ inElem);}}
\DoxyCodeLine{00256\ \ \ \ \ \}}
\DoxyCodeLine{00257\ \ \ \ \ }
\DoxyCodeLine{00258\ \ \ \ \ \textcolor{keywordflow}{return}\ result;}
\DoxyCodeLine{00259\ \}}
\DoxyCodeLine{00260\ }
\DoxyCodeLine{00261\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T,\ \textcolor{keywordtype}{size\_t}\ S>}
\DoxyCodeLine{00262\ \textcolor{keyword}{inline}\ \textcolor{keyword}{typename}\ \mbox{\hyperlink{a01810_acbb95bad3be34c7e4c770bc8c455c252}{AAX\_CAtomicQueue<T,\ S>::value\_type}}\ \mbox{\hyperlink{a01810_a0c64180813c16b4952761f82e32d7edd}{AAX\_CAtomicQueue<T,\ S>::Pop}}()}
\DoxyCodeLine{00263\ \{}
\DoxyCodeLine{00264\ \ \ \ \ \textcolor{comment}{//\ Note\ that\ read/write\ both\ begin\ at\ index\ 1}}
\DoxyCodeLine{00265\ \ \ \ \ mReadIdx\ =\ (mReadIdx+1)\ \%\ template\_size;}
\DoxyCodeLine{00266\ \ \ \ \ value\_type\ \textcolor{keyword}{const}\ val\ =\ \mbox{\hyperlink{a00749_add2856260ffb4309c4e515bac8490bea}{AAX\_Atomic\_Exchange\_Pointer}}(mRingBuffer[mReadIdx],\ (value\_type)0x0);}
\DoxyCodeLine{00267\ \ \ \ \ }
\DoxyCodeLine{00268\ \textcolor{comment}{//\ \ printf("{}AAX\_CAtomicQueue:\ popped\ \ \ \ -\/\ reset:\ \%s,\ idx:\ \%lu,\ \ \ \ \ \ \ \ \ \ \ \ val:\ \ \ \ \%p\(\backslash\)n"{},}}
\DoxyCodeLine{00269\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ (0x0\ ==\ val)\ ?\ "{}yes"{}\ :\ "{}\ no"{},}}
\DoxyCodeLine{00270\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ (unsigned\ long)mReadIdx,}}
\DoxyCodeLine{00271\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ val);}}
\DoxyCodeLine{00272\ \ \ \ \ }
\DoxyCodeLine{00273\ \ \ \ \ \textcolor{keywordflow}{if}\ (0x0\ ==\ val)}
\DoxyCodeLine{00274\ \ \ \ \ \{}
\DoxyCodeLine{00275\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ If\ the\ value\ is\ NULL\ then\ no\ value\ has\ yet\ been\ written\ to\ this\ location.\ Decrement\ the\ read\ index}}
\DoxyCodeLine{00276\ \ \ \ \ \ \ \ \ -\/-\/mReadIdx;\ \textcolor{comment}{//\ No\ need\ to\ handle\ wraparound\ since\ the\ read\ index\ will\ be\ incremented\ before\ the\ next\ read}}
\DoxyCodeLine{00277\ \ \ \ \ \}}
\DoxyCodeLine{00278\ \ \ \ \ }
\DoxyCodeLine{00279\ \ \ \ \ \textcolor{keywordflow}{return}\ val;}
\DoxyCodeLine{00280\ \}}
\DoxyCodeLine{00281\ }
\DoxyCodeLine{00282\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T,\ \textcolor{keywordtype}{size\_t}\ S>}
\DoxyCodeLine{00283\ \textcolor{keyword}{inline}\ \textcolor{keyword}{typename}\ \mbox{\hyperlink{a01810_acbb95bad3be34c7e4c770bc8c455c252}{AAX\_CAtomicQueue<T,\ S>::value\_type}}\ \mbox{\hyperlink{a01810_a0b732544b0bcdd59acfca7fac5dca984}{AAX\_CAtomicQueue<T,\ S>::Peek}}()\textcolor{keyword}{\ const}}
\DoxyCodeLine{00284\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00285\ \ \ \ \ \textcolor{comment}{//\ I\ don't\ think\ that\ we\ need\ a\ memory\ barrier\ here\ because:}}
\DoxyCodeLine{00286\ \ \ \ \ \textcolor{comment}{//\ a)\ mReadIdx\ will\ only\ be\ modified\ from\ the\ read\ thread,\ and\ therefore\ presumably}}
\DoxyCodeLine{00287\ \ \ \ \ \textcolor{comment}{//\ \ \ \ using\ the\ same\ CPU\ (or\ at\ least\ I\ can't\ see\ any\ way\ for\ mReadIndex\ modification}}
\DoxyCodeLine{00288\ \ \ \ \ \textcolor{comment}{//\ \ \ \ ordering\ to\ be\ a\ problem\ between\ Peek()\ and\ Pop()\ on\ a\ single\ thread.)}}
\DoxyCodeLine{00289\ \ \ \ \ \textcolor{comment}{//\ b)\ We\ don't\ care\ if\ mRingBuffer\ modifications\ are\ run\ out\ of\ order\ between\ the\ read}}
\DoxyCodeLine{00290\ \ \ \ \ \textcolor{comment}{//\ \ \ \ and\ write\ threads,\ as\ long\ as\ they\ are\ "{}close"{}.}}
\DoxyCodeLine{00291\ \ \ \ \ \textcolor{keyword}{const}\ uint32\_t\ testIdx\ =\ (mReadIdx+1)\ \%\ template\_size;}
\DoxyCodeLine{00292\ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{a00749_ace950fb6e426fd95d69da49462dfb878}{AAX\_Atomic\_Load\_Pointer}}(\&mRingBuffer[testIdx]);}
\DoxyCodeLine{00293\ \}}
\DoxyCodeLine{00294\ }
\DoxyCodeLine{00295\ \textcolor{comment}{//\ Attempt\ to\ support\ multiple\ read\ threads}}
\DoxyCodeLine{00296\ \textcolor{comment}{//}}
\DoxyCodeLine{00297\ \textcolor{comment}{//\ This\ approach\ is\ broken\ in\ the\ following\ scenario:}}
\DoxyCodeLine{00298\ \textcolor{comment}{//}}
\DoxyCodeLine{00299\ \textcolor{comment}{//\ Thread\ |\ Operation}}
\DoxyCodeLine{00300\ \textcolor{comment}{//\ \ \ \ \ \ A\ \ \ Pop\ v\ enter}}
\DoxyCodeLine{00301\ \textcolor{comment}{//\ \ \ \ \ \ A\ \ \ Pop\ -\/\ increment/get\ read\ index\ (get\ 1)}}
\DoxyCodeLine{00302\ \textcolor{comment}{//\ \ \ \ \ \ A\ \ \ Pop\ -\/\ exchange\ pointer\ (get\ 0x0)}}
\DoxyCodeLine{00303\ \textcolor{comment}{//\ \ other\ \ \ Push\ ptr1}}
\DoxyCodeLine{00304\ \textcolor{comment}{//\ \ other\ \ \ Push\ ptr2}}
\DoxyCodeLine{00305\ \textcolor{comment}{//\ \ \ \ \ \ B\ \ \ Pop\ v\ enter}}
\DoxyCodeLine{00306\ \textcolor{comment}{//\ \ \ \ \ \ B\ \ \ Pop\ -\/\ increment/get\ read\ index\ (get\ 2)}}
\DoxyCodeLine{00307\ \textcolor{comment}{//\ \ \ \ \ \ B\ \ \ Pop\ -\/\ exchange\ pointer\ (get\ ptr2)}}
\DoxyCodeLine{00308\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ ERROR:\ popped\ ptr2\ before\ ptr1}}
\DoxyCodeLine{00309\ \textcolor{comment}{//\ \ \ \ \ \ B\ \ \ Pop\ \string^\ exit}}
\DoxyCodeLine{00310\ \textcolor{comment}{//\ \ \ \ \ \ A\ \ \ Pop\ -\/\ decrement\ read\ index\ (set\ 1)}}
\DoxyCodeLine{00311\ \textcolor{comment}{//\ \ \ \ \ \ A\ \ \ Pop\ \string^\ exit}}
\DoxyCodeLine{00312\ \textcolor{comment}{//\ \ \ \ any\ \ \ Pop\ v\ enter}}
\DoxyCodeLine{00313\ \textcolor{comment}{//\ \ \ \ any\ \ \ Pop\ -\/\ increment/get\ read\ index\ (get\ 2)}}
\DoxyCodeLine{00314\ \textcolor{comment}{//\ \ \ \ any\ \ \ Pop\ -\/\ exchange\ pointer\ (get\ 0x0)}}
\DoxyCodeLine{00315\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ ERROR:\ should\ be\ ptr2}}
\DoxyCodeLine{00316\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ This\ NULL\ state\ continues\ for\ further\ Pop\ calls\ until\ either\ Push\ wraps\ around}}
\DoxyCodeLine{00317\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ or\ another\ pair\ of\ concurrent\ calls\ to\ Pop\ just\ happens\ to\ re-\/aligign\ the\ read}}
\DoxyCodeLine{00318\ \textcolor{comment}{//\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ index\ by\ incrementing\ twice\ before\ any\ reads\ occur}}
\DoxyCodeLine{00319\ \textcolor{comment}{//\ \ \ \ any\ \ \ Pop\ -\/\ decrement\ read\ index\ (set\ 1)}}
\DoxyCodeLine{00320\ \textcolor{comment}{//\ \ \ \ any\ \ \ Pop\ \string^\ exit}}
\DoxyCodeLine{00321\ \textcolor{comment}{//}}
\DoxyCodeLine{00322\ \textcolor{comment}{//\ This\ could\ be\ fixed\ by\ incrementing\ the\ read\ index\ until\ either\ a\ non-\/NULL\ value\ is\ found\ or}}
\DoxyCodeLine{00323\ \textcolor{comment}{//\ the\ initial\ position\ is\ reached,\ but\ that\ would\ have\ terrible\ performance.}}
\DoxyCodeLine{00324\ \textcolor{comment}{//}}
\DoxyCodeLine{00325\ \textcolor{comment}{//\ In\ any\ case,\ assuming\ a\ single\ read\ thread\ is\ optimal\ when\ we\ want\ maximum\ performance\ for\ read}}
\DoxyCodeLine{00326\ \textcolor{comment}{//\ operations,\ since\ this\ requires\ the\ fewest\ number\ of\ atomic\ operations\ in\ the\ read\ methods}}
\DoxyCodeLine{00327\ \textcolor{comment}{/*}}
\DoxyCodeLine{00328\ \textcolor{comment}{template\ <typename\ T,\ size\_t\ S>}}
\DoxyCodeLine{00329\ \textcolor{comment}{inline\ typename\ AAX\_CAtomicQueue<T,\ S>::value\_type\ AAX\_CAtomicQueue<T,\ S>::Pop()}}
\DoxyCodeLine{00330\ \textcolor{comment}{\{}}
\DoxyCodeLine{00331\ \textcolor{comment}{\ \ \ \ const\ uint32\_t\ idx\ =\ AAX\_Atomic\_IncThenGet\_32(mReadIdx);}}
\DoxyCodeLine{00332\ \textcolor{comment}{\ \ \ \ const\ uint32\_t\ widx\ =\ idx\ \%\ S;}}
\DoxyCodeLine{00333\ \textcolor{comment}{\ \ \ \ }}
\DoxyCodeLine{00334\ \textcolor{comment}{\ \ \ \ value\_type\ const\ val\ =\ AAX\_Atomic\_Exchange\_Pointer(mRingBuffer[widx],\ (value\_type)0x0);}}
\DoxyCodeLine{00335\ \textcolor{comment}{\ \ \ \ }}
\DoxyCodeLine{00336\ \textcolor{comment}{\ \ \ \ if\ (0x0\ ==\ val)}}
\DoxyCodeLine{00337\ \textcolor{comment}{\ \ \ \ \{}}
\DoxyCodeLine{00338\ \textcolor{comment}{\ \ \ \ \ \ \ \ //\ If\ the\ value\ is\ NULL\ then\ no\ value\ has\ yet\ been\ written\ to\ this\ location.\ Decrement\ the\ read\ index}}
\DoxyCodeLine{00339\ \textcolor{comment}{\ \ \ \ \ \ \ \ AAX\_Atomic\_DecThenGet\_32(mReadIdx);}}
\DoxyCodeLine{00340\ \textcolor{comment}{\ \ \ \ \}}}
\DoxyCodeLine{00341\ \textcolor{comment}{\ \ \ \ else}}
\DoxyCodeLine{00342\ \textcolor{comment}{\ \ \ \ \{}}
\DoxyCodeLine{00343\ \textcolor{comment}{\ \ \ \ \ \ \ \ //\ Handle\ wraparound\ (assumes\ some\ overhead\ between\ S\ and\ UINT\_32\_MAX)}}
\DoxyCodeLine{00344\ \textcolor{comment}{\ \ \ \ \ \ \ \ if\ (widx\ <\ idx)}}
\DoxyCodeLine{00345\ \textcolor{comment}{\ \ \ \ \ \ \ \ \{}}
\DoxyCodeLine{00346\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ AAX\_Atomic\_CompareAndExchange\_32(mReadIdx,\ idx,\ widx);}}
\DoxyCodeLine{00347\ \textcolor{comment}{\ \ \ \ \ \ \ \ \}}}
\DoxyCodeLine{00348\ \textcolor{comment}{\ \ \ \ \}}}
\DoxyCodeLine{00349\ \textcolor{comment}{\ \ \ \ }}
\DoxyCodeLine{00350\ \textcolor{comment}{\ \ \ \ return\ val;}}
\DoxyCodeLine{00351\ \textcolor{comment}{\}}}
\DoxyCodeLine{00352\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00353\ }
\DoxyCodeLine{00355\ }
\DoxyCodeLine{00357\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{/*\ defined(AAX\_CATOMICQUEUE\_H)\ */}\textcolor{preprocessor}{}}

\end{DoxyCode}
