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_SPINLOCK_H_ 00025 #define _SB_THREAD_SPINLOCK_H_ 00026 00027 #include <Inventor/SbBase.h> 00028 #include <Inventor/threads/SbThread.h> 00029 #include <Inventor/threads/SbThreadMutex.h> 00030 00059 class SbThreadSpinlock 00060 { 00061 public: 00065 SbThreadSpinlock() ; 00069 ~SbThreadSpinlock() ; 00070 00074 void lock() ; 00075 00079 void unlock() ; 00080 00081 private: 00082 #if defined(_WIN32) 00083 LONG volatile m_spinLock; 00084 SbThreadId_t m_curThread; 00085 int m_enterCount; 00086 #else 00087 SbThreadMutex m_spinLock; 00088 #endif 00089 }; 00090 00125 class SbThreadAutoSpinlock { 00126 public: 00131 SbThreadAutoSpinlock(SbThreadSpinlock *spinlock) 00132 { 00133 m_spinlock = spinlock; 00134 if ( m_spinlock ) 00135 m_spinlock->lock(); 00136 } 00137 00138 SbThreadAutoSpinlock( SbThreadSpinlock &spinlock ) 00139 { 00140 m_spinlock = &spinlock; 00141 m_spinlock->lock(); 00142 } 00143 00144 #ifndef HIDDEN_FROM_DOC 00145 ~SbThreadAutoSpinlock() 00146 { 00147 if ( m_spinlock ) 00148 m_spinlock->unlock(); 00149 } 00150 #endif // HIDDEN_FROM_DOC 00151 00152 private: 00153 // Default constructor not accessible 00154 SbThreadAutoSpinlock() 00155 :m_spinlock(NULL) 00156 {} 00157 00158 // Copy constructor not accessible 00159 SbThreadAutoSpinlock(const SbThreadAutoSpinlock&) 00160 :m_spinlock(NULL) 00161 {} 00162 00163 SbThreadSpinlock *m_spinlock; 00164 }; 00165 00166 #endif // _SB_THREAD_SPINLOCK_H_ 00167 00168 00169