icl_core_logging/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 
30 namespace icl_core {
31 namespace logging {
32 
34  : m_thread_id(0),
35  m_thread(thread),
36  m_priority(priority),
37  m_rt_task(NULL)
38 {
39 }
40 
42 {
43 }
44 
46 {
47  pthread_join_rt(m_thread_id, NULL);
48  m_rt_task = NULL;
49 }
50 
52 {
53  if (pthread_create(&m_thread_id, NULL, ThreadImplLxrt33::runThread, this))
54  {
55  m_thread_id = 0;
56  m_rt_task = NULL;
57  }
58  else
59  {
60  // Nothing to be done here!
61  }
62 
63  return m_thread_id != 0;
64 }
65 
67 {
68  ThreadImplLxrt33 *self = static_cast<ThreadImplLxrt33*>(arg);
69 
70  self->m_rt_task = rt_task_init(getpid() + pthread_self_rt(), abs(self->m_priority),
72  if (self->m_rt_task == NULL)
73  {
74  PRINTF("ERROR: Cannot initialize LXRT task %lu!\n", self->m_thread_id);
75  PRINTF(" Probably another thread with the same name already exists.\n");
76  }
77  else
78  {
79  rt_task_use_fpu(self->m_rt_task, 1);
80 
81  if (self->m_priority < 0)
82  {
83  rt_make_hard_real_time();
84  if (!rt_is_hard_real_time(rt_buddy()))
85  {
86  PRINTF("ERROR: Setting thread %lu to hard real-time failed!\n", self->m_thread_id);
87  }
88  else
89  {
90  // Everything worked as expected, so no message here.
91  }
92  }
93  else
94  {
95  // This is a soft realtime thread, so nothing additional has to
96  // be done here.
97  }
98 
99  self->m_thread->runThread();
100 
101  rt_make_soft_real_time();
102 
103  // TODO: Check if this is correct. The RTAI 3.5 and 3.8
104  // implementations leave this to a call to join().
105  rt_task_delete(self->m_rt_task);
106  self->m_rt_task = NULL;
107  }
108 
109  return NULL;
110 }
111 
112 }
113 }
TimeSpan abs(const TimeSpan &span)
Definition: TimeSpan.h:222
ThreadImplLxrt33(Thread *thread, icl_core::ThreadPriority priority)
Contains icl_core::logging::ThreadImplLxrt33.
Contains a system independet PRINTF macro.
Contains icl_core::logging::Thread.
Contains global LXRT functions.
#define DEFAULT_STACK_SIZE
#define PRINTF
int32_t ThreadPriority
Definition: os_thread.h:50


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