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


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