00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*- 00002 00003 // -- BEGIN LICENSE BLOCK ---------------------------------------------- 00004 // This file is part of FZIs ic_workspace. 00005 // 00006 // This program is free software licensed under the LGPL 00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3). 00008 // You can find a copy of this license in LICENSE folder in the top 00009 // directory of the source code. 00010 // 00011 // © Copyright 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany 00012 // 00013 // -- END LICENSE BLOCK ------------------------------------------------ 00014 00015 //---------------------------------------------------------------------- 00026 //---------------------------------------------------------------------- 00027 #ifndef ICL_CORE_LOGGING_THREAD_H_INCLUDED 00028 #define ICL_CORE_LOGGING_THREAD_H_INCLUDED 00029 00030 #include <icl_core/BaseTypes.h> 00031 #include <icl_core/os_thread.h> 00032 #include <icl_core/Noncopyable.h> 00033 #include "icl_core_logging/ImportExport.h" 00034 00035 namespace icl_core { 00036 namespace logging { 00037 00038 class ThreadImpl; 00039 00046 class ICL_CORE_LOGGING_IMPORT_EXPORT Thread : protected virtual icl_core::Noncopyable 00047 { 00048 public: 00053 Thread(icl_core::ThreadPriority priority = 0); 00054 00056 virtual ~Thread(); 00057 00064 bool execute() const { return m_execute; } 00065 00069 void join(); 00070 00077 virtual void run() = 0; 00078 00080 bool running() const { return !m_finished; } 00081 00087 bool start(); 00088 00094 void stop() { waitStarted(); m_execute = false; } 00095 00096 private: 00100 virtual void runThread(); 00101 00103 void waitStarted() const; 00104 00105 bool m_execute; 00106 bool m_finished; 00107 bool m_joined; 00108 bool m_starting; 00109 00110 ThreadImpl *m_impl; 00111 00112 // Declare thread implementations as friends so that they have access to the 00113 // RunThread() function! 00114 friend class ThreadImplLxrt33; 00115 friend class ThreadImplLxrt35; 00116 friend class ThreadImplLxrt38; 00117 friend class ThreadImplPosix; 00118 friend class ThreadImplWin32; 00119 }; 00120 00121 } 00122 } 00123 00124 #endif