Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef ORO_THREAD_HPP
00039 #define ORO_THREAD_HPP
00040
00041
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
00144 static void setLockTimeoutNoPeriod(double timeout_in_s);
00145
00152 static void setLockTimeoutPeriodFactor(double factor);
00153
00154
00155 virtual bool start();
00156
00157 virtual bool stop();
00158
00163 void setStopTimeout(Seconds s);
00164
00171 Seconds getStopTimeout() const;
00172
00173 bool setPeriod(Seconds s);
00174
00179 bool setPeriod(secs s, nsecs ns);
00180
00184 bool setPeriod(TIME_SPEC p);
00185
00190 void getPeriod(secs& s, nsecs& ns) const;
00191
00192 virtual Seconds getPeriod() const;
00193
00194 virtual nsecs getPeriodNS() const;
00195
00196 virtual bool isPeriodic() const;
00197
00198 virtual bool isRunning() const;
00199
00200 virtual bool isActive() const;
00201
00202 virtual const char* getName() const;
00203
00204 virtual RTOS_TASK * getTask()
00205 {
00206 return &rtos_task;
00207 }
00208
00209 virtual const RTOS_TASK * getTask() const
00210 {
00211 return &rtos_task;
00212 }
00213
00214 virtual bool setScheduler(int sched_type);
00215
00216 virtual int getScheduler() const;
00217
00218 virtual bool setPriority(int priority);
00219
00220 virtual int getPriority() const;
00221
00222 virtual unsigned int getPid() const;
00228 virtual bool setCpuAffinity(unsigned cpu_affinity);
00229
00233 virtual unsigned getCpuAffinity() const;
00234
00235 virtual void yield();
00236
00237 virtual void setMaxOverrun(int m);
00238
00239 virtual int getMaxOverrun() const;
00240
00241 virtual void setWaitPeriodPolicy(int p);
00242
00243 protected:
00249 void terminate();
00250
00251 void emergencyStop();
00252
00256 virtual void step();
00257
00261 virtual void loop();
00262
00266 virtual bool breakLoop();
00267
00271 virtual bool initialize();
00272
00276 virtual void finalize();
00277 private:
00278 Thread(const Thread&);
00279
00280 void setup(int _priority, unsigned cpu_affinity, const std::string& name);
00281
00285 void configure();
00286
00287 static unsigned int default_stack_size;
00288
00292 static double lock_timeout_no_period_in_s;
00293
00297 static double lock_timeout_period_factor;
00298
00302 int msched_type;
00303
00308 bool active;
00309
00313 bool prepareForExit;
00314
00318 bool inloop;
00319
00323 bool running;
00324
00328 RTOS_TASK rtos_task;
00329
00333 rt_sem_t sem;
00334
00338 MutexRecursive breaker;
00339
00344 int maxOverRun;
00345
00349 NANO_TIME period;
00350
00354 double stopTimeout;
00355
00356 #ifdef OROPKG_OS_THREAD_SCOPE
00357
00358 dev::DigitalOutInterface * d;
00359 #endif
00360 };
00361
00362 }
00363 }
00364
00365 #endif