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  {
109  class RTT_API Thread: public ThreadInterface
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  protected:
289 
290  static unsigned int default_stack_size;
291 
296 
301 
306 
311  bool active;
312 
317 
321  bool inloop;
322 
326  bool running;
327 
332 
337 
342 
348 
353 
357  double stopTimeout;
358 
359 #ifdef OROPKG_OS_THREAD_SCOPE
360  // Pointer to Threadscope device
362 #endif
363  };
364 
365  }
366 }
367 
368 #endif
long long NANO_TIME
Definition: ecos/fosi.h:67
rt_sem_t sem
Definition: Thread.hpp:336
static unsigned int default_stack_size
Definition: Thread.hpp:290
double Seconds
Definition: os/Time.hpp:53
MutexRecursive breaker
Definition: Thread.hpp:341
long secs
Definition: os/Time.hpp:57
void * thread_function(void *t)
Definition: Thread.cpp:82
bool prepareForExit
Definition: Thread.hpp:316
virtual RTOS_TASK * getTask()
Definition: Thread.hpp:205
static double lock_timeout_period_factor
Definition: Thread.hpp:300
virtual const RTOS_TASK * getTask() const
Definition: Thread.hpp:210
static RTT_UNUSED bool setCpuAffinity(ThreadInterface *thread, const std::bitset< 16 > &cpu_affinity)
static double lock_timeout_no_period_in_s
Definition: Thread.hpp:295
static void yield(TaskContext *tc)
RTOS_TASK rtos_task
Definition: Thread.hpp:331
static std::bitset< 16 > getCpuAffinity(ThreadInterface *thread)
NANO_TIME period
Definition: Thread.hpp:352
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
An object oriented wrapper around a recursive mutex.
Definition: Mutex.hpp:218
long long nsecs
Definition: os/Time.hpp:69
struct timespec TIME_SPEC
Definition: ecos/fosi.h:109
double stopTimeout
Definition: Thread.hpp:357
cyg_sem_t rt_sem_t
Definition: ecos/fosi.h:143


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:37