RWLock.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 //----------------------------------------------------------------------
00023 //----------------------------------------------------------------------
00024 #include "icl_core_thread/RWLock.h"
00025 
00026 #include <icl_core/os_lxrt.h>
00027 #include "icl_core_thread/Logging.h"
00028 
00029 #if defined _SYSTEM_LXRT_
00030 # include "icl_core_thread/RWLockImplLxrt.h"
00031 #endif
00032 
00033 #if defined _SYSTEM_POSIX_
00034 #  include "icl_core_thread/RWLockImplPosix.h"
00035 #elif defined _SYSTEM_WIN32_
00036 # include "icl_core_thread/RWLockImplWin32.h"
00037 #else
00038 # error "No rwlock implementation defined for this platform."
00039 #endif
00040 
00041 using icl_core::logging::endl;
00042 
00043 namespace icl_core {
00044 namespace thread {
00045 
00046 RWLock::RWLock()
00047   : m_impl(NULL)
00048 {
00049 #if defined _SYSTEM_LXRT_
00050   // Only create an LXRT implementation if the LXRT runtime system is
00051   // really available. Otherwise create an ACE or POSIX
00052   // implementation, depending on the system configuration.
00053   // Remark: This allows us to compile programs with LXRT support but
00054   // run them on systems on which no LXRT is installed and to disable
00055   // LXRT support at program startup on systems with installed LXRT!
00056   if (icl_core::os::isLxrtAvailable())
00057   {
00058     LOGGING_TRACE_C(IclCoreThread, RWLock, "Initializing LXRT rwlock." << endl);
00059     m_impl = new RWLockImplLxrt;
00060   }
00061   else
00062   {
00063     LOGGING_TRACE_C(IclCoreThread, RWLock, "Initializing POSIX rwlock." << endl);
00064     m_impl = new RWLockImplPosix;
00065   }
00066 
00067 #elif defined _SYSTEM_POSIX_
00068   LOGGING_TRACE_C(IclCoreThread, RWLock, "Initializing POSIX rwlock." << endl);
00069   m_impl = new RWLockImplPosix;
00070 
00071 #elif defined _SYSTEM_WIN32_
00072   LOGGING_TRACE_C(IclCoreThread, RWLock, "Initializing WIN32 rwlock." << endl);
00073   m_impl = new RWLockImplWin32;
00074 
00075 #endif
00076 }
00077 
00078 RWLock::~RWLock()
00079 {
00080   LOGGING_TRACE_C(IclCoreThread, RWLock, "Destroying rwlock." << endl);
00081   delete m_impl;
00082   m_impl = NULL;
00083 }
00084 
00085 bool RWLock::readLock()
00086 {
00087   LOGGING_TRACE_C(IclCoreThread, RWLock, "Read locking rwlock ..." << endl);
00088   bool result = m_impl->readLock();
00089   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock read lock "
00090                   << (result ? "successful" : "failed") << "." << endl);
00091   return result;
00092 }
00093 
00094 bool RWLock::readLock(const ::icl_core::TimeStamp& timeout)
00095 {
00096   LOGGING_TRACE_C(IclCoreThread, RWLock, "Read locking rwlock with absolute timeout "
00097                   << timeout << " ..." << endl);
00098   bool result = m_impl->readLock(timeout);
00099   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock read lock "
00100                   << (result ? "successful" : "failed") << "." << endl);
00101   return result;
00102 }
00103 
00104 bool RWLock::readLock(const ::icl_core::TimeSpan& timeout)
00105 {
00106   LOGGING_TRACE_C(IclCoreThread, RWLock, "Read locking rwlock with relative timeout "
00107                   << timeout << " ..." << endl);
00108   bool result = m_impl->readLock(timeout);
00109   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock read lock "
00110                   << (result ? "successful" : "failed") << "." << endl);
00111   return result;
00112 }
00113 
00114 bool RWLock::tryReadLock()
00115 {
00116   LOGGING_TRACE_C(IclCoreThread, RWLock, "Trying to read lock rwlock ..." << endl);
00117   bool result = m_impl->tryReadLock();
00118   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock try read lock "
00119                   << (result ? "successful" : "failed") << "." << endl);
00120   return result;
00121 }
00122 
00123 bool RWLock::writeLock()
00124 {
00125   LOGGING_TRACE_C(IclCoreThread, RWLock, "Write locking rwlock ..." << endl);
00126   bool result = m_impl->writeLock();
00127   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock write lock "
00128                   << (result ? "successful" : "failed") << "." << endl);
00129   return result;
00130 }
00131 
00132 bool RWLock::writeLock(const ::icl_core::TimeStamp& timeout)
00133 {
00134   LOGGING_TRACE_C(IclCoreThread, RWLock, "Write locking rwlock with absolute timeout "
00135                   << timeout << " ..." << endl);
00136   bool result = m_impl->writeLock(timeout);
00137   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock write lock "
00138                   << (result ? "successful" : "failed") << "." << endl);
00139   return result;
00140 }
00141 
00142 bool RWLock::writeLock(const ::icl_core::TimeSpan& timeout)
00143 {
00144   LOGGING_TRACE_C(IclCoreThread, RWLock, "Write locking rwlock with relative timeout "
00145                   << timeout << " ..." << endl);
00146   bool result = m_impl->writeLock(timeout);
00147   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock write lock "
00148                   << (result ? "successful" : "failed") << "." << endl);
00149   return result;
00150 }
00151 
00152 bool RWLock::tryWriteLock()
00153 {
00154   LOGGING_TRACE_C(IclCoreThread, RWLock, "Trying to write lock rwlock ..." << endl);
00155   bool result = m_impl->tryWriteLock();
00156   LOGGING_TRACE_C(IclCoreThread, RWLock, "RWLock try write lock "
00157                   << (result ? "successful" : "failed") << "." << endl);
00158   return result;
00159 }
00160 
00161 void RWLock::unlock()
00162 {
00163   LOGGING_TRACE_C(IclCoreThread, RWLock, "Unlocking rwlock." << endl);
00164   m_impl->unlock();
00165 }
00166 
00168 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00169 
00173   bool RWLock::ReadLock()
00174   {
00175     return readLock();
00176   }
00177 
00182   bool RWLock::ReadLock(const icl_core::TimeStamp& timeout)
00183   {
00184     return readLock(timeout);
00185   }
00186 
00191   bool RWLock::ReadLock(const icl_core::TimeSpan& timeout)
00192   {
00193     return readLock(timeout);
00194   }
00195 
00199   bool RWLock::TryReadLock()
00200   {
00201     return tryReadLock();
00202   }
00203 
00207   bool RWLock::WriteLock()
00208   {
00209     return writeLock();
00210   }
00211 
00216   bool RWLock::WriteLock(const icl_core::TimeStamp& timeout)
00217   {
00218     return writeLock(timeout);
00219   }
00220 
00225   bool RWLock::WriteLock(const icl_core::TimeSpan& timeout)
00226   {
00227     return writeLock(timeout);
00228   }
00229 
00233   bool RWLock::TryWriteLock()
00234   {
00235     return tryWriteLock();
00236   }
00237 
00241   void RWLock::Unlock()
00242   {
00243     unlock();
00244   }
00245 
00246 #endif
00247 
00248 
00249 }
00250 }


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