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_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 00058 class SbThreadSpinlock 00059 { 00060 public: 00064 SbThreadSpinlock() ; 00068 ~SbThreadSpinlock() ; 00069 00073 void lock() ; 00074 00078 void unlock() ; 00079 00080 private: 00081 #if defined(_WIN32) 00082 LONG volatile m_spinLock; 00083 SbThreadId_t m_curThread; 00084 int m_enterCount; 00085 #else 00086 SbThreadMutex m_spinLock; 00087 #endif 00088 }; 00089 00126 class SbThreadAutoSpinlock { 00127 public: 00132 SbThreadAutoSpinlock(SbThreadSpinlock *spinlock) 00133 { 00134 m_spinlock = spinlock; 00135 if ( m_spinlock ) 00136 m_spinlock->lock(); 00137 } 00138 00139 SbThreadAutoSpinlock( SbThreadSpinlock &spinlock ) 00140 { 00141 m_spinlock = &spinlock; 00142 m_spinlock->lock(); 00143 } 00144 00145 #ifndef HIDDEN_FROM_DOC 00146 ~SbThreadAutoSpinlock() 00147 { 00148 if ( m_spinlock ) 00149 m_spinlock->unlock(); 00150 } 00151 #endif // HIDDEN_FROM_DOC 00152 00153 private: 00154 // Default constructor not accessible 00155 SbThreadAutoSpinlock() 00156 :m_spinlock(NULL) 00157 {} 00158 00159 // Copy constructor not accessible 00160 SbThreadAutoSpinlock(const SbThreadAutoSpinlock&) 00161 :m_spinlock(NULL) 00162 {} 00163 00164 SbThreadSpinlock *m_spinlock; 00165 }; 00166 00167 #endif // _SB_THREAD_SPINLOCK_H_ 00168 00169 00170