Orocos Real-Time Toolkit
2.5.0
|
00001 /*************************************************************************** 00002 tag: Peter Soetens Mon Jun 10 14:43:13 CEST 2002 Thread.hpp 00003 00004 Thread.hpp - description 00005 ------------------- 00006 begin : Mon June 10 2002 00007 copyright : (C) 2002 Peter Soetens 00008 email : peter.soetens@mech.kuleuven.ac.be 00009 00010 *************************************************************************** 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of the GNU General Public * 00013 * License as published by the Free Software Foundation; * 00014 * version 2 of the License. * 00015 * * 00016 * As a special exception, you may use this file as part of a free * 00017 * software library without restriction. Specifically, if other files * 00018 * instantiate templates or use macros or inline functions from this * 00019 * file, or you compile this file and link it with other files to * 00020 * produce an executable, this file does not by itself cause the * 00021 * resulting executable to be covered by the GNU General Public * 00022 * License. This exception does not however invalidate any other * 00023 * reasons why the executable file might be covered by the GNU General * 00024 * Public License. * 00025 * * 00026 * This library is distributed in the hope that it will be useful, * 00027 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00028 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00029 * Lesser General Public License for more details. * 00030 * * 00031 * You should have received a copy of the GNU General Public * 00032 * License along with this library; if not, write to the Free Software * 00033 * Foundation, Inc., 59 Temple Place, * 00034 * Suite 330, Boston, MA 02111-1307 USA * 00035 * * 00036 ***************************************************************************/ 00037 00038 #ifndef ORO_THREAD_HPP 00039 #define ORO_THREAD_HPP 00040 00041 // Our own package config headers. 00042 #include "../rtt-config.h" 00043 #include "fosi.h" 00044 00045 #include "ThreadInterface.hpp" 00046 #include "Mutex.hpp" 00047 00048 #include <string> 00049 00050 namespace RTT 00051 { 00052 00053 namespace os 00054 { 00109 class RTT_API Thread: public ThreadInterface 00110 { 00111 friend void* thread_function(void* t); 00112 00113 public: 00114 00125 Thread(int scheduler, int priority, double period, unsigned cpu_affinity, 00126 const std::string & name); 00127 00128 virtual ~Thread(); 00129 00137 static void setStackSize(unsigned int ssize); 00138 00139 virtual bool start(); 00140 00141 virtual bool stop(); 00142 00143 bool setPeriod(Seconds s); 00144 00149 bool setPeriod(secs s, nsecs ns); 00150 00154 bool setPeriod(TIME_SPEC p); 00155 00160 void getPeriod(secs& s, nsecs& ns) const; 00161 00162 virtual Seconds getPeriod() const; 00163 00164 virtual nsecs getPeriodNS() const; 00165 00166 virtual bool isPeriodic() const; 00167 00168 virtual bool isRunning() const; 00169 00170 virtual bool isActive() const; 00171 00172 virtual const char* getName() const; 00173 00174 virtual RTOS_TASK * getTask() 00175 { 00176 return &rtos_task; 00177 } 00178 00179 virtual const RTOS_TASK * getTask() const 00180 { 00181 return &rtos_task; 00182 } 00183 00184 virtual bool setScheduler(int sched_type); 00185 00186 virtual int getScheduler() const; 00187 00188 virtual bool setPriority(int priority); 00189 00190 virtual int getPriority() const; 00191 00197 virtual bool setCpuAffinity(unsigned cpu_affinity); 00198 00202 virtual unsigned getCpuAffinity() const; 00203 00204 virtual void yield(); 00205 00206 virtual void setMaxOverrun(int m); 00207 00208 virtual int getMaxOverrun() const; 00209 00210 virtual void setWaitPeriodPolicy(int p); 00211 00212 protected: 00218 void terminate(); 00219 00220 void emergencyStop(); 00221 00225 virtual void step(); 00226 00230 virtual void loop(); 00231 00235 virtual bool breakLoop(); 00236 00240 virtual bool initialize(); 00241 00245 virtual void finalize(); 00246 private: 00247 Thread(const Thread&); 00248 00249 void setup(int _priority, unsigned cpu_affinity, const std::string& name); 00250 00254 void configure(); 00255 00256 static unsigned int default_stack_size; 00257 00261 int msched_type; 00262 00267 bool active; 00268 00272 bool prepareForExit; 00273 00277 bool inloop; 00278 00282 bool running; 00283 00287 RTOS_TASK rtos_task; 00288 00292 rt_sem_t sem; 00293 00297 MutexRecursive breaker; 00298 00303 int maxOverRun; 00304 00308 NANO_TIME period; 00309 00310 #ifdef OROPKG_OS_THREAD_SCOPE 00311 // Pointer to Threadscope device 00312 dev::DigitalOutInterface * d; 00313 #endif 00314 }; 00315 00316 } 00317 } 00318 00319 #endif