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-2017 BY FEI S.A.S, *** 00017 *** BORDEAUX, FRANCE *** 00018 *** ALL RIGHTS RESERVED *** 00019 **=======================================================================*/ 00020 /*======================================================================= 00021 ** Author : David Beilloin (MMM yyyy) 00022 **=======================================================================*/ 00023 00024 #ifndef _SO_INVENTOR_BASE_ 00025 #define _SO_INVENTOR_BASE_ 00026 00027 #include <Inventor/SbBase.h> 00028 #include <Inventor/STL/set> 00029 #include <Inventor/STL/map> 00030 00031 #include <Inventor/threads/SbThreadMutex.h> 00032 00033 class SbThreadRWMutex; 00034 00053 { 00054 public: 00060 static void init(); 00061 00068 static void finish(); 00069 00074 static bool isInitialized(); 00075 00076 private: 00078 enum PowerState 00079 { 00081 RUNNING, 00083 RESUME, 00085 SUSPEND 00086 }; 00087 00089 static void setPowerState(PowerState state); 00090 00092 static PowerState getPowerState(); 00093 00094 // We are able to manage 2 multi-threads cases on MS Windows platforms: 00095 // 1- standard case where all threads share common global objects 00096 // and can interact each other (notification/rendering/multiGPU...) 00097 // 00098 // => this mode is enabled by default 00099 // 00100 // 2- Experimental case where each threads can be considered as a separate Open Inventor application 00101 // each thread do not share anything, and then are independent from each other. 00102 // The following objects are thread specific: 00103 // - SoSensorManager::m_pThreadSensorMgr : SoSensorManagerThread handling notification queues 00104 // - SoDB::SoGlobalDBInfos : main globalField, realTimeSensor sensor, realTime field 00105 // - SoGlobalField::nameDict : globalField's dictionnary 00106 // - 00107 // IMPORTANT: When using this mode, no notification MUST be done from a a thread to anoher. 00108 // (ie, it is not allowed to modified an Open Inventor field/node/scenegraph... from another 00109 // thread than the one who created the given object. 00110 // 00111 // => this mode is enabled through envvar OIV_MULTITHREAD_APPLICATION 00112 // 00113 static SbBool isMultiThreadApplication() 00114 { 00115 if (s_isMultiThreadApplicationSet) 00116 return s_isMultiThreadApplication; 00117 return checkMultiThreadApplicationMode(); 00118 } 00119 00120 #if 1 SoDEPRECATED 00122 static void threadInit(); 00123 SoDEPRECATED 00125 static void threadFinish(); 00126 #endif 00128 static bool checkMultithread() 00129 { return s_checkMultithread; } 00130 00131 // globalMutex provides a way for any application to use a global mutex. 00132 // It is also used inside OIV in some instances 00133 static SbThreadRWMutex* getGlobalMutex() 00134 { return globalMutex; } 00135 00136 // returns true if OIV_MULTITHREAD_APPLICATION_DISABLE_LOCK is set, it allows to disable 00137 // any mutex lock and do internal performance test with OIV_MULTITHREAD_APPLICATION mode set 00138 static SbBool forceShouldCreateMutex(); 00139 00140 // global lock for init/finish operation 00141 static SbThreadMutex s_initFinishLock; 00142 00143 // returns TRUE if we should use double precision math internally 00144 // see also SoPreference (OIV_DOUBLE_PRECISION) 00145 static inline bool useDoublePrecision() 00146 { return s_doublePrecision; } 00147 00148 static inline void setDoublePrecision( bool val ) 00149 { s_doublePrecision = val; } 00150 00151 // returns TRUE if we should print debug msg when getting Zero vector length 00152 // see also SoPreference (OIV_REPORT_ZERO_VECTORS) 00153 static inline bool useReportZeroVector() 00154 { return s_reportZeroVectors; } 00155 00156 // returns the current intersection epsilon value to use (OIV_INTERSECT_EPSILON) 00157 static inline double getIntersectionEpsilon() 00158 { return s_intersectionEpsilon; } 00159 00160 // returns the current intersection epsilon value to use (OIV_INTERSECT_EPSILON) 00161 static inline double getIntersectionEpsilonSquared() 00162 { return s_intersectionEpsilonSquared; } 00163 00164 static inline void setIntersectionEpsilon(double epsilon) 00165 { s_intersectionEpsilon = epsilon; s_intersectionEpsilonSquared = epsilon*epsilon;} 00166 00167 //return true if finish is on the run 00168 static bool isFinishing(); 00169 00170 private: 00171 // library usage counter 00172 static int s_initRefCount; 00173 00174 // The isMultithreadedApplication flag can be set to true or false only one time, that's 00175 // why we need a threadApplicationModeIsSet flag. 00176 static bool checkMultiThreadApplicationMode(); 00177 static bool s_isMultiThreadApplication; 00178 static bool s_isMultiThreadApplicationSet; 00179 00180 static const char *s_versionString; 00181 // Global mutex 00182 static SbThreadRWMutex *globalMutex; 00183 00184 static bool s_checkMultithread; 00185 00186 // Use double precision math internally? (OIV_DOUBLE_PRECISION) 00187 static bool s_doublePrecision; 00188 00189 // see SoPreference::OIV_REPORT_ZERO_VECTORS envvar 00190 static bool s_reportZeroVectors; 00191 00192 // see SoPreferences::OIV_INTERSECT_EPSILON 00193 static double s_intersectionEpsilon; 00194 static double s_intersectionEpsilonSquared; 00195 00196 static bool s_isFinishing; 00197 00199 static PowerState s_powerState; 00200 }; 00201 00202 #endif /* _SO_INVENTOR_BASE_ */ 00203 00204 00205