Orocos Real-Time Toolkit  2.8.3
Thread.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon May 10 19:10:28 CEST 2004 Thread.cxx
3 
4  Thread.cxx - description
5  -------------------
6  begin : Mon May 10 2004
7  copyright : (C) 2004 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 
39 #include "Thread.hpp"
40 #include "../Time.hpp"
41 #include "threads.hpp"
42 #include "../Logger.hpp"
43 #include "MutexLock.hpp"
44 #include "MainThread.hpp"
45 
46 #include "../rtt-config.h"
47 #include "../internal/CatchConfig.hpp"
48 
49 #ifdef OROPKG_OS_THREAD_SCOPE
50 # include "../extras/dev/DigitalOutInterface.hpp"
51 #define SCOPE_ON if ( task->d ) task->d->switchOn( bit );
52 #define SCOPE_OFF if ( task->d ) task->d->switchOff( bit );
53 #else
54 #define SCOPE_ON
55 #define SCOPE_OFF
56 #endif
57 
58 namespace RTT {
59  namespace os
60  {
61  using RTT::Logger;
62 
63  unsigned int Thread::default_stack_size = 0;
64 
65  double Thread::lock_timeout_no_period_in_s = 1.0;
66 
67  double Thread::lock_timeout_period_factor = 10.0;
68 
69  void Thread::setStackSize(unsigned int ssize) { default_stack_size = ssize; }
70 
71  void Thread::setLockTimeoutNoPeriod(double timeout_in_s) { lock_timeout_no_period_in_s = timeout_in_s; }
72 
73  void Thread::setLockTimeoutPeriodFactor(double factor) { lock_timeout_period_factor = factor; }
74 
75  void *thread_function(void* t)
76  {
80  Thread* task = static_cast<os::Thread*> (t);
81  Logger::In in(task->getName());
82 
83  task->configure();
84 
85  // signal to setup() that we're created.
86  rtos_sem_signal(&(task->sem));
87 
88  // This lock forces setup(), which holds the lock, to continue.
89  { MutexLock lock(task->breaker); }
90 #ifdef OROPKG_OS_THREAD_SCOPE
91  // order thread scope toggle bit on thread number
92  unsigned int bit = task->threadNumber();
93 #endif
94  SCOPE_OFF
95 
96  int overruns = 0, cur_sched = task->msched_type;
97  NANO_TIME cur_period = task->period;
98 
99  while (!task->prepareForExit)
100  {
101  TRY(
105  while (1)
106  {
107  if (!task->active || (task->active && task->period == 0) || !task->running )
108  {
109  // consider this the 'configuration or waiting for command state'
110  if (task->period != 0) {
111  overruns = 0;
112  // drop out of periodic mode:
113  rtos_task_set_period(task->getTask(), 0);
114  }
115  rtos_sem_wait(&(task->sem)); // wait for command.
116  task->configure(); // check for reconfigure
117  if (task->prepareForExit) // check for exit
118  {
119  break; // break while(1) {}
120  }
121  // end of configuration
122  }
123  // This is the running state. Only enter if a task is running
124  if ( task->running )
125  {
126  if (task->period != 0) // periodic
127  {
128  MutexLock lock(task->breaker);
129  while(task->running && !task->prepareForExit )
130  {
131  TRY
132  (
133  SCOPE_ON
134  task->step(); // one cycle
135  SCOPE_OFF
136  )
137  CATCH_ALL
138  (
139  SCOPE_OFF
140  throw;
141  )
142 
143  // Check changes in period
144  if ( cur_period != task->period) {
145  // reconfigure period before going to sleep
146  rtos_task_set_period(task->getTask(), task->period);
147  cur_period = task->period;
148  if (cur_period == 0)
149  break; // break while(task->running) if no longer periodic
150  }
151 
152  // Check changes in scheduler
153  if ( cur_sched != task->msched_type) {
154  rtos_task_set_scheduler(task->getTask(), task->msched_type);
155  cur_sched = task->msched_type;
156  }
157  // rtos_task_wait_period will return immediately if
158  // the task is not periodic (ie period == 0)
159  // return non-zero to indicate overrun.
160  if (rtos_task_wait_period(task->getTask()) != 0)
161  {
162  ++overruns;
163  if (overruns == task->maxOverRun)
164  break; // break while(task->running)
165  }
166  else if (overruns != 0)
167  --overruns;
168  } // while(task->running)
169  if (overruns == task->maxOverRun || task->prepareForExit)
170  break; // break while(1) {}
171  }
172  else // non periodic:
173  TRY
174  (
175  // this mutex guarantees that stop() waits
176  // until loop() returns.
177  MutexLock lock(task->breaker);
178 
179  task->inloop = true;
180  SCOPE_ON
181  task->loop();
182  SCOPE_OFF
183  task->inloop = false;
184  ) CATCH_ALL
185  (
186  SCOPE_OFF
187  task->inloop = false;
188  throw;
189  )
190  }
191  } // while(1)
192  if (overruns == task->maxOverRun)
193  {
194  task->emergencyStop();
196  log(Critical) << rtos_task_get_name(task->getTask())
197  << " got too many periodic overruns in step() ("
198  << overruns << " times), stopped Thread !"
199  << endlog();
200  log() << " See Thread::setMaxOverrun() for info."
201  << endlog();
202  }
203  )CATCH(std::exception const& e,
204  SCOPE_OFF
205  task->emergencyStop();
207  log(Critical) << rtos_task_get_name(task->getTask())
208  << " caught a C++ exception, stopped thread !"
209  << endlog();
210  log(Critical) << "exception was: "
211  << e.what() << endlog();
212  ) CATCH_ALL
213  (
214  SCOPE_OFF
215  task->emergencyStop();
217  log(Critical) << rtos_task_get_name(task->getTask())
218  << " caught an unknown C++ exception, stopped thread !"
219  << endlog();
220  )
221  } // while (!prepareForExit)
222 
223  return 0;
224  }
225 
227  {
228  // set state to not running
229  this->running = false;
230  this->inloop = false;
231  this->active = false;
232  // execute finalize in current mode, even if hard.
233  this->finalize();
234  }
235 
236  Thread::Thread(int scheduler, int _priority,
237  Seconds periods, unsigned cpu_affinity, const std::string & name) :
238  msched_type(scheduler), active(false), prepareForExit(false),
239  inloop(false),running(false),
241  period(Seconds_to_nsecs(periods)) // Do not call setPeriod(), since the semaphores are not yet used !
242 #ifdef OROPKG_OS_THREAD_SCOPE
243  ,d(NULL)
244 #endif
245  , stopTimeout(0)
246  {
247  this->setup(_priority, cpu_affinity, name);
248  }
249 
250  void Thread::setup(int _priority, unsigned cpu_affinity, const std::string& name)
251  {
252  Logger::In in("Thread");
253  int ret;
254 
255  // we do this under lock in order to force the thread to wait until we're done.
256  MutexLock lock(breaker);
257 
258  log(Info) << "Creating Thread for scheduler=" << (msched_type == ORO_SCHED_OTHER ? "ORO_SCHED_OTHER" : "ORO_SCHED_RT")
259  << ", priority=" << _priority
260  << ", CPU affinity=" << cpu_affinity
261  << ", with name='" << name << "'"
262  << endlog();
263  ret = rtos_sem_init(&sem, 0);
264  if (ret != 0)
265  {
266  log(Critical)
267  << "Could not allocate configuration semaphore 'sem' for "
268  << name
269  << ". Throwing std::bad_alloc." << endlog();
270  rtos_sem_destroy(&sem);
271 #ifndef ORO_EMBEDDED
272  throw std::bad_alloc();
273 #else
274  return;
275 #endif
276  }
277 
278 #ifdef OROPKG_OS_THREAD_SCOPE
279  // Check if threadscope device already exists
280 
281  {
282  if ( DigitalOutInterface::nameserver.getObject("ThreadScope") )
283  {
284  d = DigitalOutInterface::nameserver.getObject("ThreadScope");
285  }
286  else
287  {
288  log(Warning) << "Failed to find 'ThreadScope' object in DigitalOutInterface::nameserver." << endlog();
289  }
290  }
291 #endif
292  int rv = rtos_task_create(&rtos_task, _priority, cpu_affinity, name.c_str(),
293  msched_type, default_stack_size, thread_function, this);
294  if (rv != 0)
295  {
296  log(Critical) << "Could not create thread "
297  << name << "."
298  << endlog();
299  rtos_sem_destroy(&sem);
300 #ifndef ORO_EMBEDDED
301  throw std::bad_alloc();
302 #else
303  return;
304 #endif
305  }
306 
307  // Wait for creation of thread.
308  rtos_sem_wait( &sem );
309 
310  const char* modname = getName();
311  Logger::In in2(modname);
312  log(Info) << "Thread created with scheduler type '"
313  << (getScheduler() == ORO_SCHED_OTHER ? "ORO_SCHED_OTHER" : "ORO_SCHED_RT") << "', priority " << getPriority()
314  << ", cpu affinity " << getCpuAffinity()
315  << " and period " << getPeriod() << " (PID= " << getPid() << " )." << endlog();
316 #ifdef OROPKG_OS_THREAD_SCOPE
317  if (d)
318  {
319  unsigned int bit = threadNumber();
320  log(Info) << "ThreadScope :"<< modname <<" toggles bit "<< bit << endlog();
321  }
322 #endif
323  }
324 
326  {
327  Logger::In in("~Thread");
328  if (this->isRunning())
329  this->stop();
330 
331  log(Debug) << "Terminating " << this->getName() << endlog();
332  terminate();
333  log(Debug) << " done" << endlog();
334  rtos_sem_destroy(&sem);
335 
336  }
337 
339  {
340  if ( period == 0)
341  {
342  // just signal if already active.
343  if ( isActive() ) {
344 #ifndef OROPKG_OS_MACOSX
345  // This is a 'weak' race condition.
346  // it could be that sem becomes zero
347  // after this check. Technically, this means
348  // loop is being executed (preemption) during start().
349  // For most user code, this is sufficient though, as it
350  // can not know the difference between executing loop()
351  // *in* start or *right after* start (the latter is
352  // guaranteed by the API).
353  // @see ActivityInterface::trigger for how trigger uses this
354  // assumption.
355  if ( rtos_sem_value(&sem) > 0 )
356  return true;
357 #endif
358  rtos_sem_signal(&sem);
359  return true;
360  }
361 
362  active=true;
363  if ( this->initialize() == false || active == false ) {
364  active = false;
365  return false;
366  }
367 
368  running = true;
369  rtos_sem_signal(&sem);
370 
371  return true;
372  }
373  else {
374 
375  if ( active )
376  return false;
377  active = true;
378 
379  bool result;
380  result = this->initialize();
381 
382  if (result == false || active == false) // detect call to stop() within initialize()
383  {
384  active = false;
385  return false;
386  }
387 
388  running = true;
389 
390  // signal start :
391  rtos_task_make_periodic(&rtos_task, period);
392  int ret = rtos_sem_signal(&sem);
393  if (ret != 0)
394  log(Critical)
395  << "Thread::start(): sem_signal returns " << ret
396  << endlog();
397  // do not wait, we did our job.
398 
399  return true;
400  }
401  }
402 
404  {
405  stopTimeout = value;
406  }
407 
409  {
410  if (stopTimeout != 0)
411  return stopTimeout;
412  else if (period == 0)
413  return Thread::lock_timeout_no_period_in_s;
414  else return Thread::lock_timeout_period_factor * getPeriod();
415  }
416 
418  {
419  if (!active)
420  return false;
421 
422  running = false;
423 
424  if ( period == 0)
425  {
426  if ( inloop ) {
427  if ( !this->breakLoop() ) {
428  log(Warning) << "Failed to stop thread " << this->getName() << ": breakLoop() returned false."<<endlog();
429  running = true;
430  return false;
431  }
432  // breakLoop was ok, wait for loop() to return.
433  }
434  // always take this lock, but after breakLoop was called !
435  MutexTimedLock lock(breaker, getStopTimeout());
436  if ( !lock.isSuccessful() ) {
437  log(Error) << "Failed to stop thread " << this->getName() << ": breakLoop() returned true, but loop() function did not return after " << getStopTimeout() <<" seconds."<<endlog();
438  running = true;
439  return false;
440  }
441  } else {
442  //
443  MutexTimedLock lock(breaker, getStopTimeout() );
444  if ( lock.isSuccessful() ) {
445  // drop out of periodic mode.
446  rtos_task_make_periodic(&rtos_task, 0);
447  } else {
448  log(Error) << "Failed to stop thread " << this->getName() << ": step() function did not return after "<< getStopTimeout() <<" seconds."<<endlog();
449  running = true;
450  return false;
451  }
452  }
453 
454  this->finalize();
455  active = false;
456  return true;
457  }
458 
459  bool Thread::isRunning() const
460  {
461  return period == 0 ? inloop : running;
462  }
463 
464  bool Thread::isActive() const
465  {
466  return active;
467  }
468 
469  bool Thread::setScheduler(int sched_type)
470  {
471  Logger::In in("Thread::setScheduler");
472  if (os::CheckScheduler(sched_type) == false)
473  return false;
474  if (this->getScheduler() == sched_type)
475  {
476  return true;
477  }
478 
479  log(Info) << "Setting scheduler type for Thread '"
480  << rtos_task_get_name(&rtos_task) << "' to "
481  << sched_type << endlog();
482  rtos_task_set_scheduler(&rtos_task, sched_type); // this may be a no-op, in that case, configure() will pick the change up.
483  msched_type = sched_type;
484  rtos_sem_signal(&sem);
485  return true; // we assume all will go well.
486  }
487 
489  {
490  return rtos_task_get_scheduler(&rtos_task);
491  }
492 
493  void Thread::configure()
494  {
495  // this function is called from within the thread
496  // when we wake up after start()
497  // It is intended to check our scheduler, priority,..., and do the in-thread
498  // stuff that may be required by the RTOS. For example: RTAI requires that
499  // we set the scheduler within the thread itself.
500 
501  // reconfigure period
502  rtos_task_set_period(&rtos_task, period);
503 
504  // reconfigure scheduler.
505  if (msched_type != rtos_task_get_scheduler(&rtos_task))
506  {
507  rtos_task_set_scheduler(&rtos_task, msched_type);
508  msched_type = rtos_task_get_scheduler(&rtos_task);
509  }
510  }
511 
513  {
514  }
515 
517  {
518  this->step();
519  }
520 
522  {
523  return false;
524  }
525 
526 
528  {
529  return true;
530  }
531 
533  {
534  }
535 
536  bool Thread::setPeriod(double s)
537  {
538  nsecs nsperiod = Seconds_to_nsecs(s);
539  return setPeriod(0, nsperiod);
540  }
541 
543  {
544  nsecs nsperiod = ns + 1000* 1000* 1000* s ;
545  if (nsperiod < 0)
546  return false;
547  // logic to switch from per->nper || nper->per
548  if ( (nsperiod == 0 && period != 0) || (nsperiod != 0 && period == 0)) {
549  // switch between periodic/non-periodic
550  // note for RTAI: the fosi_internal layer must detect if this is called from
551  // within rtos_task or outside the thread.
552  rtos_task_make_periodic(&rtos_task, nsperiod);
553  // jump from non periodic into periodic: first sample.
554  if ( period == 0) {
555  period = nsperiod; // avoid race with sem in thread func.
556  rtos_sem_signal(&sem);
557  }
558  }
559  // update rate:
560  period = nsperiod;
561 
562  return true;
563  }
564 
566  {
567  return this->setPeriod( p.tv_sec, p.tv_nsec );
568  }
569 
570  void Thread::getPeriod(secs& s, nsecs& ns) const
571  {
572  s = secs(period/(1000*1000*1000));
573  ns = period - s*1000*1000*1000;
574  }
575 
577  {
578  return rtos_task_set_priority(&rtos_task, p) == 0;
579  }
580 
581  bool Thread::isPeriodic() const
582  {
583  return period != 0;
584  }
585 
587  {
588  return rtos_task_get_priority(&rtos_task);
589  }
590 
591  double Thread::getPeriod() const
592  {
593  return nsecs_to_Seconds(period);
594  }
595 
597  {
598  return period;
599  }
600 
601  bool Thread::setCpuAffinity(unsigned cpu_affinity)
602  {
603  return rtos_task_set_cpu_affinity(&rtos_task, cpu_affinity) == 0;
604  }
605 
606  unsigned Thread::getCpuAffinity() const
607  {
608  return rtos_task_get_cpu_affinity(&rtos_task);
609  }
610 
611  unsigned int Thread::getPid() const
612  {
613  return rtos_task_get_pid(&rtos_task);
614  }
615 
617  {
618  rtos_task_yield( &rtos_task );
619  }
620 
622  {
623  // avoid callling twice.
624  if (prepareForExit) return;
625 
626  prepareForExit = true;
627  rtos_sem_signal(&sem);
628 
629  rtos_task_delete(&rtos_task); // this must join the thread.
630  }
631 
632  const char* Thread::getName() const
633  {
634  return rtos_task_get_name(&rtos_task);
635  }
636 
637  void Thread::setMaxOverrun( int m )
638  {
639  maxOverRun = m;
640  }
641 
643  {
644  return maxOverRun;
645  }
646 
648  {
649  rtos_task_set_wait_period_policy(&rtos_task, p);
650  }
651 
652  }
653 }
654 
long long NANO_TIME
Definition: fosi.h:55
virtual bool breakLoop()
Definition: Thread.cpp:521
int rtos_task_get_priority(const RTOS_TASK *task)
Return the priority of a thread.
virtual void setMaxOverrun(int m)
Definition: Thread.cpp:637
INTERNAL_QUAL void rtos_task_make_periodic(RTOS_TASK *mytask, NANO_TIME nanosecs)
This function is to inform the RTOS that a thread is switching between periodic or non-periodic execu...
double Seconds
Seconds are stored as a double precision float.
Definition: Time.hpp:53
#define TRY(C)
Contains static global configuration variables and cached entries.
Definition: CatchConfig.hpp:56
static void setLockTimeoutNoPeriod(double timeout_in_s)
Sets the lock timeout for a thread which does not have a period The default is 1 second.
Definition: Thread.cpp:71
static NameServer< DigitalOutInterface * > nameserver
The NameServer of this interface.
bool CheckScheduler(int &sched_type)
Check if the scheduler is a valid type in the current process and adapt to a valid value...
Definition: threads.cpp:46
A Thread object executes user code in its own thread.
Definition: Thread.hpp:109
unsigned int rtos_task_get_pid(const RTOS_TASK *task)
Returns the process ID the OS gave to the task task.
Seconds nsecs_to_Seconds(const nsecs ns)
Definition: Time.hpp:108
void setStopTimeout(Seconds s)
Sets the timeout for stop(), in seconds.
Definition: Thread.cpp:403
int rtos_sem_signal(rt_sem_t *m)
int rtos_task_set_scheduler(RTOS_TASK *t, int sched_type)
Set the scheduler of a given task t to a the type sched_type.
friend void * thread_function(void *t)
Definition: Thread.cpp:75
void emergencyStop()
Definition: Thread.cpp:226
long secs
seconds as a signed long.
Definition: Time.hpp:57
A simple logging class to debug/ analyse what is going on in the Orocos system.
Definition: Logger.hpp:95
virtual bool setCpuAffinity(unsigned cpu_affinity)
Set cpu affinity for this thread.
Definition: Thread.cpp:601
int rtos_task_set_cpu_affinity(RTOS_TASK *task, unsigned cpu_affinity)
Set the cpu affinity of a thread.
virtual bool setScheduler(int sched_type)
Change the scheduler policy in which this thread runs.
Definition: Thread.cpp:469
unsigned rtos_task_get_cpu_affinity(const RTOS_TASK *task)
Return the cpu affinity of a thread.
virtual bool setPriority(int priority)
Set the priority of this Thread.
Definition: Thread.cpp:576
virtual void step()
Definition: Thread.cpp:512
virtual RTOS_TASK * getTask()
Get the RTOS_TASK pointer.
Definition: Thread.hpp:205
This file has all the (periodic) thread specific interfaces.
virtual void loop()
Definition: Thread.cpp:516
virtual int getMaxOverrun() const
Definition: Thread.cpp:642
#define CATCH(T, C)
Definition: CatchConfig.hpp:57
void rtos_task_set_wait_period_policy(RTOS_TASK *task, int policy)
Set the wait policy of a thread.
static void setLockTimeoutPeriodFactor(double factor)
Set the lock timeout for a thread which has a period by a factor of the period The default is factor ...
Definition: Thread.cpp:73
void rtos_task_delete(RTOS_TASK *mytask)
This function must join the thread created with rtos_task_create and then clean up the RTOS_TASK stru...
virtual void finalize()
Definition: Thread.cpp:532
virtual bool isActive() const
Returns whether the thread is active.
Definition: Thread.cpp:464
#define SCOPE_OFF
Definition: Thread.cpp:55
int rtos_task_set_priority(RTOS_TASK *task, int priority)
Set the priority of a thread.
unsigned int threadNumber() const
The unique thread number (within the same process).
int rtos_sem_destroy(rt_sem_t *m)
virtual bool initialize()
Definition: Thread.cpp:527
const char * rtos_task_get_name(const RTOS_TASK *task)
Returns the name by which a task is known in the RTOS.
A MutexTimedLock locks a Mutex object on construction and if successful, unlocks it on destruction of...
Definition: MutexLock.hpp:146
virtual unsigned getCpuAffinity() const
Definition: Thread.cpp:606
#define CATCH_ALL(C)
Definition: CatchConfig.hpp:58
int rtos_task_wait_period(RTOS_TASK *task)
This function is called by a periodic thread which wants to go to sleep and wake up the next period...
bool isSuccessful()
Return if the locking of the Mutex was succesfull.
Definition: MutexLock.hpp:168
ValueType getObject(const NameType &s) const
Get the object registered for a name.
Definition: NameServer.hpp:136
INTERNAL_QUAL void rtos_task_yield(RTOS_TASK *)
Yields the current thread.
void terminate()
Exit and destroy the thread.
Definition: Thread.cpp:621
virtual int getScheduler() const
Get the scheduler policy in which this thread runs.
Definition: Thread.cpp:488
#define OROSEM_OS_PERIODIC_THREADS_MAX_OVERRUN
Notify the Logger in which &#39;module&#39; the message occured.
Definition: Logger.hpp:159
bool setPeriod(Seconds s)
Set the periodicity in Seconds.
Definition: Thread.cpp:536
int rtos_sem_init(rt_sem_t *m, int value)
All these should return zero in case of succes.
nsecs Seconds_to_nsecs(const Seconds s)
Definition: Time.hpp:107
#define SCOPE_ON
Definition: Thread.cpp:54
virtual ~Thread()
Definition: Thread.cpp:325
static void setStackSize(unsigned int ssize)
Sets the stack size of the threads to be created.
Definition: Thread.cpp:69
virtual bool start()
Start the Thread.
Definition: Thread.cpp:338
Thread(int scheduler, int priority, double period, unsigned cpu_affinity, const std::string &name)
Create a Thread with a given scheduler type, priority and a name.
Definition: Thread.cpp:236
int rtos_sem_value(rt_sem_t *m)
Seconds getStopTimeout() const
Returns the desired timeout for stop(), in seconds.
Definition: Thread.cpp:408
virtual void yield()
Yields (put to the back of the scheduler queue) the calling thread.
Definition: Thread.cpp:616
virtual bool stop()
Stop the Thread.
Definition: Thread.cpp:417
virtual void setWaitPeriodPolicy(int p)
Set the wait policy of a periodic thread.
Definition: Thread.cpp:647
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
void rtos_task_set_period(RTOS_TASK *mytask, NANO_TIME nanosecs)
Change the period of a periodic RTOS task.
virtual int getPriority() const
The priority of this Thread.
Definition: Thread.cpp:586
virtual Seconds getPeriod() const
Get the periodicity in Seconds.
Definition: Thread.cpp:591
long long nsecs
nanoseconds as a signed long long.
Definition: Time.hpp:69
struct timespec TIME_SPEC
Definition: fosi.h:97
virtual unsigned int getPid() const
Returns the Process or Thread ID of this thread, as assigned by the Operating System.
Definition: Thread.cpp:611
int rtos_sem_wait(rt_sem_t *m)
#define ORO_SCHED_OTHER
Definition: fosi.h:50
virtual bool isPeriodic() const
Definition: Thread.cpp:581
virtual nsecs getPeriodNS() const
Get the periodicity in nanoseconds.
Definition: Thread.cpp:596
virtual const char * getName() const
Read the name of this task.
Definition: Thread.cpp:632
INTERNAL_QUAL int rtos_task_create(RTOS_TASK *task, int priority, unsigned cpu_affinity, const char *name, int sched_type, size_t stack_size, void *(*start_routine)(void *), ThreadInterface *obj)
Create a thread.
virtual bool isRunning() const
Returns whether the thread is running.
Definition: Thread.cpp:459
MutexLock is a scope based Monitor, protecting critical sections with a Mutex object through locking ...
Definition: MutexLock.hpp:51
int rtos_task_get_scheduler(const RTOS_TASK *t)
Returns the current scheduler set for task t.