Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00023
00024 #include "ThreadImplLxrt38.h"
00025
00026 #include <icl_core/internal_raw_debug.h>
00027 #include <icl_core/os_lxrt.h>
00028
00029 #include "Thread.h"
00030
00031
00032 namespace icl_core {
00033 namespace logging {
00034
00035 ThreadImplLxrt38::ThreadImplLxrt38(Thread *thread, icl_core::ThreadPriority priority)
00036 : m_thread_id(0),
00037 m_thread(thread),
00038 m_priority(priority),
00039 m_rt_task(NULL),
00040 m_rt_start_sync(NULL)
00041 {
00042 }
00043
00044 ThreadImplLxrt38::~ThreadImplLxrt38()
00045 {
00046
00047 join();
00048
00049 if (m_rt_start_sync == NULL)
00050 {
00051
00052 }
00053 else
00054 {
00055 rt_sem_delete(m_rt_start_sync);
00056 m_rt_start_sync = NULL;
00057 }
00058 }
00059
00060 void ThreadImplLxrt38::join()
00061 {
00062 if (m_thread_id == 0)
00063 {
00064
00065 }
00066 else
00067 {
00068 pthread_join_rt(m_thread_id, NULL);
00069 m_rt_task = NULL;
00070 m_thread_id = 0;
00071 }
00072 }
00073
00074 bool ThreadImplLxrt38::start()
00075 {
00076 m_rt_start_sync = rt_typed_sem_init(size_t(this), 2, CNT_SEM | PRIO_Q);
00077 if (m_rt_start_sync == NULL)
00078 {
00079
00080 }
00081 else
00082 {
00083 if (pthread_create(&m_thread_id, NULL, ThreadImplLxrt38::runThread, this))
00084 {
00085 m_thread_id = 0;
00086 m_rt_task = NULL;
00087
00088 rt_sem_delete(m_rt_start_sync);
00089 m_rt_start_sync = NULL;
00090 }
00091 else
00092 {
00093 rt_sem_wait_barrier(m_rt_start_sync);
00094 }
00095 }
00096
00097 return m_thread_id != 0;
00098 }
00099
00100 void *ThreadImplLxrt38::runThread(void *arg)
00101 {
00102 ThreadImplLxrt38 *self = static_cast<ThreadImplLxrt38*>(arg);
00103
00104 if (self->m_rt_start_sync == NULL)
00105 {
00106
00107
00108 PRINTF("ERROR: NULL thread start barrier!\n");
00109 }
00110 else
00111 {
00112 self->m_rt_task = rt_task_init(getpid() + pthread_self_rt(), abs(self->m_priority),
00113 DEFAULT_STACK_SIZE, 0);
00114 if (self->m_rt_task == NULL)
00115 {
00116 PRINTF("ERROR: Cannot initialize LXRT task %lu!\n", self->m_thread_id);
00117 PRINTF(" Probably another thread with the same name already exists.\n");
00118
00119
00120 rt_sem_wait_barrier(self->m_rt_start_sync);
00121 }
00122 else
00123 {
00124 if (self->m_priority < 0)
00125 {
00126 rt_make_hard_real_time();
00127 if (!rt_is_hard_real_time(rt_buddy()))
00128 {
00129 PRINTF("ERROR: Setting thread %lu to hard real-time failed!\n", self->m_thread_id);
00130 }
00131 else
00132 {
00133
00134 }
00135 }
00136 else
00137 {
00138
00139
00140 }
00141
00142 rt_sem_wait_barrier(self->m_rt_start_sync);
00143
00144 self->m_thread->runThread();
00145
00146
00147
00148 rt_make_soft_real_time();
00149 }
00150 }
00151
00152 return NULL;
00153 }
00154
00155 }
00156 }