\hypertarget{classTimeSlice}{
\section{TimeSlice Class Reference}
\label{classTimeSlice}\index{TimeSlice@{TimeSlice}}
}


A class for computing whether some processing is taking too long.  




{\ttfamily \#include $<$time\_\-slice.hh$>$}

\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{classTimeSlice_af1da21ad588c230ba4f0eebcf719a00f}{TimeSlice} (uint32\_\-t usec\_\-limit, size\_\-t test\_\-iter\_\-frequency)
\begin{DoxyCompactList}\small\item\em Constructor for a given time limit and test frequency. \item\end{DoxyCompactList}\item 
\hypertarget{classTimeSlice_aace12b8e43110ac0d545a01b0d2e2b02}{
void \hyperlink{classTimeSlice_aace12b8e43110ac0d545a01b0d2e2b02}{reset} ()}
\label{classTimeSlice_aace12b8e43110ac0d545a01b0d2e2b02}

\begin{DoxyCompactList}\small\item\em Reset \hyperlink{protocolthe-p}{the} \hyperlink{classTimeSlice}{TimeSlice} object. \item\end{DoxyCompactList}\item 
bool \hyperlink{classTimeSlice_a3d53c5ddd0e96c3b2d826119078eb6e8}{is\_\-expired} ()
\begin{DoxyCompactList}\small\item\em Test if \hyperlink{protocolthe-p}{the} time slice has expired. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Private Attributes}
\begin{DoxyCompactItemize}
\item 
\hypertarget{classTimeSlice_ae812195b922ae4de7a7e9e21067b1163}{
\hyperlink{classTimeVal}{TimeVal} {\bfseries \_\-time\_\-slice\_\-limit}}
\label{classTimeSlice_ae812195b922ae4de7a7e9e21067b1163}

\item 
\hypertarget{classTimeSlice_ac4e84762a79ac89dd86261cb47de954e}{
const size\_\-t {\bfseries \_\-test\_\-iter\_\-frequency}}
\label{classTimeSlice_ac4e84762a79ac89dd86261cb47de954e}

\item 
\hypertarget{classTimeSlice_a1e06f572c765142f5c7cfea4c6f7bb69}{
\hyperlink{classTimeVal}{TimeVal} {\bfseries \_\-time\_\-slice\_\-start}}
\label{classTimeSlice_a1e06f572c765142f5c7cfea4c6f7bb69}

\item 
\hypertarget{classTimeSlice_a83720de5604d0d6cafa0e3b14bea8a2a}{
size\_\-t {\bfseries \_\-remain\_\-iter}}
\label{classTimeSlice_a83720de5604d0d6cafa0e3b14bea8a2a}

\end{DoxyCompactItemize}


\subsection{Detailed Description}
A class for computing whether some processing is taking too long. This class can be used to compute whether some processing is taking too long time to complete. It is up to \hyperlink{protocolthe-p}{the} program that uses \hyperlink{classTimeSlice}{TimeSlice} to check whether \hyperlink{protocolthe-p}{the} processing is taking too long, and suspend processing of that task if necessary.

Example of usage: 
\begin{DoxyPre}
    \hyperlink{classTimeSlice}{TimeSlice} time\_slice(100000, 20); // 100ms, test every 20th iteration\end{DoxyPre}



\begin{DoxyPre}    for (size\_t i = 0; i < 1000000000; i++) \{
        if (time\_slice.is\_expired()) \{
            // Stop processing.
            // Schedule a timer after 0 ms to continue processing.
            // If needed, save state to continue from here.
            return;
        \}
        // Do something CPU-hungry
    \}
    time\_slice.reset(); // Prepare it again for later usage if needed
\end{DoxyPre}
 

\subsection{Constructor \& Destructor Documentation}
\hypertarget{classTimeSlice_af1da21ad588c230ba4f0eebcf719a00f}{
\index{TimeSlice@{TimeSlice}!TimeSlice@{TimeSlice}}
\index{TimeSlice@{TimeSlice}!TimeSlice@{TimeSlice}}
\subsubsection[{TimeSlice}]{\setlength{\rightskip}{0pt plus 5cm}TimeSlice::TimeSlice (
\begin{DoxyParamCaption}
\item[{uint32\_\-t}]{usec\_\-limit, }
\item[{size\_\-t}]{test\_\-iter\_\-frequency}
\end{DoxyParamCaption}
)}}
\label{classTimeSlice_af1da21ad588c230ba4f0eebcf719a00f}


Constructor for a given time limit and test frequency. 

Create a \hyperlink{classTimeSlice}{TimeSlice} object that will measure time slices with given frequency of testing. The time slice is measured once in test\_\-iter\_\-frequency times when method \hyperlink{classTimeSlice_a3d53c5ddd0e96c3b2d826119078eb6e8}{is\_\-expired()} is called.


\begin{DoxyParams}{Parameters}
{\em usec\_\-limit} & \hyperlink{protocolthe-p}{the} time slice to measure in microseconds. \\
\hline
{\em test\_\-iter\_\-frequency} & \hyperlink{protocolthe-p}{the} frequency of measuring \hyperlink{protocolthe-p}{the} time slice. \\
\hline
\end{DoxyParams}


\subsection{Member Function Documentation}
\hypertarget{classTimeSlice_a3d53c5ddd0e96c3b2d826119078eb6e8}{
\index{TimeSlice@{TimeSlice}!is\_\-expired@{is\_\-expired}}
\index{is\_\-expired@{is\_\-expired}!TimeSlice@{TimeSlice}}
\subsubsection[{is\_\-expired}]{\setlength{\rightskip}{0pt plus 5cm}bool TimeSlice::is\_\-expired (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}inline\mbox{]}}}}
\label{classTimeSlice_a3d53c5ddd0e96c3b2d826119078eb6e8}


Test if \hyperlink{protocolthe-p}{the} time slice has expired. 

If \hyperlink{protocolthe-p}{the} time slice has expired, automatically prepare this object to start measuring again \hyperlink{protocolthe-p}{the} time slice.

\begin{DoxyReturn}{Returns}
true if \hyperlink{protocolthe-p}{the} time slice has expired, otherwise false. 
\end{DoxyReturn}


The documentation for this class was generated from the following files:\begin{DoxyCompactItemize}
\item 
/home/greearb/git/xorp.ct.github/xorp/libxorp/time\_\-slice.hh\item 
/home/greearb/git/xorp.ct.github/xorp/libxorp/time\_\-slice.cc\end{DoxyCompactItemize}
