RWLock.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/RWLock.h"
00012 
00013 #include <icl_core/os_lxrt.h>
00014 #include "icl_core_thread/Logging.h"
00015 
00016 #if defined _SYSTEM_LXRT_
00017 # include "icl_core_thread/RWLockImplLxrt.h"
00018 #endif
00019 
00020 #if defined _SYSTEM_POSIX_
00021 #  include "icl_core_thread/RWLockImplPosix.h"
00022 #elif defined _SYSTEM_WIN32_
00023 # include "icl_core_thread/RWLockImplWin32.h"
00024 #else
00025 # error "No rwlock implementation defined for this platform."
00026 #endif
00027 
00028 using icl_core::logging::endl;
00029 
00030 namespace icl_core {
00031 namespace thread {
00032 
00033 RWLock::RWLock()
00034   : m_impl(NULL)
00035 {
00036 #if defined _SYSTEM_LXRT_
00037   // Only create an LXRT implementation if the LXRT runtime system is
00038   // really available. Otherwise create an ACE or POSIX
00039   // implementation, depending on the system configuration.
00040   // Remark: This allows us to compile programs with LXRT support but
00041   // run them on systems on which no LXRT is installed and to disable
00042   // LXRT support at program startup on systems with installed LXRT!
00043   if (icl_core::os::isLxrtAvailable())
00044   {
00045     LOGGING_TRACE_C(IclCoreThread, RWLock, "Initializing LXRT rwlock." << endl);
00046     m_impl = new RWLockImplLxrt;
00047   }
00048   else
00049   {
00050     LOGGING_TRACE_C(IclCoreThread, RWLock, "Initializing POSIX rwlock." << endl);
00051     m_impl = new RWLockImplPosix;
00052   }
00053 
00054 #elif defined _SYSTEM_POSIX_
00055   LOGGING_TRACE_C(IclCoreThread, RWLock, "Initializing POSIX rwlock." << endl);
00056   m_impl = new RWLockImplPosix;
00057 
00058 #elif defined _SYSTEM_WIN32_
00059   LOGGING_TRACE_C(IclCoreThread, RWLock, "Initializing WIN32 rwlock." << endl);
00060   m_impl = new RWLockImplWin32;
00061 
00062 #endif
00063 }
00064 
00065 RWLock::~RWLock()
00066 {
00067   LOGGING_TRACE_C(IclCoreThread, RWLock, "Destroying rwlock." << endl);
00068   delete m_impl;
00069   m_impl = NULL;
00070 }
00071 
00072 bool RWLock::readLock()
00073 {
00074   LOGGING_TRACE_C(IclCoreThread, RWLock, "Read locking rwlock ..." << endl);
00075   bool result = m_impl->readLock();
00076   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock read lock "
00077                   << (result ? "successful" : "failed") << "." << endl);
00078   return result;
00079 }
00080 
00081 bool RWLock::readLock(const ::icl_core::TimeStamp& timeout)
00082 {
00083   LOGGING_TRACE_C(IclCoreThread, RWLock, "Read locking rwlock with absolute timeout "
00084                   << timeout << " ..." << endl);
00085   bool result = m_impl->readLock(timeout);
00086   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock read lock "
00087                   << (result ? "successful" : "failed") << "." << endl);
00088   return result;
00089 }
00090 
00091 bool RWLock::readLock(const ::icl_core::TimeSpan& timeout)
00092 {
00093   LOGGING_TRACE_C(IclCoreThread, RWLock, "Read locking rwlock with relative timeout "
00094                   << timeout << " ..." << endl);
00095   bool result = m_impl->readLock(timeout);
00096   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock read lock "
00097                   << (result ? "successful" : "failed") << "." << endl);
00098   return result;
00099 }
00100 
00101 bool RWLock::tryReadLock()
00102 {
00103   LOGGING_TRACE_C(IclCoreThread, RWLock, "Trying to read lock rwlock ..." << endl);
00104   bool result = m_impl->tryReadLock();
00105   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock try read lock "
00106                   << (result ? "successful" : "failed") << "." << endl);
00107   return result;
00108 }
00109 
00110 bool RWLock::writeLock()
00111 {
00112   LOGGING_TRACE_C(IclCoreThread, RWLock, "Write locking rwlock ..." << endl);
00113   bool result = m_impl->writeLock();
00114   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock write lock "
00115                   << (result ? "successful" : "failed") << "." << endl);
00116   return result;
00117 }
00118 
00119 bool RWLock::writeLock(const ::icl_core::TimeStamp& timeout)
00120 {
00121   LOGGING_TRACE_C(IclCoreThread, RWLock, "Write locking rwlock with absolute timeout "
00122                   << timeout << " ..." << endl);
00123   bool result = m_impl->writeLock(timeout);
00124   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock write lock "
00125                   << (result ? "successful" : "failed") << "." << endl);
00126   return result;
00127 }
00128 
00129 bool RWLock::writeLock(const ::icl_core::TimeSpan& timeout)
00130 {
00131   LOGGING_TRACE_C(IclCoreThread, RWLock, "Write locking rwlock with relative timeout "
00132                   << timeout << " ..." << endl);
00133   bool result = m_impl->writeLock(timeout);
00134   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock write lock "
00135                   << (result ? "successful" : "failed") << "." << endl);
00136   return result;
00137 }
00138 
00139 bool RWLock::tryWriteLock()
00140 {
00141   LOGGING_TRACE_C(IclCoreThread, RWLock, "Trying to write lock rwlock ..." << endl);
00142   bool result = m_impl->tryWriteLock();
00143   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock try write lock "
00144                   << (result ? "successful" : "failed") << "." << endl);
00145   return result;
00146 }
00147 
00148 void RWLock::unlock()
00149 {
00150   LOGGING_TRACE_C(IclCoreThread, RWLock, "Unlocking rwlock." << endl);
00151   m_impl->unlock();
00152 }
00153 
00155 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00156 
00160   bool RWLock::ReadLock()
00161   {
00162     return readLock();
00163   }
00164 
00169   bool RWLock::ReadLock(const icl_core::TimeStamp& timeout)
00170   {
00171     return readLock(timeout);
00172   }
00173 
00178   bool RWLock::ReadLock(const icl_core::TimeSpan& timeout)
00179   {
00180     return readLock(timeout);
00181   }
00182 
00186   bool RWLock::TryReadLock()
00187   {
00188     return tryReadLock();
00189   }
00190 
00194   bool RWLock::WriteLock()
00195   {
00196     return writeLock();
00197   }
00198 
00203   bool RWLock::WriteLock(const icl_core::TimeStamp& timeout)
00204   {
00205     return writeLock(timeout);
00206   }
00207 
00212   bool RWLock::WriteLock(const icl_core::TimeSpan& timeout)
00213   {
00214     return writeLock(timeout);
00215   }
00216 
00220   bool RWLock::TryWriteLock()
00221   {
00222     return tryWriteLock();
00223   }
00224 
00228   void RWLock::Unlock()
00229   {
00230     unlock();
00231   }
00232 
00233 #endif
00234 
00235 
00236 }
00237 }


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