MSVC: implement some of the atomic operations via MSVC' Interlocked ops

These actually look sane; the outliers are the load/store pairs, but
given that the "alternative implementation" is just a plain old variable
load...
diff --git a/compat/compat.h.in b/compat/compat.h.in
index bb7cdb0..f8be220 100644
--- a/compat/compat.h.in
+++ b/compat/compat.h.in
@@ -108,10 +108,18 @@
 
 # define ATOMIC_STORE_RELAXED(var, x) ((var) = (x))
 # define ATOMIC_LOAD_RELAXED(var) (var)
-# define ATOMIC_INC_RELAXED(var) __sync_fetch_and_add(&(var), 1)
-# define ATOMIC_ADD_RELAXED(var, x) __sync_fetch_and_add(&(var), x)
-# define ATOMIC_DEC_RELAXED(var) __sync_fetch_and_sub(&(var), 1)
-# define ATOMIC_SUB_RELAXED(var, x) __sync_fetch_and_sub(&(var), x)
+# ifndef _WIN32
+#  define ATOMIC_INC_RELAXED(var) __sync_fetch_and_add(&(var), 1)
+#  define ATOMIC_ADD_RELAXED(var, x) __sync_fetch_and_add(&(var), x)
+#  define ATOMIC_DEC_RELAXED(var) __sync_fetch_and_sub(&(var), 1)
+#  define ATOMIC_SUB_RELAXED(var, x) __sync_fetch_and_sub(&(var), x)
+# else
+#  include <windows.h>
+#  define ATOMIC_INC_RELAXED(var) InterlockedExchangeAdd(&(var), 1)
+#  define ATOMIC_ADD_RELAXED(var, x) InterlockedExchangeAdd(&(var), x)
+#  define ATOMIC_DEC_RELAXED(var) InterlockedExchangeAdd(&(var), -1)
+#  define ATOMIC_SUB_RELAXED(var, x) InterlockedExchangeAdd(&(var), -(x))
+# endif
 #endif
 
 #ifndef HAVE_VDPRINTF
diff --git a/src/config.h.in b/src/config.h.in
index 9915a83..4f53f2e 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -25,8 +25,14 @@
 #define LYPLG_EXT_DIR "@PLUGINS_DIR_EXTENSIONS@"
 
 /** atomic compiler operations, to be able to use uint32_t */
-#define LY_ATOMIC_INC_BARRIER(var) __sync_fetch_and_add(&(var), 1)
-#define LY_ATOMIC_DEC_BARRIER(var) __sync_fetch_and_sub(&(var), 1)
+#ifndef _WIN32
+# define LY_ATOMIC_INC_BARRIER(var) __sync_fetch_and_add(&(var), 1)
+# define LY_ATOMIC_DEC_BARRIER(var) __sync_fetch_and_sub(&(var), 1)
+#else
+#  include <windows.h>
+# define LY_ATOMIC_INC_BARRIER(var) InterlockedExchangeAdd(&(var), 1)
+# define LY_ATOMIC_DEC_BARRIER(var) InterlockedExchangeAdd(&(var), -1)
+#endif
 
 /** printf compiler attribute */
 #ifdef __GNUC__