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 00024 #include "icl_core_logging/ScopedSemaphore.h" 00025 #include "icl_core_logging/Semaphore.h" 00026 00027 namespace icl_core { 00028 namespace logging { 00029 00030 ScopedSemaphore::ScopedSemaphore(Semaphore& semaphore) 00031 : m_semaphore(semaphore), 00032 m_is_decremented(false) 00033 { 00034 if (m_semaphore.wait()) 00035 { 00036 m_is_decremented = true; 00037 } 00038 } 00039 00040 ScopedSemaphore::~ScopedSemaphore() 00041 { 00042 if (isDecremented()) 00043 { 00044 m_semaphore.post(); 00045 } 00046 } 00047 00049 #ifdef _IC_BUILDER_DEPRECATED_STYLE_ 00050 00054 bool ScopedSemaphore::IsDecremented() const 00055 { 00056 return isDecremented(); 00057 } 00058 00059 #endif 00060 00061 00062 } 00063 }