\doxysection{Thread\+Safe\+Queue.\+hh}
\hypertarget{ThreadSafeQueue_8hh_source}{}\label{ThreadSafeQueue_8hh_source}\index{include/utils/ThreadSafeQueue.hh@{include/utils/ThreadSafeQueue.hh}}
\mbox{\hyperlink{ThreadSafeQueue_8hh}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{//\ C++\ Includes}}
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#include\ <queue>}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#include\ <thread>}}
\DoxyCodeLine{00004\ \textcolor{preprocessor}{\#include\ <functional>}}
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#include\ <mutex>}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#include\ <condition\_variable>}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ \textcolor{keyword}{namespace\ }\mbox{\hyperlink{namespaceutils}{utils}}\ \{}
\DoxyCodeLine{00009\ }
\DoxyCodeLine{00010\ \textcolor{keyword}{template}<\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00011\ \textcolor{keyword}{class\ }\mbox{\hyperlink{classutils_1_1ThreadSafeQueue}{ThreadSafeQueue}}\ \{}
\DoxyCodeLine{00012\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00013\ \ \ \ \ std::queue<T>\ \mbox{\hyperlink{classutils_1_1ThreadSafeQueue_a970596f4c9a6d1a806b06d46807e06ee}{\_queue}};}
\DoxyCodeLine{00014\ \ \ \ \ std::mutex\ \mbox{\hyperlink{classutils_1_1ThreadSafeQueue_a43fef8c13f23363c48bac7a6a49a565b}{\_mutex}};}
\DoxyCodeLine{00015\ \ \ \ \ std::condition\_variable\ \mbox{\hyperlink{classutils_1_1ThreadSafeQueue_aa8f60ba625a00977e004c6641325671e}{\_cv}};}
\DoxyCodeLine{00016\ }
\DoxyCodeLine{00017\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00018\ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classutils_1_1ThreadSafeQueue_a00347d38cfa085d97c67796779da2f33}{push}}(T\ value)\ \{}
\DoxyCodeLine{00019\ }
\DoxyCodeLine{00020\ \ \ \ \ \ \ \ \ \{}
\DoxyCodeLine{00021\ \ \ \ \ \ \ \ \ \ \ \ \ std::lock\_guard<std::mutex>\ lock(\mbox{\hyperlink{classutils_1_1ThreadSafeQueue_a43fef8c13f23363c48bac7a6a49a565b}{\_mutex}});}
\DoxyCodeLine{00022\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classutils_1_1ThreadSafeQueue_a970596f4c9a6d1a806b06d46807e06ee}{\_queue}}.push(std::move(value));}
\DoxyCodeLine{00023\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00024\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classutils_1_1ThreadSafeQueue_aa8f60ba625a00977e004c6641325671e}{\_cv}}.notify\_one();}
\DoxyCodeLine{00025\ \ \ \ \ \}}
\DoxyCodeLine{00026\ }
\DoxyCodeLine{00027\ \ \ \ \ T\ \mbox{\hyperlink{classutils_1_1ThreadSafeQueue_a0fc878c7c3ed27b4c65bcf277b99a48b}{wait\_and\_pop}}()\ \{}
\DoxyCodeLine{00028\ \ \ \ \ \ \ \ \ std::unique\_lock<std::mutex>\ lock(\mbox{\hyperlink{classutils_1_1ThreadSafeQueue_a43fef8c13f23363c48bac7a6a49a565b}{\_mutex}});}
\DoxyCodeLine{00029\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classutils_1_1ThreadSafeQueue_aa8f60ba625a00977e004c6641325671e}{\_cv}}.wait(lock,\ [\&]\ \{\ \textcolor{keywordflow}{return}\ !\mbox{\hyperlink{classutils_1_1ThreadSafeQueue_a970596f4c9a6d1a806b06d46807e06ee}{\_queue}}.empty();\ \});}
\DoxyCodeLine{00030\ \ \ \ \ \ \ \ \ T\ val\ =\ std::move(\mbox{\hyperlink{classutils_1_1ThreadSafeQueue_a970596f4c9a6d1a806b06d46807e06ee}{\_queue}}.front());}
\DoxyCodeLine{00031\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classutils_1_1ThreadSafeQueue_a970596f4c9a6d1a806b06d46807e06ee}{\_queue}}.pop();}
\DoxyCodeLine{00032\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ val;}
\DoxyCodeLine{00033\ \ \ \ \ \}}
\DoxyCodeLine{00034\ \};}
\DoxyCodeLine{00035\ \}\ \textcolor{comment}{//\ End\ utils\ namespace}}

\end{DoxyCode}
