RWLockImplLxrt38.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 //----------------------------------------------------------------------
00010 //----------------------------------------------------------------------
00011 #include "icl_core_thread/RWLockImplLxrt38.h"
00012 
00013 #include <rtai_posix.h>
00014 
00015 #include <icl_core/internal_raw_debug.h>
00016 #include <icl_core/os_lxrt.h>
00017 
00018 #include "icl_core_thread/Common.h"
00019 
00020 #undef STRICT_LXRT_CHECKS
00021 
00022 
00023 namespace icl_core {
00024 namespace thread {
00025 
00026 RWLockImplLxrt38::RWLockImplLxrt38()
00027   : m_rwlock(NULL)
00028 {
00029 #ifdef STRICT_LXRT_CHECKS
00030   if (!icl_core::os::isThisLxrtTask())
00031   {
00032     PRINTF("RWLockImplLxrt38::RWLockImplLxrt38: Called from a Linux task!\n");
00033     return;
00034   }
00035 #endif
00036   m_rwlock = rt_typed_rwl_init(size_t(this), RESEM_RECURS);
00037 }
00038 
00039 RWLockImplLxrt38::~RWLockImplLxrt38()
00040 {
00041 #ifdef STRICT_LXRT_CHECKS
00042   if (!icl_core::os::isThisLxrtTask())
00043   {
00044     PRINTF("RWLockImplLxrt38::~RWLockImplLxrt38: Called from a Linux task!\n");
00045     return;
00046   }
00047 #endif
00048   if (m_rwlock)
00049   {
00050     rt_rwl_delete(m_rwlock);
00051     m_rwlock = NULL;
00052   }
00053 }
00054 
00055 bool RWLockImplLxrt38::readLock()
00056 {
00057 #ifdef STRICT_LXRT_CHECKS
00058   if (!icl_core::os::isThisLxrtTask())
00059   {
00060     PRINTF("RWLockImplLxrt38::readLock: Called from a Linux task!\n");
00061     return false;
00062   }
00063 #endif
00064   return rt_rwl_rdlock(m_rwlock) == 0;
00065 }
00066 
00067 bool RWLockImplLxrt38::readLock(const icl_core::TimeStamp& timeout)
00068 {
00069 #ifdef STRICT_LXRT_CHECKS
00070   if (!icl_core::os::isThisLxrtTask())
00071   {
00072     PRINTF("RWLockImplLxrt38::readLock: Called from a Linux task!\n");
00073     return false;
00074   }
00075 #endif
00076   struct timespec timeout_spec = timeout.systemTimespec();
00077   int ret = rt_rwl_rdlock_until(m_rwlock, timespec2count(&timeout_spec));
00078   return (ret == 0);
00079 }
00080 
00081 bool RWLockImplLxrt38::readLock(const icl_core::TimeSpan& timeout)
00082 {
00083 #ifdef STRICT_LXRT_CHECKS
00084   if (!icl_core::os::isThisLxrtTask())
00085   {
00086     PRINTF("RWLockImplLxrt38::readLock: Called from a Linux task!\n");
00087     return false;
00088   }
00089 #endif
00090   return readLock(impl::getAbsoluteTimeout(timeout));
00091 }
00092 
00093 bool RWLockImplLxrt38::tryReadLock()
00094 {
00095 #ifdef STRICT_LXRT_CHECKS
00096   if (!icl_core::os::isThisLxrtTask())
00097   {
00098     PRINTF("RWLockImplLxrt38::tryReadLock: Called from a Linux task!\n");
00099     return false;
00100   }
00101 #endif
00102   int ret = rt_rwl_rdlock_if(m_rwlock);
00103   return (ret == 0);
00104 }
00105 
00106 bool RWLockImplLxrt38::writeLock()
00107 {
00108 #ifdef STRICT_LXRT_CHECKS
00109   if (!icl_core::os::isThisLxrtTask())
00110   {
00111     PRINTF("RWLockImplLxrt38::writeLock: Called from a Linux task!\n");
00112     return false;
00113   }
00114 #endif
00115   return rt_rwl_wrlock(m_rwlock) == 0;
00116 }
00117 
00118 bool RWLockImplLxrt38::writeLock(const icl_core::TimeStamp& timeout)
00119 {
00120 #ifdef STRICT_LXRT_CHECKS
00121   if (!icl_core::os::isThisLxrtTask())
00122   {
00123     PRINTF("RWLockImplLxrt38::writeLock: Called from a Linux task!\n");
00124     return false;
00125   }
00126 #endif
00127   struct timespec timeout_spec = timeout.systemTimespec();
00128   int ret = rt_rwl_wrlock_until(m_rwlock, timespec2count(&timeout_spec));
00129   return (ret == 0);
00130 }
00131 
00132 bool RWLockImplLxrt38::writeLock(const icl_core::TimeSpan& timeout)
00133 {
00134 #ifdef STRICT_LXRT_CHECKS
00135   if (!icl_core::os::isThisLxrtTask())
00136   {
00137     PRINTF("RWLockImplLxrt38::writeLock: Called from a Linux task!\n");
00138     return false;
00139   }
00140 #endif
00141   return writeLock(impl::getAbsoluteTimeout(timeout));
00142 }
00143 
00144 bool RWLockImplLxrt38::tryWriteLock()
00145 {
00146 #ifdef STRICT_LXRT_CHECKS
00147   if (!icl_core::os::isThisLxrtTask())
00148   {
00149     PRINTF("RWLockImplLxrt38::tryWriteLock: Called from a Linux task!\n");
00150     return false;
00151   }
00152 #endif
00153   int ret = rt_rwl_wrlock_if(m_rwlock);
00154   return ret == 0;
00155   /*
00156   // ATTENTION: Calling pthread_rwlock_trywrlock_rt() while another
00157   // thread holds a read lock seems to be buggy in RTAI 3.3, so the
00158   // following does NOT work:
00159   //   int ret = pthread_rwlock_trywrlock_rt(rwlock);
00160   //   return (ret == 0);
00161   // Therefore we call WriteLock() with a very short timeout!
00162   static icl_core::TimeSpan try_write_lock_timeout(0, 1);
00163   return writeLock(try_write_lock_timeout);
00164   */
00165 }
00166 
00167 void RWLockImplLxrt38::unlock()
00168 {
00169 #ifdef STRICT_LXRT_CHECKS
00170   if (!icl_core::os::isThisLxrtTask())
00171   {
00172     PRINTF("RWLockImplLxrt38::unlock: Called from a Linux task!\n");
00173     return;
00174   }
00175 #endif
00176   rt_rwl_unlock(m_rwlock);
00177 }
00178 
00179 }
00180 }


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