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