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-2014 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 00072 class SbThreadAutoLock { 00073 public: 00078 SbThreadAutoLock(SbThreadMutex *mutex) 00079 { 00080 m_mutex = mutex; 00081 if ( m_mutex ) 00082 m_mutex->lock(); 00083 } 00084 00085 SbThreadAutoLock( SbThreadMutex &mutex ) 00086 { 00087 m_mutex = &mutex; 00088 m_mutex->lock(); 00089 } 00090 00091 #ifndef HIDDEN_FROM_DOC 00092 ~SbThreadAutoLock() 00093 { 00094 if ( m_mutex ) 00095 m_mutex->unlock(); 00096 } 00097 #endif // HIDDEN_FROM_DOC 00098 00099 private: 00100 SbThreadMutex *m_mutex; 00101 }; 00102 00146 class SbThreadAutoReadLock { 00147 public: 00153 SbThreadAutoReadLock( SbThreadRWMutex *mutex ); 00154 SbThreadAutoReadLock( SbThreadRWMutex &mutex ); 00155 00156 #ifndef HIDDEN_FROM_DOC 00157 00160 ~SbThreadAutoReadLock(); 00161 #endif 00162 00167 int unlock(); 00172 int relock(); 00173 00174 private: 00175 SbThreadRWMutex *m_mutex; 00176 SbBool m_isLocked; 00177 00178 }; 00179 00225 class SbThreadAutoWriteLock { 00226 public: 00232 SbThreadAutoWriteLock( SbThreadRWMutex *mutex ); 00233 SbThreadAutoWriteLock( SbThreadRWMutex &mutex ); 00234 00235 #ifndef HIDDEN_FROM_DOC 00236 00239 ~SbThreadAutoWriteLock(); 00240 #endif 00241 00246 int unlock(); 00251 int relock(); 00252 00253 private: 00254 SbThreadRWMutex *m_mutex; 00255 SbBool m_isLocked; 00256 00257 }; 00258 00259 #endif //_SB_THREAD_AUTO_LOCK_H_ 00260 00261 00262