Mutex.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/Mutex.h"
00012 
00013 
00014 #include <icl_core/os_lxrt.h>
00015 
00016 #undef ICL_CORE_LOCAL_LOGGING
00017 //#define ICL_CORE_LOCAL_LOGGING
00018 #include "icl_core_thread/Logging.h"
00019 
00020 #define LOCAL_PRINTF(args)
00021 //#define LOCAL_PRINTF PRINTF
00022 
00023 #if defined _SYSTEM_LXRT_
00024 # include "icl_core_thread/MutexImplLxrt.h"
00025 #endif
00026 
00027 #if defined _SYSTEM_POSIX_
00028 #  include "icl_core_thread/MutexImplPosix.h"
00029 #elif defined _SYSTEM_WIN32_
00030 # include "icl_core_thread/MutexImplWin32.h"
00031 #else
00032 # error "No mutex implementation defined for this platform."
00033 #endif
00034 
00035 using icl_core::logging::endl;
00036 
00037 namespace icl_core {
00038 namespace thread {
00039 
00040 Mutex::Mutex()
00041   : m_impl(NULL)
00042 {
00043 #if defined _SYSTEM_LXRT_
00044   // Only create an LXRT implementation if the LXRT runtime system is
00045   // really available. Otherwise create an ACE or POSIX
00046   // implementation, depending on the system configuration.
00047   // Remark: This allows us to compile programs with LXRT support but
00048   // run them on systems on which no LXRT is installed and to disable
00049   // LXRT support at program startup on systems with installed LXRT!
00050   if (icl_core::os::isLxrtAvailable())
00051   {
00052     LOCAL_PRINTF("Initializing LXRT mutex.\n");
00053     m_impl = new MutexImplLxrt;
00054   }
00055   else
00056   {
00057     LOCAL_PRINTF("Initializing POSIX mutex.\n");
00058     m_impl = new MutexImplPosix;
00059   }
00060 
00061 #elif defined _SYSTEM_POSIX_
00062   LOCAL_PRINTF("Initializing POSIX mutex.\n");
00063   m_impl = new MutexImplPosix;
00064 
00065 #elif defined _SYSTEM_WIN32_
00066   LOCAL_PRINTF("Initializing WIN32 mutex.\n");
00067   m_impl = new MutexImplWin32;
00068 
00069 #endif
00070 }
00071 
00072 Mutex::~Mutex()
00073 {
00074   LOCAL_PRINTF("Destroying mutex.\n");
00075   delete m_impl;
00076   m_impl = NULL;
00077 }
00078 
00079 bool Mutex::lock()
00080 {
00081   LLOGGING_TRACE_C(Thread, Mutex, "Locking mutex ..." << endl);
00082   bool result = m_impl->lock();
00083   LLOGGING_TRACE_C(Thread, Mutex, "Mutex lock " << (result ? "successful" : "failed") << "." << endl);
00084   return result;
00085 }
00086 
00087 bool Mutex::lock(const ::icl_core::TimeStamp& timeout)
00088 {
00089   LLOGGING_TRACE_C(Thread, Mutex, "Locking mutex with absolute timeout " << timeout << " ..." << endl);
00090   bool result = m_impl->lock(timeout);
00091   LLOGGING_TRACE_C(Thread, Mutex, "Mutex lock " << (result ? "successful" : "failed") << "." << endl);
00092   return result;
00093 }
00094 
00095 bool Mutex::lock(const ::icl_core::TimeSpan& timeout)
00096 {
00097   LLOGGING_TRACE_C(Thread, Mutex, "Locking mutex with relative timeout " << timeout << " ..." << endl);
00098   bool result = m_impl->lock(timeout);
00099   LLOGGING_TRACE_C(Thread, Mutex, "Mutex lock " << (result ? "successful" : "failed") << "." << endl);
00100   return result;
00101 }
00102 
00103 bool Mutex::tryLock()
00104 {
00105   LLOGGING_TRACE_C(Thread, Mutex, "Trying to lock mutex ..." << endl);
00106   bool result = m_impl->tryLock();
00107   LLOGGING_TRACE_C(Thread, Mutex, "Mutex try-lock " << (result ? "successful" : "failed") << "." << endl);
00108   return result;
00109 }
00110 
00111 void Mutex::unlock()
00112 {
00113   LLOGGING_TRACE_C(Thread, Mutex, "Unlocking mutex." << endl);
00114   m_impl->unlock();
00115 }
00116 
00118 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00119 
00124 bool Mutex::Lock()
00125 {
00126   return lock();
00127 }
00128 
00133 bool Mutex::Lock(const icl_core::TimeStamp& timeout)
00134 {
00135   return lock(timeout);
00136 }
00137 
00142 bool Mutex::Lock(const icl_core::TimeSpan& timeout)
00143 {
00144   return lock(timeout);
00145 }
00146 
00153 bool Mutex::TryLock()
00154 {
00155   return tryLock();
00156 }
00157 
00160 void Mutex::Unlock()
00161 {
00162   unlock();
00163 }
00164 
00165 #endif
00166 
00167 
00168 }
00169 }


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