settings.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #if defined(LIBCO_C)
  2. /*[amd64, arm, ppc, x86]:
  3. by default, co_swap_function is marked as a text (code) section
  4. if not supported, uncomment the below line to use mprotect instead */
  5. /* #define LIBCO_MPROTECT */
  6. /*[amd64]:
  7. Win64 only: provides a substantial speed-up, but will thrash XMM regs
  8. do not use this unless you are certain your application won't use SSE */
  9. /* #define LIBCO_NO_SSE */
  10. #if !defined(thread_local) /* User can override thread_local for obscure compilers */
  11. #if !defined(LIBCO_MP) /* Running in single-threaded environment */
  12. #define thread_local
  13. #else /* Running in multi-threaded environment */
  14. #if defined(__STDC_VERSION__) /* Compiling as C Language */
  15. #if defined(_MSC_VER) /* Don't rely on MSVC's C11 support */
  16. #define thread_local __declspec(thread)
  17. #elif __STDC_VERSION__ < 201112L /* If we are on C90/99 */
  18. #if defined(__clang__) || defined(__GNUC__) /* Clang and GCC */
  19. #define thread_local __thread
  20. #else /* Otherwise, we ignore the directive (unless user provides their own) */
  21. #define thread_local
  22. #endif
  23. #else /* C11 and newer define thread_local in threads.h */
  24. #include <threads.h>
  25. #endif
  26. #elif defined(__cplusplus) /* Compiling as C++ Language */
  27. #if __cplusplus < 201103L /* thread_local is a C++11 feature */
  28. #if defined(_MSC_VER)
  29. #define thread_local __declspec(thread)
  30. #elif defined(__clang__) || defined(__GNUC__)
  31. #define thread_local __thread
  32. #else /* Otherwise, we ignore the directive (unless user provides their own) */
  33. #define thread_local
  34. #endif
  35. #else /* In C++ >= 11, thread_local in a builtin keyword */
  36. /* Don't do anything */
  37. #endif
  38. #endif
  39. #endif
  40. #endif
  41. /* In alignas(a), 'a' should be a power of two that is at least the type's
  42. alignment and at most the implementation's alignment limit. This limit is
  43. 2**13 on MSVC. To be portable to MSVC through at least version 10.0,
  44. 'a' should be an integer constant, as MSVC does not support expressions
  45. such as 1 << 3.
  46. The following C11 requirements are NOT supported on MSVC:
  47. - If 'a' is zero, alignas has no effect.
  48. - alignas can be used multiple times; the strictest one wins.
  49. - alignas (TYPE) is equivalent to alignas (alignof (TYPE)).
  50. */
  51. #if !defined(alignas)
  52. #if defined(__STDC_VERSION__) /* C Language */
  53. #if defined(_MSC_VER) /* Don't rely on MSVC's C11 support */
  54. #define alignas(bytes) __declspec(align(bytes))
  55. #elif __STDC_VERSION__ >= 201112L /* C11 and above */
  56. #include <stdalign.h>
  57. #elif defined(__clang__) || defined(__GNUC__) /* C90/99 on Clang/GCC */
  58. #define alignas(bytes) __attribute__ ((aligned (bytes)))
  59. #else /* Otherwise, we ignore the directive (user should provide their own) */
  60. #define alignas(bytes)
  61. #endif
  62. #elif defined(__cplusplus) /* C++ Language */
  63. #if __cplusplus < 201103L
  64. #if defined(_MSC_VER)
  65. #define alignas(bytes) __declspec(align(bytes))
  66. #elif defined(__clang__) || defined(__GNUC__) /* C++98/03 on Clang/GCC */
  67. #define alignas(bytes) __attribute__ ((aligned (bytes)))
  68. #else /* Otherwise, we ignore the directive (unless user provides their own) */
  69. #define alignas(bytes)
  70. #endif
  71. #else /* C++ >= 11 has alignas keyword */
  72. /* Do nothing */
  73. #endif
  74. #endif /* = !defined(__STDC_VERSION__) && !defined(__cplusplus) */
  75. #endif
  76. #if !defined(LIBCO_ASSERT)
  77. #include <assert.h>
  78. #define LIBCO_ASSERT assert
  79. #endif
  80. #if !defined(LIBCO_MALLOC) || !defined(LIBCO_FREE)
  81. #include <stdlib.h>
  82. #define LIBCO_MALLOC malloc
  83. #define LIBCO_FREE free
  84. #endif
  85. #if defined(_MSC_VER)
  86. #define section(name) __declspec(allocate("." #name))
  87. #elif defined(__APPLE__)
  88. #define section(name) __attribute__((section("__TEXT,__" #name)))
  89. #else
  90. #define section(name) __attribute__((section("." #name "#")))
  91. #endif
  92. /* if defined(LIBCO_C) */
  93. #endif