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