eathread_sync_gcc.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) Electronic Arts Inc. All rights reserved.
  3. ///////////////////////////////////////////////////////////////////////////////
  4. #if defined(EA_PRAGMA_ONCE_SUPPORTED)
  5. #pragma once // Some compilers (e.g. VC++) benefit significantly from using this. We've measured 3-4% build speed improvements in apps as a result.
  6. #endif
  7. /////////////////////////////////////////////////////////////////////////////
  8. // Functionality related to memory and code generation synchronization.
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef EATHREAD_GCC_EATHREAD_SYNC_GCC_H
  11. #define EATHREAD_GCC_EATHREAD_SYNC_GCC_H
  12. #include <EABase/eabase.h>
  13. #define EA_THREAD_SYNC_IMPLEMENTED
  14. // EAProcessorPause
  15. // Intel has defined a 'pause' instruction for x86 processors starting with the P4, though this simply
  16. // maps to the otherwise undocumented 'rep nop' instruction. This pause instruction is important for
  17. // high performance spinning, as otherwise a high performance penalty incurs.
  18. #if defined(EA_PROCESSOR_X86) || defined(EA_PROCESSOR_X86_64)
  19. #define EAProcessorPause() __asm__ __volatile__ ("rep ; nop")
  20. #else
  21. #define EAProcessorPause()
  22. #endif
  23. // EAReadBarrier / EAWriteBarrier / EAReadWriteBarrier
  24. // The x86 processor memory architecture ensures read and write consistency on both single and
  25. // multi processing systems. This makes programming simpler but limits maximimum system performance.
  26. // We define EAReadBarrier here to be the same as EACompilerMemory barrier in order to limit the
  27. // compiler from making any assumptions at its level about memory usage. Year 2003+ versions of the
  28. // Microsoft SDK define a 'MemoryBarrier' statement which has the same effect as EAReadWriteBarrier.
  29. #if (((__GNUC__ * 100) + __GNUC_MINOR__) >= 401) // GCC 4.1 or later
  30. #define EAReadBarrier __sync_synchronize
  31. #define EAWriteBarrier __sync_synchronize
  32. #define EAReadWriteBarrier __sync_synchronize
  33. #else
  34. #define EAReadBarrier EACompilerMemoryBarrier
  35. #define EAWriteBarrier EACompilerMemoryBarrier
  36. #define EAReadWriteBarrier EACompilerMemoryBarrier
  37. #endif
  38. // EACompilerMemoryBarrier
  39. #if defined(EA_PROCESSOR_ARM) || defined(EA_PROCESSOR_X86) || defined(EA_PROCESSOR_X86_64)
  40. #define EACompilerMemoryBarrier() __asm__ __volatile__ ("":::"memory")
  41. #else
  42. #define EACompilerMemoryBarrier()
  43. #endif
  44. #endif // EATHREAD_GCC_EATHREAD_SYNC_GCC_H