Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00022
00023 #include "ThreadImplLxrt33.h"
00024
00025 #include <icl_core/internal_raw_debug.h>
00026 #include <icl_core/os_lxrt.h>
00027
00028 #include "Thread.h"
00029
00030 namespace icl_core {
00031 namespace logging {
00032
00033 ThreadImplLxrt33::ThreadImplLxrt33(Thread *thread, icl_core::ThreadPriority priority)
00034 : m_thread_id(0),
00035 m_thread(thread),
00036 m_priority(priority),
00037 m_rt_task(NULL)
00038 {
00039 }
00040
00041 ThreadImplLxrt33::~ThreadImplLxrt33()
00042 {
00043 }
00044
00045 void ThreadImplLxrt33::join()
00046 {
00047 pthread_join_rt(m_thread_id, NULL);
00048 m_rt_task = NULL;
00049 }
00050
00051 bool ThreadImplLxrt33::start()
00052 {
00053 if (pthread_create(&m_thread_id, NULL, ThreadImplLxrt33::runThread, this))
00054 {
00055 m_thread_id = 0;
00056 m_rt_task = NULL;
00057 }
00058 else
00059 {
00060
00061 }
00062
00063 return m_thread_id != 0;
00064 }
00065
00066 void *ThreadImplLxrt33::runThread(void *arg)
00067 {
00068 ThreadImplLxrt33 *self = static_cast<ThreadImplLxrt33*>(arg);
00069
00070 self->m_rt_task = rt_task_init(getpid() + pthread_self_rt(), abs(self->m_priority),
00071 DEFAULT_STACK_SIZE, 0);
00072 if (self->m_rt_task == NULL)
00073 {
00074 PRINTF("ERROR: Cannot initialize LXRT task %lu!\n", self->m_thread_id);
00075 PRINTF(" Probably another thread with the same name already exists.\n");
00076 }
00077 else
00078 {
00079 rt_task_use_fpu(self->m_rt_task, 1);
00080
00081 if (self->m_priority < 0)
00082 {
00083 rt_make_hard_real_time();
00084 if (!rt_is_hard_real_time(rt_buddy()))
00085 {
00086 PRINTF("ERROR: Setting thread %lu to hard real-time failed!\n", self->m_thread_id);
00087 }
00088 else
00089 {
00090
00091 }
00092 }
00093 else
00094 {
00095
00096
00097 }
00098
00099 self->m_thread->runThread();
00100
00101 rt_make_soft_real_time();
00102
00103
00104
00105 rt_task_delete(self->m_rt_task);
00106 self->m_rt_task = NULL;
00107 }
00108
00109 return NULL;
00110 }
00111
00112 }
00113 }