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 //---------------------------------------------------------------------- 00028 //---------------------------------------------------------------------- 00029 #ifndef ICL_CORE_THREAD_SCOPED_MUTEX_LOCK_H_INCLUDED 00030 #define ICL_CORE_THREAD_SCOPED_MUTEX_LOCK_H_INCLUDED 00031 00032 #include <icl_core/BaseTypes.h> 00033 #include <icl_core/Noncopyable.h> 00034 #include "icl_core_thread/ImportExport.h" 00035 00036 #ifdef _IC_BUILDER_DEPRECATED_STYLE_ 00037 # include "icl_core/Deprecate.h" 00038 #endif 00039 00040 namespace icl_core { 00041 namespace thread { 00042 00043 class Mutex; 00044 00050 class ICL_CORE_THREAD_IMPORT_EXPORT ScopedMutexLock : protected virtual icl_core::Noncopyable 00051 { 00052 public: 00057 explicit ScopedMutexLock(Mutex& mutex, bool force = true); 00060 ~ScopedMutexLock(); 00061 00064 bool isLocked() const { return m_is_locked; } 00065 00068 operator bool () const { return isLocked(); } 00069 00071 #ifdef _IC_BUILDER_DEPRECATED_STYLE_ 00072 00076 ICL_CORE_VC_DEPRECATE_STYLE bool IsLocked() const ICL_CORE_GCC_DEPRECATE_STYLE; 00077 00078 #endif 00079 00080 00081 private: 00082 Mutex& m_mutex; 00083 bool m_is_locked; 00084 }; 00085 00086 } 00087 } 00088 00089 #endif