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 //---------------------------------------------------------------------- 00022 //---------------------------------------------------------------------- 00023 #include "icl_core_thread/Sem.h" 00024 00025 00026 #if defined _SYSTEM_LXRT_ 00027 # include "SemaphoreImplLxrt.h" 00028 #endif 00029 00030 #if defined _SYSTEM_DARWIN_ 00031 # include "SemaphoreImplDarwin.h" 00032 #elif defined _SYSTEM_POSIX_ 00033 # include "SemaphoreImplPosix.h" 00034 #elif defined _SYSTEM_WIN32_ 00035 # include "SemaphoreImplWin32.h" 00036 #else 00037 # error "No semaphore implementation defined for this platform." 00038 #endif 00039 00040 namespace icl_core { 00041 namespace thread { 00042 00043 Semaphore::Semaphore(size_t initial_value) 00044 : m_impl(0) 00045 { 00046 #if defined _SYSTEM_LXRT_ 00047 // Only create an LXRT implementation if the LXRT runtime system is 00048 // really available. Otherwise create an ACE or POSIX 00049 // implementation, depending on the system configuration. 00050 // Remark: This allows us to compile programs with LXRT support but 00051 // run them on systems on which no LXRT is installed and to disable 00052 // LXRT support at program startup on systems with installed LXRT! 00053 if (icl_core::os::isLxrtAvailable()) 00054 { 00055 m_impl = new SemaphoreImplLxrt(initial_value); 00056 } 00057 else 00058 { 00059 m_impl = new SemaphoreImplPosix(initial_value); 00060 } 00061 00062 #elif defined _SYSTEM_DARWIN_ 00063 m_impl = new SemaphoreImplDarwin(initial_value); 00064 00065 #elif defined _SYSTEM_POSIX_ 00066 m_impl = new SemaphoreImplPosix(initial_value); 00067 00068 #elif defined _SYSTEM_WIN32_ 00069 m_impl = new SemaphoreImplWin32(initial_value); 00070 00071 #endif 00072 } 00073 00074 Semaphore::~Semaphore() 00075 { 00076 delete m_impl; 00077 m_impl = 0; 00078 } 00079 00080 void Semaphore::post() 00081 { 00082 return m_impl->post(); 00083 } 00084 00085 bool Semaphore::tryWait() 00086 { 00087 return m_impl->tryWait(); 00088 } 00089 00090 bool Semaphore::wait() 00091 { 00092 return m_impl->wait(); 00093 } 00094 00095 bool Semaphore::wait(const icl_core::TimeSpan& timeout) 00096 { 00097 return m_impl->wait(timeout); 00098 } 00099 00100 bool Semaphore::wait(const icl_core::TimeStamp& timeout) 00101 { 00102 return m_impl->wait(timeout); 00103 } 00104 00106 #ifdef _IC_BUILDER_DEPRECATED_STYLE_ 00107 00111 void Semaphore::Post() 00112 { 00113 post(); 00114 } 00115 00119 bool Semaphore::TryWait() 00120 { 00121 return tryWait(); 00122 } 00123 00127 bool Semaphore::Wait() 00128 { 00129 return wait(); 00130 } 00131 00135 bool Semaphore::Wait(const icl_core::TimeSpan& timeout) 00136 { 00137 return wait(timeout); 00138 } 00139 00143 bool Semaphore::Wait(const icl_core::TimeStamp& timeout) 00144 { 00145 return wait(timeout); 00146 } 00147 00148 #endif 00149 00150 00151 } 00152 }