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


fzi_icl_core
Author(s):
autogenerated on Tue Aug 8 2017 02:28:03