\hypertarget{class_qore_1_1_thread_1_1_auto_write_lock}{}\doxysection{Qore\+::Thread\+::Auto\+Write\+Lock Class Reference}
\label{class_qore_1_1_thread_1_1_auto_write_lock}\index{Qore::Thread::AutoWriteLock@{Qore::Thread::AutoWriteLock}}


A helper class for the \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock}} class for exception-\/safe write lock handling.  


\doxysubsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\mbox{\hyperlink{class_qore_1_1_thread_1_1_auto_write_lock_aaf9bbd287ecdf11bf71321e32b8b7010}{constructor}} (\mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock}} rwl)
\begin{DoxyCompactList}\small\item\em Creates the \mbox{\hyperlink{class_qore_1_1_thread_1_1_auto_write_lock}{Auto\+Write\+Lock}} object based on the \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock}} argument passed and immediately calls \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a15face42a9f0634de3e2f835f8daa35b}{R\+W\+Lock\+::write\+Lock()}} \end{DoxyCompactList}\item 
\mbox{\hyperlink{class_qore_1_1_thread_1_1_auto_write_lock_ad3eef0401dbebb40cdb28530f5d8e482}{copy}} ()
\begin{DoxyCompactList}\small\item\em Throws an exception; objects of this class cannot be copied. \end{DoxyCompactList}\item 
\mbox{\hyperlink{class_qore_1_1_thread_1_1_auto_write_lock_acd1ebb811fb9ae507bce766a4cbbdac4}{destructor}} ()
\begin{DoxyCompactList}\small\item\em Calls \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a577f98df56071f39199c7ace72dc132d}{R\+W\+Lock\+::write\+Unlock()}} on the saved \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock}} and destroys the \mbox{\hyperlink{class_qore_1_1_thread_1_1_auto_write_lock}{Auto\+Write\+Lock}} object. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
A helper class for the \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock}} class for exception-\/safe write lock handling. 

\begin{DoxyParagraph}{Restrictions\+:}
\mbox{\hyperlink{group__parse__options_gade963e1fbbd1f5b2c777df7221512a1b}{Qore\+::\+P\+O\+\_\+\+N\+O\+\_\+\+T\+H\+R\+E\+A\+D\+\_\+\+C\+L\+A\+S\+S\+ES}}
\end{DoxyParagraph}
\mbox{\hyperlink{class_qore_1_1_thread_1_1_auto_write_lock}{Auto\+Write\+Lock}} objects, when used along with a \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock}} object, allow Qore programmers to safely acquire and release a write lock, even if exceptions are thrown or return statements are executed in the block where the \mbox{\hyperlink{class_qore_1_1_thread_1_1_auto_write_lock}{Auto\+Write\+Lock}} object is created.

\mbox{\hyperlink{class_qore_1_1_thread_1_1_auto_write_lock}{Auto\+Write\+Lock}} objects are helper objects that acquire a write lock for the lifetime of the \mbox{\hyperlink{class_qore_1_1_thread_1_1_auto_write_lock}{Auto\+Write\+Lock}} object. For this reason, it is only appropriate to assign an \mbox{\hyperlink{class_qore_1_1_thread_1_1_auto_write_lock}{Auto\+Write\+Lock}} object to a local variable, so when the local variable goes out of scope, the \mbox{\hyperlink{class_qore_1_1_thread_1_1_auto_write_lock}{Auto\+Write\+Lock}} object will be deleted and the write lock will be automatically released.

For example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{our RWLock rwl();}
\DoxyCodeLine{}
\DoxyCodeLine{sub check\_error(error) \{}
\DoxyCodeLine{    \textcolor{comment}{\# note that the write lock is acquired in the AutoWriteLock constructor, and}}
\DoxyCodeLine{    \textcolor{comment}{\# the write lock will be released as soon as the block is exited below.}}
\DoxyCodeLine{    \textcolor{comment}{\# (with either the throw statement or the return statement)}}
\DoxyCodeLine{    AutoWriteLock awl(rwl);}
\DoxyCodeLine{    \textcolor{keywordflow}{if} (error)}
\DoxyCodeLine{        throw \textcolor{stringliteral}{"ERROR"}, \textcolor{stringliteral}{"sorry, an error happened"};}
\DoxyCodeLine{}
\DoxyCodeLine{    \textcolor{keywordflow}{return} \textcolor{stringliteral}{"OK"};}
\DoxyCodeLine{\}}
\end{DoxyCode}


\begin{DoxyNote}{Note}
This class is not available with the \mbox{\hyperlink{group__parse__options_gade963e1fbbd1f5b2c777df7221512a1b}{P\+O\+\_\+\+N\+O\+\_\+\+T\+H\+R\+E\+A\+D\+\_\+\+C\+L\+A\+S\+S\+ES}} parse option 
\end{DoxyNote}


\doxysubsection{Member Function Documentation}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_auto_write_lock_aaf9bbd287ecdf11bf71321e32b8b7010}\label{class_qore_1_1_thread_1_1_auto_write_lock_aaf9bbd287ecdf11bf71321e32b8b7010}} 
\index{Qore::Thread::AutoWriteLock@{Qore::Thread::AutoWriteLock}!constructor@{constructor}}
\index{constructor@{constructor}!Qore::Thread::AutoWriteLock@{Qore::Thread::AutoWriteLock}}
\doxysubsubsection{\texorpdfstring{constructor()}{constructor()}}
{\footnotesize\ttfamily Qore\+::\+Thread\+::\+Auto\+Write\+Lock\+::constructor (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock}}}]{rwl }\end{DoxyParamCaption})}



