GpCoreTools/InfiniteLoop.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of GpCoreTools.
00004 **
00005 **  This file may be distributed and/or modified under the terms of the
00006 **  GNU General Public License version 2 or 3 as published by the Free
00007 **  Software Foundation and appearing in the file LICENSE.GPL included
00008 **  in the packaging of this file.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00013 **  more details.
00014 **
00015 **  You should have received a copy of the GNU General Public License
00016 **  along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 **
00018 **  See http://www.geopsy.org for more information.
00019 **
00020 **  Created: 2009-06-27
00021 **  Authors:
00022 **    Marc Wathelet
00023 **    Marc Wathelet (LGIT, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef INFINITELOOP_H
00028 #define INFINITELOOP_H
00029 
00030 #include "GpCoreToolsDLLExport.h"
00031 
00032 namespace GpCoreTools {
00033 
00034 class GPCORETOOLS_EXPORT InfiniteLoop
00035 {
00036 public:
00037   InfiniteLoop();
00038   ~InfiniteLoop();
00039 
00040   inline void start();
00041   inline void stop();
00042   void wait();
00043   inline bool isRunning() const;
00044 protected:
00045   inline bool isTerminated() const;
00046   inline void setTerminated();
00047 private:
00048   enum State {NotRunning, Running, Terminate};
00049   volatile State _state;
00050 };
00051 
00052 inline void InfiniteLoop::start()
00053 {
00054   _state=Running;
00055 }
00056 
00057 inline void InfiniteLoop::stop()
00058 {
00059   if(_state==Running) {
00060     _state=Terminate;
00061   }
00062 }
00063 
00064 inline bool InfiniteLoop::isRunning() const
00065 {
00066   return _state!=NotRunning;
00067 }
00068 
00069 inline bool InfiniteLoop::isTerminated() const
00070 {
00071   return _state==Terminate;
00072 }
00073 
00074 inline void InfiniteLoop::setTerminated()
00075 {
00076   _state=NotRunning;
00077 }
00078 
00079 } // namespace GpCoreTools
00080 
00081 #endif // INFINITELOOP_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines