00001 //---------------------------------------------------------------------------- 00002 /** @file SgSystem.h 00003 System specific definitions for SmartGo. 00004 00005 This file contains system specific defines and includes. 00006 It always needs to be the first header file included by any .cpp file. */ 00007 //---------------------------------------------------------------------------- 00008 00009 #ifndef SG_SYSTEM_H 00010 #define SG_SYSTEM_H 00011 00012 //---------------------------------------------------------------------------- 00013 00014 // Used by GNU Autotools 00015 #ifdef HAVE_CONFIG_H 00016 #include <config.h> 00017 #endif 00018 00019 //---------------------------------------------------------------------------- 00020 00021 /** Avoid compiler warnings for unused variables. 00022 This function is more portable than using a \#pragma directive. */ 00023 template <class T> 00024 inline void SG_UNUSED(const T&) 00025 { 00026 } 00027 00028 /** Avoid compiler warnings for variables used only if NDEBUG is not defined. 00029 This macro is more portable than using a \#pragma directive. */ 00030 #ifndef NDEBUG 00031 #define SG_DEBUG_ONLY(x) 00032 #else 00033 #define SG_DEBUG_ONLY(x) SG_UNUSED(x) 00034 #endif 00035 00036 //---------------------------------------------------------------------------- 00037 00038 // Explicit inlining attributes. The macros are defined as non-empty only 00039 // if supported by the compiler (note that Intel ICC also defines __GNUC__, 00040 // but would ignore the attributes with a warning) 00041 00042 #if defined(__GNUC__) && ! defined(__ICC) 00043 #define SG_ATTR_ALWAYS_INLINE __attribute__((always_inline)) 00044 #define SG_ATTR_NOINLINE __attribute__((noinline)) 00045 #else 00046 #define SG_ATTR_NOINLINE 00047 #define SG_ATTR_ALWAYS_INLINE 00048 #endif 00049 00050 #if defined(__GNUC__) && ! defined(__ICC) && \ 00051 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) 00052 #define SG_ATTR_FLATTEN __attribute__((flatten)) 00053 #else 00054 #define SG_ATTR_FLATTEN 00055 #endif 00056 00057 //---------------------------------------------------------------------------- 00058 00059 #include <sys/types.h> 00060 #if (BYTE_ORDER == BIG_ENDIAN) 00061 #define OTHER_BYTE_ORDER 0 00062 #else 00063 #define OTHER_BYTE_ORDER 1 00064 #endif 00065 00066 //---------------------------------------------------------------------------- 00067 00068 /** Additional code to run in debug mode after an assertion failed. */ 00069 class SgAssertionHandler 00070 { 00071 public: 00072 /** Constructor. 00073 Automatically registers the handler. */ 00074 SgAssertionHandler(); 00075 00076 /** Constructor. 00077 Automatically unregisters the handler. */ 00078 virtual ~SgAssertionHandler(); 00079 00080 virtual void Run() = 0; 00081 }; 00082 00083 #ifndef NDEBUG 00084 00085 /** System-specific action when an SG_ASSERT fails */ 00086 void SgHandleAssertion(const char* expr, const char* file, int line); 00087 00088 #define SG_ASSERT(x) \ 00089 do \ 00090 { \ 00091 if(! (x)) \ 00092 ::SgHandleAssertion(#x, __FILE__, __LINE__); \ 00093 } while (false) 00094 #else 00095 #define SG_ASSERT(x) (static_cast<void>(0)) 00096 #endif 00097 00098 #define SG_ASSERTRANGE(i, from, to) SG_ASSERT(i >= from && i <= to) 00099 00100 //---------------------------------------------------------------------------- 00101 00102 #ifndef NDEBUG 00103 const bool SG_CHECK = true; 00104 const bool SG_HEAVYCHECK = SG_CHECK && true; 00105 #else 00106 const bool SG_CHECK = false; 00107 const bool SG_HEAVYCHECK = false; 00108 #endif 00109 00110 //---------------------------------------------------------------------------- 00111 00112 #if defined(WIN32) && defined(_MSC_VER) 00113 00114 // Visual C++ already includes classes from the coming standard C++0x into 00115 // namespace std by default, which conflicts with classes from Boost 00116 // (e.g. shared_ptr). This can be disabled by defining the following macro. 00117 #define _HAS_CPP0X 0 00118 00119 // Don't report Visual C++ warning 4355 ('this' : used in base member 00120 // initializer list) in default warning level 3. Storing a reference to 00121 // 'this' is used at several places in the Fuego code (e.g. constructors of 00122 // thread functions). This is not a problem as long as 'this' is not used 00123 // yet. 00124 #pragma warning(4:4355) 00125 00126 // Disable Visual C++ warnings about unsafe functions from the standard 00127 // C++ library 00128 #define _CRT_SECURE_NO_WARNINGS 00129 #define _SCL_SECURE_NO_WARNINGS 00130 00131 #endif // defined(WIN32) && defined(_MSC_VER) 00132 00133 //---------------------------------------------------------------------------- 00134 00135 #ifdef __MINGW32__ 00136 00137 #define WIN32 1 00138 00139 // Enable Windows2000 (0x0500) compatibility in MinGW header files 00140 #define WINVER 0x0500 00141 #define _WIN32_WINNT 0x0500 00142 00143 #endif // __MINGW32__ 00144 00145 //---------------------------------------------------------------------------- 00146 00147 /** Sets the global user abort flag. 00148 This flag should be set to false at the beginning of each user event, 00149 e.g. each GUI event or GTP command. 00150 Lengthy functions should poll the user abort flag with SgUserAbort and 00151 abort, if necessary; they should not reset the flag themselves. 00152 It can also be called from a different thread (the abort flag is 00153 declared volatile). */ 00154 void SgSetUserAbort(bool aborted); 00155 00156 /** Poll for user abort. 00157 @see SgSetUserAbort. */ 00158 bool SgUserAbort(); 00159 00160 //---------------------------------------------------------------------------- 00161 00162 inline void SgSynchronizeThreadMemory() 00163 { 00164 #ifdef ENABLE_CACHE_SYNC 00165 00166 #ifdef HAVE_SYNC_SYNCHRONIZE 00167 __sync_synchronize(); 00168 #else 00169 #error "Explicit cache synchronization requires __sync_synchronize() builtin" 00170 #endif 00171 00172 #endif 00173 } 00174 00175 //---------------------------------------------------------------------------- 00176 00177 #endif // SG_SYSTEM_H