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 (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 00052 SoInventorBase 00053 { 00054 public: 00060 static void init(); 00061 00068 static void finish(); 00069 00074 static bool isInitialized(); 00075 00079 static SbBool shouldCreateMutex(); 00080 00084 static SbBool threadModeIsSet() 00085 { return s_threadModeIsSet; } 00086 00090 static SbBool isMultithread() 00091 { return s_isMultithreaded; } 00092 00097 static void enableMultithread(const SbBool flag) 00098 { 00099 if (!threadModeIsSet()) 00100 { 00101 s_isMultithreaded = flag; 00102 s_threadModeIsSet = TRUE; 00103 } 00104 } 00105 private: 00107 enum PowerState 00108 { 00110 RUNNING, 00112 RESUME, 00114 SUSPEND 00115 }; 00116 00118 static void setPowerState(PowerState state); 00119 00121 static PowerState getPowerState(); 00122 00123 // We are able to manage 2 multi-threads cases on MS Windows platforms: 00124 // 1- standard case where all threads share common global objects 00125 // and can interact each other (notification/rendering/multiGPU...) 00126 // 00127 // => this mode is enabled through envvar OIV_MULTITHREAD 00128 // 00129 // 2- Experimental case where each threads can be considered as a separate Open Inventor application 00130 // each thread do not share anything, and then are independent from each other. 00131 // The following objects are thread specific: 00132 // - SoSensorManager::m_pThreadSensorMgr : SoSensorManagerThread handling notification queues 00133 // - SoDB::SoGlobalDBInfos : main globalField, realTimeSensor sensor, realTime field 00134 // - SoGlobalField::nameDict : globalField's dictionnary 00135 // - 00136 // IMPORTANT: When using this mode, no notification MUST be done from a a thread to anoher. 00137 // (ie, it is not allowed to modified an Open Inventor field/node/scenegraph... from another 00138 // thread than the one who created the given object. 00139 // 00140 // => this mode is enabled through envvar OIV_MULTITHREAD_APPLICATION (required also OIV_MULTITHREAD to be set) 00141 // 00142 static SbBool isMultiThreadApplication() 00143 { 00144 if (s_isMultiThreadApplicationSet) 00145 return s_isMultiThreadApplication; 00146 return checkMultiThreadApplicationMode(); 00147 } 00148 00149 static void threadInit(); 00150 static void threadFinish(); 00151 00152 static bool checkMultithread() 00153 { return s_checkMultithread; } 00154 00155 // globalMutex provides a way for any application to use a global mutex. 00156 // It is also used inside OIV in some instances 00157 static SbThreadRWMutex* getGlobalMutex() 00158 { return globalMutex; } 00159 00160 // returns true if OIV_MULTITHREAD_APPLICATION_DISABLE_LOCK is set, it allows to 00161 // - disable any mutex lock even if OIV_MULTITHREAD is defined. 00162 // - do internal performance test with OIV_MULTITHREAD_APPLICATION mode set 00163 static SbBool forceShouldCreateMutex(); 00164 00165 // global lock for init/finish operation 00166 static SbThreadMutex s_initFinishLock; 00167 00168 // returns TRUE if we should use double precision math internally 00169 // see also SoPreference (OIV_DOUBLE_PRECISION) 00170 static inline bool useDoublePrecision() 00171 { return s_doublePrecision; } 00172 00173 static inline void setDoublePrecision( bool val ) 00174 { s_doublePrecision = val; } 00175 00176 // returns TRUE if we should print debug msg when getting Zero vector length 00177 // see also SoPreference (OIV_REPORT_ZERO_VECTORS) 00178 static inline bool useReportZeroVector() 00179 { return s_reportZeroVectors; } 00180 00181 // returns the current intersection epsilon value to use (OIV_INTERSECT_EPSILON) 00182 static inline double getIntersectionEpsilon() 00183 { return s_intersectionEpsilon; } 00184 00185 // returns the current intersection epsilon value to use (OIV_INTERSECT_EPSILON) 00186 static inline double getIntersectionEpsilonSquared() 00187 { return s_intersectionEpsilonSquared; } 00188 00189 static inline void setIntersectionEpsilon(double epsilon) 00190 { s_intersectionEpsilon = epsilon; s_intersectionEpsilonSquared = epsilon*epsilon;} 00191 00192 //return true if finish is on the run 00193 static bool isFinishing(); 00194 00195 private: 00196 // library usage counter 00197 static int s_initRefCount; 00198 00199 // The isMultithreaded flag can be set to true or false only one time, that's 00200 // why we need a threadModeIsSet flag. 00201 static SbBool s_threadModeIsSet; 00202 static SbBool s_isMultithreaded; 00203 00204 // The isMultithreadedApplication flag can be set to true or false only one time, that's 00205 // why we need a threadApplicationModeIsSet flag. 00206 static bool checkMultiThreadApplicationMode(); 00207 static bool s_isMultiThreadApplication; 00208 static bool s_isMultiThreadApplicationSet; 00209 00210 static const char *s_versionString; 00211 // Global mutex 00212 static SbThreadRWMutex *globalMutex; 00213 00214 static bool s_checkMultithread; 00215 00216 // Use double precision math internally? (OIV_DOUBLE_PRECISION) 00217 static bool s_doublePrecision; 00218 00219 // see SoPreference::OIV_REPORT_ZERO_VECTORS envvar 00220 static bool s_reportZeroVectors; 00221 00222 // see SoPreferences::OIV_INTERSECT_EPSILON 00223 static double s_intersectionEpsilon; 00224 static double s_intersectionEpsilonSquared; 00225 00226 static bool s_isFinishing; 00227 00229 static PowerState s_powerState; 00230 }; 00231 00232 #endif /* _SO_INVENTOR_BASE_ */ 00233 00234 00235