MetriVis Overview | Download | User Manual | Development
Reference Overview | Design Documentation | Reference Backend | Reference Frontend

src/pattern/Thread.h

Go to the documentation of this file.
00001 /*
00002  *   MetriVis - Metrics Visualization Application
00003  *
00004  *
00005  *   License notice:
00006  *
00007  *   This program is free software: you can redistribute it and/or modify
00008  *   it under the terms of the GNU General Public License as published by
00009  *   the Free Software Foundation, either version 3 of the License, or
00010  *   (at your option) any later version.
00011  *
00012  *   This program is distributed in the hope that it will be useful,
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *   GNU General Public License for more details.
00016  *
00017  *   You should have received a copy of the GNU General Public License
00018  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  */
00021 
00022 #ifndef _METRIVIS_THREAD_H
00023 #define _METRIVIS_THREAD_H
00024 
00032 #include <boost/thread/thread.hpp>
00033 #include <boost/thread/mutex.hpp>
00034 #include <string>
00035 
00036 
00037 namespace metrivis {
00038 
00039 
00086 class Thread {
00087 
00088 public:
00092   Thread();
00093 
00097   virtual ~Thread();
00098 
00107   virtual int Init();
00108 
00115   int Start();
00116 
00124   int Stop();
00125 
00133   int StopBlocking();
00134 
00143   virtual int Uninit();
00144 
00145 
00151   int RunBlocking();
00152 
00153 
00159   void Wait();
00160 
00165   inline boost::thread& thread() const {
00166     return *thread_;
00167   }
00168 
00173   inline bool IsRunning() const {
00174     return (internal_state_ == Thread::RUNNING);
00175   }
00176 
00181   inline void set_name(const std::string& name) {
00182     name_ = name;
00183   }
00184 
00189   inline const std::string& name() const {
00190     return name_;
00191   }
00192 
00193 
00194 protected:
00195 
00210   virtual void Run() = 0;
00211 
00212 
00213 private:
00214 
00220   void InternalRun();
00221 
00222 
00223 protected:
00224 
00225   volatile bool running_;            
00226 
00227 
00228 private:
00229 
00236   enum State {
00237     UNUSED = 0,
00238     INITIALIZED,
00239     RUNNING
00240   };
00241   State internal_state_;             
00242 
00243   boost::thread* thread_;            
00244   boost::mutex run_mutex_;           
00245 
00246   std::string name_;                 
00247 };
00248 
00249 } // namespace metrivis
00250 
00251 #endif //_METRIVIS_THREAD_H

Generated on Fri Feb 29 16:47:19 2008 for MetriVis by  doxygen 1.5.3