Orocos Real-Time Toolkit  2.8.3
Thread.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jun 10 14:43:13 CEST 2002 Thread.hpp
3 
4  Thread.hpp - description
5  -------------------
6  begin : Mon June 10 2002
7  copyright : (C) 2002 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 #ifndef ORO_THREAD_HPP
39 #define ORO_THREAD_HPP
40 
41 // Our own package config headers.
42 #include "../rtt-config.h"
43 #include "fosi.h"
44 
45 #include "ThreadInterface.hpp"
46 #include "Mutex.hpp"
47 
48 #include <string>
49 
50 namespace RTT
51 {
52 
53  namespace os
54  {
110  {
111  friend void* thread_function(void* t);
112 
113  public:
114 
126  Thread(int scheduler, int priority, double period, unsigned cpu_affinity,
127  const std::string & name);
128 
129  virtual ~Thread();
130 
138  static void setStackSize(unsigned int ssize);
139 
145  static void setLockTimeoutNoPeriod(double timeout_in_s);
146 
153  static void setLockTimeoutPeriodFactor(double factor);
154 
155 
156  virtual bool start();
157 
158  virtual bool stop();
159 
164  void setStopTimeout(Seconds s);
165 
172  Seconds getStopTimeout() const;
173 
174  bool setPeriod(Seconds s);
175 
180  bool setPeriod(secs s, nsecs ns);
181 
185  bool setPeriod(TIME_SPEC p);
186 
191  void getPeriod(secs& s, nsecs& ns) const;
192 
193  virtual Seconds getPeriod() const;
194 
195  virtual nsecs getPeriodNS() const;
196 
197  virtual bool isPeriodic() const;
198 
199  virtual bool isRunning() const;
200 
201  virtual bool isActive() const;
202 
203  virtual const char* getName() const;
204 
205  virtual RTOS_TASK * getTask()
206  {
207  return &rtos_task;
208  }
209 
210  virtual const RTOS_TASK * getTask() const
211  {
212  return &rtos_task;
213  }
214 
215  virtual bool setScheduler(int sched_type);
216 
217  virtual int getScheduler() const;
218 
219  virtual bool setPriority(int priority);
220 
221  virtual int getPriority() const;
222 
223  virtual unsigned int getPid() const;
224 
230  virtual bool setCpuAffinity(unsigned cpu_affinity);
231 
235  virtual unsigned getCpuAffinity() const;
236 
237  virtual void yield();
238 
239  virtual void setMaxOverrun(int m);
240 
241  virtual int getMaxOverrun() const;
242 
243  virtual void setWaitPeriodPolicy(int p);
244 
245  protected:
251  void terminate();
252 
253  void emergencyStop();
254 
258  virtual void step();
259 
263  virtual void loop();
264 
268  virtual bool breakLoop();
269 
273  virtual bool initialize();
274 
278  virtual void finalize();
279  private:
280  Thread(const Thread&);
281 
282  void setup(int _priority, unsigned cpu_affinity, const std::string& name);
283 
287  void configure();
288 
289  static unsigned int default_stack_size;
290 
294  static double lock_timeout_no_period_in_s;
295 
299  static double lock_timeout_period_factor;
300 
304  int msched_type;
305 
310  bool active;
311 
315  bool prepareForExit;
316 
320  bool inloop;
321 
325  bool running;
326 
330  RTOS_TASK rtos_task;
331 
335  rt_sem_t sem;
336 
340  MutexRecursive breaker;
341 
346  int maxOverRun;
347 
351  NANO_TIME period;
352 
356  double stopTimeout;
357 
358 #ifdef OROPKG_OS_THREAD_SCOPE
359  // Pointer to Threadscope device
361 #endif
362  };
363 
364  }
365 }
366 
367 #endif
long long NANO_TIME
Definition: fosi.h:55
double Seconds
Seconds are stored as a double precision float.
Definition: Time.hpp:53
A Thread object executes user code in its own thread.
Definition: Thread.hpp:109
long secs
seconds as a signed long.
Definition: Time.hpp:57
#define RTT_API
Definition: rtt-config.h:97
void * thread_function(void *t)
Definition: Thread.cpp:75
virtual RTOS_TASK * getTask()
Get the RTOS_TASK pointer.
Definition: Thread.hpp:205
A thread which is being run.
virtual const RTOS_TASK * getTask() const
const version of the above.
Definition: Thread.hpp:210
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
An object oriented wrapper around a recursive mutex.
Definition: Mutex.hpp:208
long long nsecs
nanoseconds as a signed long long.
Definition: Time.hpp:69
A class representing a Digital Output device which can read or write a maximum of 32 bits at once...
Definition: fosi.h:62
struct timespec TIME_SPEC
Definition: fosi.h:97
cyg_sem_t rt_sem_t
Definition: fosi.h:131