ThreadImplLxrt33.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 //----------------------------------------------------------------------
00009 //----------------------------------------------------------------------
00010 #include "ThreadImplLxrt33.h"
00011 
00012 #include <icl_core/internal_raw_debug.h>
00013 #include <icl_core/os_lxrt.h>
00014 
00015 #include "Thread.h"
00016 
00017 namespace icl_core {
00018 namespace logging {
00019 
00020 ThreadImplLxrt33::ThreadImplLxrt33(Thread *thread, icl_core::ThreadPriority priority)
00021   : m_thread_id(0),
00022     m_thread(thread),
00023     m_priority(priority),
00024     m_rt_task(NULL)
00025 {
00026 }
00027 
00028 ThreadImplLxrt33::~ThreadImplLxrt33()
00029 {
00030 }
00031 
00032 void ThreadImplLxrt33::join()
00033 {
00034   pthread_join_rt(m_thread_id, NULL);
00035   m_rt_task = NULL;
00036 }
00037 
00038 bool ThreadImplLxrt33::start()
00039 {
00040   if (pthread_create(&m_thread_id, NULL, ThreadImplLxrt33::runThread, this))
00041   {
00042     m_thread_id = 0;
00043     m_rt_task = NULL;
00044   }
00045   else
00046   {
00047     // Nothing to be done here!
00048   }
00049 
00050   return m_thread_id != 0;
00051 }
00052 
00053 void *ThreadImplLxrt33::runThread(void *arg)
00054 {
00055   ThreadImplLxrt33 *self = static_cast<ThreadImplLxrt33*>(arg);
00056 
00057   self->m_rt_task = rt_task_init(getpid() + pthread_self_rt(), abs(self->m_priority),
00058                                  DEFAULT_STACK_SIZE, 0);
00059   if (self->m_rt_task == NULL)
00060   {
00061     PRINTF("ERROR: Cannot initialize LXRT task %lu!\n", self->m_thread_id);
00062     PRINTF("       Probably another thread with the same name already exists.\n");
00063   }
00064   else
00065   {
00066     rt_task_use_fpu(self->m_rt_task, 1);
00067 
00068     if (self->m_priority < 0)
00069     {
00070       rt_make_hard_real_time();
00071       if (!rt_is_hard_real_time(rt_buddy()))
00072       {
00073         PRINTF("ERROR: Setting thread %lu to hard real-time failed!\n", self->m_thread_id);
00074       }
00075       else
00076       {
00077         // Everything worked as expected, so no message here.
00078       }
00079     }
00080     else
00081     {
00082       // This is a soft realtime thread, so nothing additional has to
00083       // be done here.
00084     }
00085 
00086     self->m_thread->runThread();
00087 
00088     rt_make_soft_real_time();
00089 
00090     // TODO: Check if this is correct. The RTAI 3.5 and 3.8
00091     // implementations leave this to a call to join().
00092     rt_task_delete(self->m_rt_task);
00093     self->m_rt_task = NULL;
00094   }
00095 
00096   return NULL;
00097 }
00098 
00099 }
00100 }


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Fri Aug 28 2015 12:59:19