icl_core_thread/ThreadImplLxrt33.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23 #include "ThreadImplLxrt33.h"
24 
26 #include <icl_core/os_lxrt.h>
27 
28 #include "Thread.h"
29 #include "Logging.h"
30 
31 #define DEFAULT_STACK_SIZE 0x4000
32 
33 namespace icl_core {
34 namespace thread {
35 
37  icl_core::ThreadPriority priority)
38  : m_thread_id(0),
39  m_thread(thread),
40  m_priority(priority),
41  m_description(description),
42  m_rt_task(NULL)
43 { }
44 
46 { }
47 
49 {
50  if (m_rt_task != NULL)
51  {
52  rt_task_delete(m_rt_task);
53  m_rt_task = NULL;
54  }
55  pthread_cancel_rt(m_thread_id);
56  m_thread_id = 0;
57  m_rt_task = NULL;
58 }
59 
61 {
62  return m_priority < 0;
63 }
64 
66 {
67  return os::isThisHRT();
68 }
69 
71 {
72  pthread_join_rt(m_thread_id, NULL);
73  m_thread_id = 0;
74  m_rt_task = NULL;
75 }
76 
78 {
79  return m_priority;
80 }
81 
82 bool ThreadImplLxrt33::setHardRealtime(bool hard_realtime)
83 {
84  if (hard_realtime && !os::isThisHRT())
85  {
86  rt_make_hard_real_time();
87  return os::isThisHRT();
88  }
89  else if (!hard_realtime && os::isThisHRT())
90  {
91  rt_make_soft_real_time();
92  return !os::isThisHRT();
93  }
94  else
95  {
96  return false;
97  }
98 }
99 
101 {
102  // TODO: Make this work!
103  /*
104  if (m_rt_task != NULL) {
105  int ret = rt_change_prio(m_rt_task, abs(priority));
106  if (ret == 0) {
107  m_priority = priority;
108 
109  if (priority > 0 && IsHardRealtimeThread()) {
110  rt_make_soft_real_time();
111  } else if (priority < 0 && !IsHardRealtimeThread()) {
112  rt_make_hard_real_time();
113  }
114 
115  return true;
116  }
117  }
118  */
119 
120  return false;
121 }
122 
124 {
125  if (pthread_create(&m_thread_id, NULL, ThreadImplLxrt33::runThread, this))
126  {
127  m_thread_id = 0;
128  m_rt_task = NULL;
129  }
130 
131  return m_thread_id != 0;
132 }
133 
135 {
137 }
138 
140 {
141  ThreadImplLxrt33 *self = static_cast<ThreadImplLxrt33*>(arg);
142 
143  self->m_rt_task = rt_task_init(getpid() + pthread_self_rt(),
144  abs(self->m_priority), DEFAULT_STACK_SIZE, 0);
145  if (self->m_rt_task == NULL)
146  {
147  PRINTF("ERROR: Cannot initialize LXRT task %lu!\n", self->m_thread_id);
148  PRINTF(" Probably another thread with the same name already exists.\n");
149  }
150  else
151  {
152  rt_task_use_fpu(self->m_rt_task, 1);
153 
154  if (self->m_priority < 0)
155  {
156  rt_make_hard_real_time();
157  if (!rt_is_hard_real_time(rt_buddy()))
158  {
159  PRINTF("ERROR: Setting thread %lu to hard real-time failed!\n", self->m_thread_id);
160  }
161  }
162 
163  self->m_thread->runThread();
164 
165  rt_make_soft_real_time();
166  rt_task_delete(self->m_rt_task);
167  self->m_rt_task = NULL;
168  }
169 
170  return NULL;
171 }
172 
173 }
174 }
ICL_CORE_OS_IMPL_NS::ThreadId ThreadId
Definition: os_thread.h:49
Contains icl_core::thread::ThreadImpl for RTAI/LXRT 3.3.
TimeSpan abs(const TimeSpan &span)
Definition: TimeSpan.h:222
ThreadImplLxrt33(Thread *thread, const icl_core::String &description, icl_core::ThreadPriority priority)
Contains a system independet PRINTF macro.
Contains logging definitions for the icl_core_thread library.
virtual bool setHardRealtime(bool hard_realtime)
virtual bool setPriority(icl_core::ThreadPriority priority)
bool isThisHRT()
Definition: os_lxrt.cpp:159
Contains global LXRT functions.
std::string String
Definition: BaseTypes.h:43
Contains icl_core::thread::Thread.
virtual icl_core::ThreadPriority priority() const
#define PRINTF
#define DEFAULT_STACK_SIZE
int32_t ThreadPriority
Definition: os_thread.h:50
virtual icl_core::ThreadId threadId() const


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58