Orocos Real-Time Toolkit  2.9.0
MainThread.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: FMTC do nov 2 13:06:03 CET 2006 MainThread.cpp
3 
4  MainThread.cpp - description
5  -------------------
6  begin : do november 02 2006
7  copyright : (C) 2006 FMTC
8  email : peter.soetens@fmtc.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 
39 
40 // this file must be included always first.
42 #include "os/MainThread.hpp"
43 
44 namespace RTT
45 { namespace os {
46 
47  boost::shared_ptr<ThreadInterface> MainThread::mt;
48 
49 
50  MainThread::MainThread() {
51  rtos_task_create_main(&main_task);
52  }
53 
55  rtos_task_delete_main(&main_task);
56  }
57 
59  {
60  if (mt)
61  return mt.get();
62  mt.reset( new MainThread() );
63  return mt.get();
64  }
65 
67  {
68  mt.reset();
69  }
70 
71  bool MainThread::start() { return false; }
72 
73  bool MainThread::stop() { return false; }
74 
75  Seconds MainThread::getPeriod() const { return 0; }
76 
77  nsecs MainThread::getPeriodNS() const { return 0; }
78 
79  bool MainThread::isRunning() const { return true; }
80  bool MainThread::isActive() const { return true; }
81 
82  const char* MainThread::getName() const { return "main"; }
83 
84  RTOS_TASK * MainThread::getTask() { return &main_task; }
85 
86  const RTOS_TASK * MainThread::getTask() const { return &main_task; }
87 
88  bool MainThread::setScheduler(int sched_type)
89  {
90  if ( rtos_task_set_scheduler(&main_task, sched_type) == 0)
91  return true;
92  return false;
93  }
95  {
96  return rtos_task_get_scheduler(&main_task);
97  }
98 
100  {
101  return rtos_task_set_priority(&main_task, p) == 0;
102  }
103 
105  {
106  return rtos_task_get_priority(&main_task);
107  }
108 
109  unsigned int MainThread::getPid() const
110  {
111  return rtos_task_get_pid(&main_task);
112  }
113 
114  unsigned MainThread::getCpuAffinity() const
115  {
116  return rtos_task_get_cpu_affinity(&main_task);
117  }
118 
120  {
121  return false;
122  }
123 
125  {
126  }
127 
129  {
130  return 0;
131  }
132 
134  {
135  rtos_task_set_wait_period_policy(&main_task, p);
136  }
137 
139  {
140  rtos_task_yield(&main_task);
141  }
142 
143  unsigned int MainThread::threadNumber() const { return 0; }
144 }}
145 
146 
virtual RTOS_TASK * getTask()
Get the RTOS_TASK pointer.
Definition: MainThread.cpp:84
int rtos_task_get_priority(const RTOS_TASK *task)
Return the priority of a thread.
virtual bool isRunning() const
Returns always true.
Definition: MainThread.cpp:79
double Seconds
Seconds are stored as a double precision float.
Definition: Time.hpp:53
static ThreadInterface * Instance()
Return an object which represents the main thread.
Definition: MainThread.cpp:58
unsigned int rtos_task_get_pid(const RTOS_TASK *task)
Returns the process ID the OS gave to the task task.
virtual bool isActive() const
Returns always true.
Definition: MainThread.cpp:80
INTERNAL_QUAL int rtos_task_delete_main(RTOS_TASK *main_task)
Cleanup the main thread.
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.
virtual const char * getName() const
Returns "main".
Definition: MainThread.cpp:82
virtual ~MainThread()
Definition: MainThread.cpp:54
virtual bool stop()
Always fails.
Definition: MainThread.cpp:73
unsigned rtos_task_get_cpu_affinity(const RTOS_TASK *task)
Return the cpu affinity of a thread.
virtual unsigned int getPid() const
Returns the Process or Thread ID of this thread, as assigned by the Operating System.
Definition: MainThread.cpp:109
virtual unsigned getCpuAffinity() const
Definition: MainThread.cpp:114
virtual bool setPriority(int priority)
Set the priority of this Thread.
Definition: MainThread.cpp:99
A thread which is being run.
This file has all the (periodic) thread specific interfaces.
static void Release()
This is called to cleanup the main thread.
Definition: MainThread.cpp:66
virtual int getMaxOverrun() const
Definition: MainThread.cpp:128
void rtos_task_set_wait_period_policy(RTOS_TASK *task, int policy)
Set the wait policy of a thread.
virtual int getScheduler() const
Get the scheduler policy in which this thread runs.
Definition: MainThread.cpp:94
int rtos_task_set_priority(RTOS_TASK *task, int priority)
Set the priority of a thread.
virtual int getPriority() const
The priority of this Thread.
Definition: MainThread.cpp:104
virtual bool setScheduler(int sched_type)
Change the scheduler policy in which this thread runs.
Definition: MainThread.cpp:88
virtual Seconds getPeriod() const
Returns zero.
Definition: MainThread.cpp:75
virtual void setWaitPeriodPolicy(int p)
Set the wait policy of a periodic thread.
Definition: MainThread.cpp:133
INTERNAL_QUAL void rtos_task_yield(RTOS_TASK *)
Yields the current thread.
unsigned int threadNumber() const
Returns zero, the number of the main() thread.
Definition: MainThread.cpp:143
virtual void setMaxOverrun(int m)
Definition: MainThread.cpp:124
virtual bool start()
Always fails.
Definition: MainThread.cpp:71
virtual nsecs getPeriodNS() const
Returns zero.
Definition: MainThread.cpp:77
virtual void yield()
Yields (put to the back of the scheduler queue) the calling thread.
Definition: MainThread.cpp:138
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
INTERNAL_QUAL int rtos_task_create_main(RTOS_TASK *main_task)
Initialise the main thread.
virtual bool setPeriod(Seconds period)
Returns always false.
Definition: MainThread.cpp:119
long long nsecs
nanoseconds as a signed long long.
Definition: Time.hpp:69
Definition: fosi.h:62
A class which represents the main() thread.
Definition: MainThread.hpp:52
int rtos_task_get_scheduler(const RTOS_TASK *t)
Returns the current scheduler set for task t.