00001 /*======================================================================= 00002 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00003 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00004 *** *** 00005 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00006 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00007 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00008 *** *** 00009 *** RESTRICTED RIGHTS LEGEND *** 00010 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00011 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00012 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00013 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00014 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00015 *** *** 00016 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00017 *** BORDEAUX, FRANCE *** 00018 *** ALL RIGHTS RESERVED *** 00019 **=======================================================================*/ 00020 /*======================================================================= 00021 ** Author : David Beilloin (Feb 2008) 00022 **=======================================================================*/ 00023 00024 #ifndef _SB_THREAD_AUTO_LOCK_H_ 00025 #define _SB_THREAD_AUTO_LOCK_H_ 00026 00027 #include <Inventor/SbBase.h> 00028 #include <Inventor/threads/SbThreadMutex.h> 00029 00030 class SbThreadRWMutex; 00031 00073 class SbThreadAutoLock { 00074 public: 00079 SbThreadAutoLock(SbThreadMutex *mutex) 00080 { 00081 m_mutex = mutex; 00082 if ( m_mutex ) 00083 m_mutex->lock(); 00084 } 00085 00086 SbThreadAutoLock( SbThreadMutex &mutex ) 00087 { 00088 m_mutex = &mutex; 00089 m_mutex->lock(); 00090 } 00091 00092 #ifndef HIDDEN_FROM_DOC 00093 ~SbThreadAutoLock() 00094 { 00095 if ( m_mutex ) 00096 m_mutex->unlock(); 00097 } 00098 #endif // HIDDEN_FROM_DOC 00099 00100 private: 00101 SbThreadMutex *m_mutex; 00102 }; 00103 00148 class SbThreadAutoReadLock { 00149 public: 00155 SbThreadAutoReadLock( SbThreadRWMutex *mutex ); 00156 SbThreadAutoReadLock( SbThreadRWMutex &mutex ); 00157 00158 #ifndef HIDDEN_FROM_DOC 00159 00162 ~SbThreadAutoReadLock(); 00163 #endif 00164 00169 int unlock(); 00174 int relock(); 00175 00176 private: 00177 SbThreadRWMutex *m_mutex; 00178 SbBool m_isLocked; 00179 00180 }; 00181 00228 class SbThreadAutoWriteLock { 00229 public: 00235 SbThreadAutoWriteLock( SbThreadRWMutex *mutex ); 00236 SbThreadAutoWriteLock( SbThreadRWMutex &mutex ); 00237 00238 #ifndef HIDDEN_FROM_DOC 00239 00242 ~SbThreadAutoWriteLock(); 00243 #endif 00244 00249 int unlock(); 00254 int relock(); 00255 00256 private: 00257 SbThreadRWMutex *m_mutex; 00258 SbBool m_isLocked; 00259 00260 }; 00261 00262 #endif //_SB_THREAD_AUTO_LOCK_H_ 00263 00264 00265