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
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
00192 virtual unsigned int getPid() const;
00198 virtual bool setCpuAffinity(unsigned cpu_affinity);
00199
00203 virtual unsigned getCpuAffinity() const;
00204
00205 virtual void yield();
00206
00207 virtual void setMaxOverrun(int m);
00208
00209 virtual int getMaxOverrun() const;
00210
00211 virtual void setWaitPeriodPolicy(int p);
00212
00213 protected:
00219 void terminate();
00220
00221 void emergencyStop();
00222
00226 virtual void step();
00227
00231 virtual void loop();
00232
00236 virtual bool breakLoop();
00237
00241 virtual bool initialize();
00242
00246 virtual void finalize();
00247 private:
00248 Thread(const Thread&);
00249
00250 void setup(int _priority, unsigned cpu_affinity, const std::string& name);
00251
00255 void configure();
00256
00257 static unsigned int default_stack_size;
00258
00262 int msched_type;
00263
00268 bool active;
00269
00273 bool prepareForExit;
00274
00278 bool inloop;
00279
00283 bool running;
00284
00288 RTOS_TASK rtos_task;
00289
00293 rt_sem_t sem;
00294
00298 MutexRecursive breaker;
00299
00304 int maxOverRun;
00305
00309 NANO_TIME period;
00310
00311 #ifdef OROPKG_OS_THREAD_SCOPE
00312
00313 dev::DigitalOutInterface * d;
00314 #endif
00315 };
00316
00317 }
00318 }
00319
00320 #endif