Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgSystem.h

Go to the documentation of this file.
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 
00010 #ifndef SG_SYSTEM_H
00011 #define SG_SYSTEM_H
00012 
00013 //----------------------------------------------------------------------------
00014 
00015 // Used by GNU Autotools
00016 #ifdef HAVE_CONFIG_H
00017 #include <config.h>
00018 #endif
00019 
00020 //----------------------------------------------------------------------------
00021 
00022 /** Avoid compiler warnings for unused variables.
00023     This function is more portable than using a \#pragma directive.
00024 */
00025 template <class T>
00026 inline void SG_UNUSED(const T&)
00027 {
00028 }
00029 
00030 /** Avoid compiler warnings for variables used only if NDEBUG is not defined.
00031     This macro is more portable than using a \#pragma directive.
00032 */
00033 #ifndef NDEBUG
00034 #define SG_DEBUG_ONLY(x)
00035 #else
00036 #define SG_DEBUG_ONLY(x) SG_UNUSED(x)
00037 #endif
00038 
00039 //----------------------------------------------------------------------------
00040 
00041 // Explicit inlining attributes. The macros are defined as non-empty only
00042 // if supported by the compiler (note that Intel ICC also defines __GNUC__,
00043 // but would ignore the attributes with a warning)
00044 
00045 #if defined(__GNUC__) && ! defined(__ICC)
00046 #define SG_ATTR_ALWAYS_INLINE __attribute__((always_inline))
00047 #define SG_ATTR_NOINLINE __attribute__((noinline))
00048 #else
00049 #define SG_ATTR_NOINLINE
00050 #define SG_ATTR_ALWAYS_INLINE
00051 #endif
00052 
00053 #if defined(__GNUC__) && ! defined(__ICC) && \
00054     (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
00055 #define SG_ATTR_FLATTEN __attribute__((flatten))
00056 #else
00057 #define SG_ATTR_FLATTEN
00058 #endif
00059 
00060 //----------------------------------------------------------------------------
00061 
00062 #include <sys/types.h>
00063 #if (BYTE_ORDER == BIG_ENDIAN)
00064 #define OTHER_BYTE_ORDER 0
00065 #else
00066 #define OTHER_BYTE_ORDER 1
00067 #endif
00068 
00069 //----------------------------------------------------------------------------
00070 
00071 /** Additional code to run in debug mode after an assertion failed. */
00072 class SgAssertionHandler
00073 {
00074 public:
00075     /** Constructor.
00076         Automatically registers the handler.
00077     */
00078     SgAssertionHandler();
00079 
00080     /** Constructor.
00081         Automatically unregisters the handler.
00082     */
00083     virtual ~SgAssertionHandler();
00084 
00085     virtual void Run() = 0;
00086 };
00087 
00088 #ifndef NDEBUG
00089 
00090 /** System-specific action when an SG_ASSERT fails */
00091 void SgHandleAssertion(const char* expr, const char* file, int line);
00092 
00093 #define SG_ASSERT(x) \
00094     do \
00095     { \
00096         if(! (x)) \
00097             ::SgHandleAssertion(#x, __FILE__, __LINE__); \
00098     } while (false)
00099 #else
00100 #define SG_ASSERT(x) (static_cast<void>(0))
00101 #endif
00102 
00103 #define SG_ASSERTRANGE(i, from, to) SG_ASSERT(i >= from && i <= to)
00104 
00105 //----------------------------------------------------------------------------
00106 
00107 #ifndef NDEBUG
00108 const bool SG_CHECK = true;
00109 const bool SG_HEAVYCHECK = SG_CHECK && true;
00110 #else
00111 const bool SG_CHECK = false;
00112 const bool SG_HEAVYCHECK = false;
00113 #endif
00114 
00115 //----------------------------------------------------------------------------
00116 
00117 /** Sets the global user abort flag.
00118     This flag should be set to false at the beginning of each user event,
00119     e.g. each GUI event or GTP command.
00120     Lengthy functions should poll the user abort flag with SgUserAbort and
00121     abort, if necessary; they should not reset the flag themselves.
00122     It can also be called from a different thread (the abort flag is
00123     declared volatile).
00124 */
00125 void SgSetUserAbort(bool aborted);
00126 
00127 /** Poll for user abort.
00128     @see SgSetUserAbort.
00129 */
00130 bool SgUserAbort();
00131 
00132 //----------------------------------------------------------------------------
00133 
00134 inline void SgSynchronizeThreadMemory()
00135 {
00136 #ifdef ENABLE_CACHE_SYNC
00137 
00138 #ifdef HAVE_SYNC_SYNCHRONIZE
00139     __sync_synchronize();
00140 #else
00141 #error "Explicit cache synchronization requires __sync_synchronize() builtin"
00142 #endif
00143 
00144 #endif
00145 }
00146 
00147 //----------------------------------------------------------------------------
00148 
00149 #endif // SG_SYSTEM_H


17 Jun 2010 Doxygen 1.4.7