\section{Critical\-Section\-Block Class Reference}
\label{classCriticalSectionBlock}\index{CriticalSectionBlock@{CriticalSectionBlock}}
{\tt \#include $<$Critical\-Section\-Block.H$>$}

\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf Critical\-Section\-Block} (critsec\_\-t $\ast$critsec)
\item 
bool {\bf checkonce} ()
\item 
{\bf $\sim$Critical\-Section\-Block} ()
\end{CompactItemize}
\subsection*{Private Attributes}
\begin{CompactItemize}
\item 
critsec\_\-t $\ast$ {\bf \_\-critsec}
\item 
char {\bf \_\-checkonce\-Hack\-Counter}
\end{CompactItemize}


\subsection{Detailed Description}
A Critical\-Section\-Block locks a critical section for the lifetime of the Critical\-Section\-Block.

The Critical\-Section\-Block gets a critical section and initially enters it, i.e. the constructor blocks until the section is free. The critical section is unlocked in the destructor.

The actual trick is, that if the Critical\-Section\-Block is created as automatic variable on the stack (complicated expression for {\em local variable\/}), C++ implicitly calls the destructor, whenever we leave the block it is created in.

Leaving the block may be due to a regular return, or an Exception or just falling off the edge, thus this automatically takes care of cleaning up the section which is especially handy if we expect Exceptions. Never forgotten-to-unlock critical sections again .. (isn't this cool ?)

Usage like: \small\begin{alltt}
 --------------------------------------------------------------------
 critsec\_t someCriticalSection;
 void foo () \{
     CriticalSectionBlock criticalSection(&someCriticalSection);
     //.. critical section protected ...
     myCriticalDataStructure = 42;
    // criticalSection is automatically released
 \}
 --------------------------------------------------------------------- 
 \end{alltt}\normalsize 


There is as well a macro available which utilizes this class to make it {\em really\/} easy to use and to read. People who have programmed Java reckognize this; use this in favour of the plain Critical\-Section\-Block because it improves readability a lot:

\small\begin{alltt}
 --------------------------------------------------------------------- 
 critsec\_t someCriticalSection;
 void foo () \{
     // ...
     synchronized (\&someCriticalSection) \{
         //.. critical section protected...
         myCriticalDataStructure = 42;
     \}
     // ...
 \}
 --------------------------------------------------------------------- 
 \end{alltt}\normalsize 


\begin{Desc}
\item[Author:]Henner Zeller $<${\tt H.Zeller@acm.org}$>$ \end{Desc}




Definition at line 70 of file Critical\-Section\-Block.H.

\subsection{Constructor \& Destructor Documentation}
\index{CriticalSectionBlock@{Critical\-Section\-Block}!CriticalSectionBlock@{CriticalSectionBlock}}
\index{CriticalSectionBlock@{CriticalSectionBlock}!CriticalSectionBlock@{Critical\-Section\-Block}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}Critical\-Section\-Block::Critical\-Section\-Block (critsec\_\-t $\ast$ {\em critsec})\hspace{0.3cm}{\tt  [inline]}}\label{classCriticalSectionBlock_a0}


Constructor locks the critical section.

Definition at line 83 of file Critical\-Section\-Block.H.\index{CriticalSectionBlock@{Critical\-Section\-Block}!~CriticalSectionBlock@{$\sim$CriticalSectionBlock}}
\index{~CriticalSectionBlock@{$\sim$CriticalSectionBlock}!CriticalSectionBlock@{Critical\-Section\-Block}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}Critical\-Section\-Block::$\sim${\bf Critical\-Section\-Block} ()\hspace{0.3cm}{\tt  [inline]}}\label{classCriticalSectionBlock_a2}


destructor automatically unlocks the critical section.

Definition at line 98 of file Critical\-Section\-Block.H.

\subsection{Member Function Documentation}
\index{CriticalSectionBlock@{Critical\-Section\-Block}!checkonce@{checkonce}}
\index{checkonce@{checkonce}!CriticalSectionBlock@{Critical\-Section\-Block}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool Critical\-Section\-Block::checkonce ()\hspace{0.3cm}{\tt  [inline]}}\label{classCriticalSectionBlock_a1}


don't use. Used internally for the {\bf synchronized()}{\rm (p.\,\pageref{CriticalSectionBlock_8H_a0})} \{ \} macro.

Definition at line 93 of file Critical\-Section\-Block.H.

\subsection{Field Documentation}
\index{CriticalSectionBlock@{Critical\-Section\-Block}!_checkonceHackCounter@{\_\-checkonceHackCounter}}
\index{_checkonceHackCounter@{\_\-checkonceHackCounter}!CriticalSectionBlock@{Critical\-Section\-Block}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}char {\bf Critical\-Section\-Block::\_\-checkonce\-Hack\-Counter}\hspace{0.3cm}{\tt  [private]}}\label{classCriticalSectionBlock_r1}


little hack, to make it possible to implement the {\bf synchronized()}{\rm (p.\,\pageref{CriticalSectionBlock_8H_a0})} macro with the for(;;) loop below.

Definition at line 77 of file Critical\-Section\-Block.H.\index{CriticalSectionBlock@{Critical\-Section\-Block}!_critsec@{\_\-critsec}}
\index{_critsec@{\_\-critsec}!CriticalSectionBlock@{Critical\-Section\-Block}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}critsec\_\-t$\ast$ {\bf Critical\-Section\-Block::\_\-critsec}\hspace{0.3cm}{\tt  [private]}}\label{classCriticalSectionBlock_r0}




Definition at line 72 of file Critical\-Section\-Block.H.

The documentation for this class was generated from the following file:\begin{CompactItemize}
\item 
include/c++/{\bf Critical\-Section\-Block.H}\end{CompactItemize}
