ThreadImplLxrt33.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
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     // Nothing to be done here!
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         // Everything worked as expected, so no message here.
00091       }
00092     }
00093     else
00094     {
00095       // This is a soft realtime thread, so nothing additional has to
00096       // be done here.
00097     }
00098 
00099     self->m_thread->runThread();
00100 
00101     rt_make_soft_real_time();
00102 
00103     // TODO: Check if this is correct. The RTAI 3.5 and 3.8
00104     // implementations leave this to a call to join().
00105     rt_task_delete(self->m_rt_task);
00106     self->m_rt_task = NULL;
00107   }
00108 
00109   return NULL;
00110 }
00111 
00112 }
00113 }


fzi_icl_core
Author(s):
autogenerated on Thu Jun 6 2019 20:22:24