add several __has_something macro

With these macros implemented we can write codes just like we can assume
the compiler being clang.  MSC_VERSION_SINCE is defined to implement
those macros, but turned out to be handy for other places.  The -fdeclspec
compiler flag is necessary for clang to properly handle __has_declspec().
This commit is contained in:
卜部昌平 2019-12-02 14:58:43 +09:00
parent 863dbb21d8
commit 0958e19ffb
Notes: git 2019-12-26 20:46:07 +09:00
8 changed files with 115 additions and 30 deletions

View file

@ -38,7 +38,7 @@ typedef unsigned int rb_atomic_t; /* Anything OK */
# define RUBY_ATOMIC_GENERIC_MACRO 1
#elif defined _WIN32
#if defined _MSC_VER && _MSC_VER > 1200
#if MSC_VERSION_SINCE(1300)
#pragma intrinsic(_InterlockedOr)
#endif
typedef LONG rb_atomic_t;
@ -48,7 +48,7 @@ typedef LONG rb_atomic_t;
# define ATOMIC_DEC(var) InterlockedDecrement(&(var))
#if defined __GNUC__
# define ATOMIC_OR(var, val) __asm__("lock\n\t" "orl\t%1, %0" : "=m"(var) : "Ir"(val))
#elif defined _MSC_VER && _MSC_VER <= 1200
#elif MSC_VERSION_BEFORE(1300)
# define ATOMIC_OR(var, val) rb_w32_atomic_or(&(var), (val))
static inline void
rb_w32_atomic_or(volatile rb_atomic_t *var, rb_atomic_t val)
@ -66,7 +66,7 @@ rb_w32_atomic_or(volatile rb_atomic_t *var, rb_atomic_t val)
#endif
# define ATOMIC_EXCHANGE(var, val) InterlockedExchange(&(var), (val))
# define ATOMIC_CAS(var, oldval, newval) InterlockedCompareExchange(&(var), (newval), (oldval))
# if defined _MSC_VER && _MSC_VER <= 1200
# if MSC_VERSION_BEFORE(1300)
static inline rb_atomic_t
rb_w32_atomic_cas(volatile rb_atomic_t *var, rb_atomic_t oldval, rb_atomic_t newval)
{