Thread.h
Go to the documentation of this file.
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 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00030 //----------------------------------------------------------------------
00031 #ifndef ICL_CORE_THREAD_THREAD_H_INCLUDED
00032 #define ICL_CORE_THREAD_THREAD_H_INCLUDED
00033 
00034 #include <icl_core/BaseTypes.h>
00035 #include <icl_core/Noncopyable.h>
00036 #include <icl_core/TimeSpan.h>
00037 #include <icl_core/TimeStamp.h>
00038 #include <icl_core/os_thread.h>
00039 
00040 #include "icl_core_thread/ImportExport.h"
00041 #include "icl_core_thread/Mutex.h"
00042 
00043 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00044 # include "icl_core/Deprecate.h"
00045 #endif
00046 
00047 namespace icl_core {
00048 namespace thread {
00049 
00050 class ThreadImpl;
00051 
00077 class ICL_CORE_THREAD_IMPORT_EXPORT Thread : protected virtual icl_core::Noncopyable
00078 {
00079 public:
00083   Thread(const icl_core::String& description, icl_core::ThreadPriority priority = 0);
00084 
00087   virtual ~Thread();
00088 
00096   void cancel();
00097 
00105   bool checkHardRealtime();
00106 
00109   icl_core::String getDescription() const;
00110 
00117   bool execute() const { return m_execute; }
00118 
00121   bool isHardRealtime() const;
00122 
00126   bool executesHardRealtime() const;
00127 
00131   void join();
00132 
00135   icl_core::ThreadPriority priority() const;
00136 
00141   virtual void onStop() { }
00142 
00149   virtual void run() = 0;
00150 
00153   bool running() const { return !m_finished; }
00154 
00161   void setDescription(const icl_core::String& description);
00162 
00168   bool setHardRealtime(bool hard_realtime = true);
00169 
00175   bool setPriority(icl_core::ThreadPriority priority);
00176 
00182   bool start();
00183 
00189   void stop() { waitStarted(); m_execute = false; }
00190 
00193   icl_core::ThreadId threadId() const;
00194 
00199   const char *threadInfo() const { return m_thread_info.c_str(); }
00200 
00204   bool threadSelf() const
00205   {
00206     waitStarted();
00207     return icl_core::os::threadSelf() == threadId();
00208   }
00209 
00214   bool wait();
00215 
00222   bool wait(const icl_core::TimeStamp& timeout);
00223 
00230   bool wait(const icl_core::TimeSpan& timeout);
00231 
00234   static icl_core::ThreadId selfId() { return icl_core::os::threadSelf(); }
00235 
00237 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00238 
00247   ICL_CORE_VC_DEPRECATE_STYLE void Cancel() ICL_CORE_GCC_DEPRECATE_STYLE;
00248 
00252   ICL_CORE_VC_DEPRECATE_STYLE bool CheckHardRealtime() ICL_CORE_GCC_DEPRECATE_STYLE;
00253 
00257   ICL_CORE_VC_DEPRECATE_STYLE icl_core::String Description() const ICL_CORE_GCC_DEPRECATE_STYLE;
00258 
00263   ICL_CORE_VC_DEPRECATE_STYLE bool Execute() const ICL_CORE_GCC_DEPRECATE_STYLE;
00264 
00268   ICL_CORE_VC_DEPRECATE_STYLE bool IsHardRealtime() const ICL_CORE_GCC_DEPRECATE_STYLE;
00269 
00274   ICL_CORE_VC_DEPRECATE_STYLE bool ExecutesHardRealtime() const
00275     ICL_CORE_GCC_DEPRECATE_STYLE;
00276 
00280   ICL_CORE_VC_DEPRECATE_STYLE void Join() ICL_CORE_GCC_DEPRECATE_STYLE;
00281 
00285   ICL_CORE_VC_DEPRECATE_STYLE icl_core::ThreadPriority Priority() const
00286     ICL_CORE_GCC_DEPRECATE_STYLE;
00287 
00291   ICL_CORE_VC_DEPRECATE_STYLE bool Running() const ICL_CORE_GCC_DEPRECATE_STYLE;
00292 
00296   ICL_CORE_VC_DEPRECATE_STYLE void SetDescription(const icl_core::String& description)
00297     ICL_CORE_GCC_DEPRECATE_STYLE;
00298 
00302   ICL_CORE_VC_DEPRECATE_STYLE bool SetHardRealtime(bool hard_realtime = true)
00303     ICL_CORE_GCC_DEPRECATE_STYLE;
00304 
00308   ICL_CORE_VC_DEPRECATE_STYLE bool SetPriority(icl_core::ThreadPriority priority)
00309     ICL_CORE_GCC_DEPRECATE_STYLE;
00310 
00314   ICL_CORE_VC_DEPRECATE_STYLE bool Start() ICL_CORE_GCC_DEPRECATE_STYLE;
00315 
00319   ICL_CORE_VC_DEPRECATE_STYLE void Stop() ICL_CORE_GCC_DEPRECATE_STYLE;
00320 
00324   ICL_CORE_VC_DEPRECATE_STYLE icl_core::ThreadId ThreadId() const ICL_CORE_GCC_DEPRECATE_STYLE;
00325 
00330   ICL_CORE_VC_DEPRECATE_STYLE const char *ThreadInfo() const ICL_CORE_GCC_DEPRECATE_STYLE;
00331 
00336   ICL_CORE_VC_DEPRECATE_STYLE bool ThreadSelf() const ICL_CORE_GCC_DEPRECATE_STYLE;
00337 
00341   ICL_CORE_VC_DEPRECATE_STYLE bool Wait() ICL_CORE_GCC_DEPRECATE_STYLE;
00342 
00347   ICL_CORE_VC_DEPRECATE_STYLE bool Wait(const icl_core::TimeStamp& timeout)
00348     ICL_CORE_GCC_DEPRECATE_STYLE;
00349 
00354   ICL_CORE_VC_DEPRECATE_STYLE bool Wait(const icl_core::TimeSpan& timeout)
00355     ICL_CORE_GCC_DEPRECATE_STYLE;
00356 
00360   static ICL_CORE_VC_DEPRECATE_STYLE icl_core::ThreadId SelfId()
00361     ICL_CORE_GCC_DEPRECATE_STYLE;
00362 
00363 #endif
00364 
00365 
00366 private:
00371   virtual void makePeriodic();
00372 
00376   void runThread();
00377 
00380   void waitStarted() const;
00381 
00383 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00384 
00388   ICL_CORE_VC_DEPRECATE_STYLE void RunThread() ICL_CORE_GCC_DEPRECATE_STYLE;
00389 
00393   ICL_CORE_VC_DEPRECATE_STYLE void WaitStarted() const ICL_CORE_GCC_DEPRECATE_STYLE;
00394 
00395 #endif
00396 
00397 
00398   bool m_execute;
00399   bool m_finished;
00400   bool m_joined;
00401   bool m_starting;
00402 
00403   icl_core::String m_thread_info;
00404   icl_core::ThreadPriority m_priority;
00405 
00406   Mutex m_thread_mutex;
00407 
00408   ThreadImpl *m_impl;
00409 
00410   // Declare thread implementations as friends so that they have
00411   // access to the runThread() function!
00412   friend class ThreadImplLxrt33;
00413   friend class ThreadImplLxrt35;
00414   friend class ThreadImplLxrt38;
00415   friend class ThreadImplPosix;
00416   friend class ThreadImplWin32;
00417 };
00418 
00419 }
00420 }
00421 
00422 #endif


fzi_icl_core
Author(s):
autogenerated on Thu Jun 6 2019 20:22:24