Creates the \mbox{\hyperlink{class_qore_1_1_thread_1_1_auto_write_lock}{Auto\+Write\+Lock}} object based on the \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock}} argument passed and immediately calls \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a15face42a9f0634de3e2f835f8daa35b}{R\+W\+Lock\+::write\+Lock()}} 

The \mbox{\hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock}} object immediately calls \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a15face42a9f0634de3e2f835f8daa35b}{R\+W\+Lock\+::write\+Lock()}} on the \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock}} object passed, and saves it so it can be released when the \mbox{\hyperlink{class_qore_1_1_thread_1_1_auto_read_lock}{Auto\+Read\+Lock}} object is destroyed.

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}{0}
\DoxyCodeLine{AutoWriteLock awl(rwlock);}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em T\+H\+R\+E\+A\+D-\/\+D\+E\+A\+D\+L\+O\+CK} & A deadlock was detected while trying to acquire the lock \\
\hline
{\em L\+O\+C\+K-\/\+E\+R\+R\+OR} & \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a15face42a9f0634de3e2f835f8daa35b}{R\+W\+Lock\+::write\+Lock()}} called while already holding the read lock, object deleted in another thread, etc. \\
\hline
\end{DoxyExceptions}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_auto_write_lock_ad3eef0401dbebb40cdb28530f5d8e482}\label{class_qore_1_1_thread_1_1_auto_write_lock_ad3eef0401dbebb40cdb28530f5d8e482}} 
\index{Qore::Thread::AutoWriteLock@{Qore::Thread::AutoWriteLock}!copy@{copy}}
\index{copy@{copy}!Qore::Thread::AutoWriteLock@{Qore::Thread::AutoWriteLock}}
\doxysubsubsection{\texorpdfstring{copy()}{copy()}}
{\footnotesize\ttfamily Qore\+::\+Thread\+::\+Auto\+Write\+Lock\+::copy (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Throws an exception; objects of this class cannot be copied. 


\begin{DoxyExceptions}{Exceptions}
{\em A\+U\+T\+O\+W\+R\+I\+T\+E\+L\+O\+C\+K-\/\+C\+O\+P\+Y-\/\+E\+R\+R\+OR} & objects of this class cannot be copied \\
\hline
\end{DoxyExceptions}
\mbox{\Hypertarget{class_qore_1_1_thread_1_1_auto_write_lock_acd1ebb811fb9ae507bce766a4cbbdac4}\label{class_qore_1_1_thread_1_1_auto_write_lock_acd1ebb811fb9ae507bce766a4cbbdac4}} 
\index{Qore::Thread::AutoWriteLock@{Qore::Thread::AutoWriteLock}!destructor@{destructor}}
\index{destructor@{destructor}!Qore::Thread::AutoWriteLock@{Qore::Thread::AutoWriteLock}}
\doxysubsubsection{\texorpdfstring{destructor()}{destructor()}}
{\footnotesize\ttfamily Qore\+::\+Thread\+::\+Auto\+Write\+Lock\+::destructor (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Calls \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a577f98df56071f39199c7ace72dc132d}{R\+W\+Lock\+::write\+Unlock()}} on the saved \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock}} and destroys the \mbox{\hyperlink{class_qore_1_1_thread_1_1_auto_write_lock}{Auto\+Write\+Lock}} object. 

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}{0}
\DoxyCodeLine{delete awl;}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em L\+O\+C\+K-\/\+E\+R\+R\+OR} & \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock_a577f98df56071f39199c7ace72dc132d}{R\+W\+Lock\+::write\+Unlock()}} called while not holding the write lock, \mbox{\hyperlink{class_qore_1_1_thread_1_1_r_w_lock}{R\+W\+Lock}} object deleted in another thread, etc \\
\hline
\end{DoxyExceptions}
