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


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