MutexImplLxrt33.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 "icl_core_thread/MutexImplLxrt33.h"
00024 
00025 #include <icl_core/internal_raw_debug.h>
00026 #include <icl_core/os_lxrt.h>
00027 
00028 #include "icl_core_thread/Common.h"
00029 
00030 #undef STRICT_LXRT_CHECKS
00031 
00032 namespace icl_core {
00033 namespace thread {
00034 
00035 MutexImplLxrt33::MutexImplLxrt33()
00036   : m_mutex(0)
00037 {
00038 #ifdef STRICT_LXRT_CHECKS
00039   if (!icl_core::os::IsThisLxrtTask())
00040   {
00041     PRINTF("MutexImplLxrt33::MutexImplLxrt33: Called from a Linux task!\n");
00042     return;
00043   }
00044 #endif
00045   m_mutex = new pthread_mutex_t;
00046   pthread_mutex_init_rt(m_mutex, NULL);
00047 }
00048 
00049 MutexImplLxrt33::~MutexImplLxrt33()
00050 {
00051 #ifdef STRICT_LXRT_CHECKS
00052   if (!icl_core::os::IsThisLxrtTask())
00053   {
00054     PRINTF("MutexImplLxrt33::~MutexImplLxrt33: Called from a Linux task!\n");
00055     return;
00056   }
00057 #endif
00058   if (m_mutex)
00059   {
00060     pthread_mutex_destroy_rt(m_mutex);
00061     delete m_mutex;
00062     m_mutex = 0;
00063   }
00064 }
00065 
00066 bool MutexImplLxrt33::lock()
00067 {
00068 #ifdef STRICT_LXRT_CHECKS
00069   if (!icl_core::os::isThisLxrtTask())
00070   {
00071     PRINTF("MutexImplLxrt33::lock: Called from a Linux task!\n");
00072     return false;
00073   }
00074 #endif
00075   return pthread_mutex_lock_rt(m_mutex) == 0;
00076 }
00077 
00078 bool MutexImplLxrt33::lock(const icl_core::TimeSpan& timeout)
00079 {
00080 #ifdef STRICT_LXRT_CHECKS
00081   if (!icl_core::os::isThisLxrtTask())
00082   {
00083     PRINTF("MutexImplLxrt33::lock: Called from a Linux task!\n");
00084     return false;
00085   }
00086 #endif
00087   return lock(impl::getAbsoluteTimeout(timeout));
00088 }
00089 
00090 bool MutexImplLxrt33::lock(const icl_core::TimeStamp& timeout)
00091 {
00092 #ifdef STRICT_LXRT_CHECKS
00093   if (!icl_core::os::isThisLxrtTask())
00094   {
00095     PRINTF("MutexImplLxrt33::lock: Called from a Linux task!\n");
00096     return false;
00097   }
00098 #endif
00099   struct timespec timeout_absolute_timespec = timeout.systemTimespec();
00100   bool ret = (pthread_mutex_timedlock_rt(m_mutex, & timeout_absolute_timespec) == 0);
00101   return ret;
00102 }
00103 
00104 bool MutexImplLxrt33::tryLock()
00105 {
00106 #ifdef STRICT_LXRT_CHECKS
00107   if (!icl_core::os::isThisLxrtTask())
00108   {
00109     PRINTF("MutexImplLxrt33::tryLock: Called from a Linux task!\n");
00110     return false;
00111   }
00112 #endif
00113   bool ret = (pthread_mutex_trylock_rt(m_mutex) == 0);
00114   return ret;
00115 }
00116 
00117 void MutexImplLxrt33::unlock()
00118 {
00119 #ifdef STRICT_LXRT_CHECKS
00120   if (!icl_core::os::isThisLxrtTask())
00121   {
00122     PRINTF("MutexImplLxrt33::unlock: Called from a Linux task!\n");
00123     return;
00124   }
00125 #endif
00126   pthread_mutex_unlock_rt(m_mutex);
00127 }
00128 
00129 }
00130 }


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