7a6331
diff --git a/src/include/thread.h b/src/include/thread.h
7a6331
index 2303c3e..039a98d 100644
7a6331
--- a/src/include/thread.h
7a6331
+++ b/src/include/thread.h
7a6331
@@ -87,9 +87,15 @@
7a6331
 #  include <tbb/spin_mutex.h>
7a6331
 #endif
7a6331
 
7a6331
-#ifdef _WIN32
7a6331
+#if defined(_WIN32) && !USE_TBB
7a6331
 #  include <windows.h>
7a6331
 #  include <winbase.h>
7a6331
+#  pragma intrinsic (_InterlockedExchangeAdd)
7a6331
+#  pragma intrinsic (_InterlockedCompareExchange)
7a6331
+#  pragma intrinsic (_InterlockedCompareExchange64)
7a6331
+#  if defined(_WIN64)
7a6331
+#    pragma intrinsic(_InterlockedExchangeAdd64)
7a6331
+#  endif
7a6331
 #endif
7a6331
 
7a6331
 #ifdef __APPLE__
7a6331
@@ -250,7 +256,7 @@ private:
7a6331
 inline int
7a6331
 atomic_exchange_and_add (volatile int *at, int x)
7a6331
 {
7a6331
-#if defined(__GNUC__) && defined(_GLIBCXX_ATOMIC_BUILTINS)
7a6331
+#if defined(__GNUC__) && (defined(_GLIBCXX_ATOMIC_BUILTINS) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 401))
7a6331
     return __sync_fetch_and_add ((int *)at, x);
7a6331
 #elif USE_TBB
7a6331
     atomic<int> *a = (atomic<int> *)at;
7a6331
@@ -260,9 +266,9 @@ atomic_exchange_and_add (volatile int *at, int x)
7a6331
     return OSAtomicAdd32Barrier (x, at) - x;
7a6331
 #elif defined(_WIN32)
7a6331
     // Windows
7a6331
-    return InterlockedExchangeAdd ((volatile LONG *)at, x);
7a6331
+    return _InterlockedExchangeAdd ((volatile LONG *)at, x);
7a6331
 #else
7a6331
-    error ("No atomics on this platform.")
7a6331
+#   error No atomics on this platform.
7a6331
 #endif
7a6331
 }
7a6331
 
7a6331
@@ -271,7 +277,7 @@ atomic_exchange_and_add (volatile int *at, int x)
7a6331
 inline long long
7a6331
 atomic_exchange_and_add (volatile long long *at, long long x)
7a6331
 {
7a6331
-#if defined(__GNUC__) && defined(_GLIBCXX_ATOMIC_BUILTINS)
7a6331
+#if defined(__GNUC__) && (defined(_GLIBCXX_ATOMIC_BUILTINS) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 401))
7a6331
     return __sync_fetch_and_add (at, x);
7a6331
 #elif USE_TBB
7a6331
     atomic<long long> *a = (atomic<long long> *)at;
7a6331
@@ -281,9 +287,13 @@ atomic_exchange_and_add (volatile long long *at, long long x)
7a6331
     return OSAtomicAdd64Barrier (x, at) - x;
7a6331
 #elif defined(_WIN32)
7a6331
     // Windows
7a6331
+#  if defined(_WIN64)
7a6331
+    return _InterlockedExchangeAdd64 ((volatile LONGLONG *)at, x);
7a6331
+#  else
7a6331
     return InterlockedExchangeAdd64 ((volatile LONGLONG *)at, x);
7a6331
+#  endif
7a6331
 #else
7a6331
-    error ("No atomics on this platform.")
7a6331
+#   error No atomics on this platform.
7a6331
 #endif
7a6331
 }
7a6331
 
7a6331
@@ -298,7 +308,7 @@ atomic_exchange_and_add (volatile long long *at, long long x)
7a6331
 inline bool
7a6331
 atomic_compare_and_exchange (volatile int *at, int compareval, int newval)
7a6331
 {
7a6331
-#if defined(__GNUC__) && defined(_GLIBCXX_ATOMIC_BUILTINS)
7a6331
+#if defined(__GNUC__) && (defined(_GLIBCXX_ATOMIC_BUILTINS) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 401))
7a6331
     return __sync_bool_compare_and_swap (at, compareval, newval);
7a6331
 #elif USE_TBB
7a6331
     atomic<int> *a = (atomic<int> *)at;
7a6331
@@ -306,9 +316,9 @@ atomic_compare_and_exchange (volatile int *at, int compareval, int newval)
7a6331
 #elif defined(__APPLE__)
7a6331
     return OSAtomicCompareAndSwap32Barrier (compareval, newval, at);
7a6331
 #elif defined(_WIN32)
7a6331
-    return (InterlockedCompareExchange ((volatile LONG *)at, newval, compareval) == compareval);
7a6331
+    return (_InterlockedCompareExchange ((volatile LONG *)at, newval, compareval) == compareval);
7a6331
 #else
7a6331
-    error ("No atomics on this platform.")
7a6331
+#   error No atomics on this platform.
7a6331
 #endif
7a6331
 }
7a6331
 
7a6331
@@ -317,7 +327,7 @@ atomic_compare_and_exchange (volatile int *at, int compareval, int newval)
7a6331
 inline bool
7a6331
 atomic_compare_and_exchange (volatile long long *at, long long compareval, long long newval)
7a6331
 {
7a6331
-#if defined(__GNUC__) && defined(_GLIBCXX_ATOMIC_BUILTINS)
7a6331
+#if defined(__GNUC__) && (defined(_GLIBCXX_ATOMIC_BUILTINS) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 401))
7a6331
     return __sync_bool_compare_and_swap (at, compareval, newval);
7a6331
 #elif USE_TBB
7a6331
     atomic<long long> *a = (atomic<long long> *)at;
7a6331
@@ -325,9 +335,9 @@ atomic_compare_and_exchange (volatile long long *at, long long compareval, long
7a6331
 #elif defined(__APPLE__)
7a6331
     return OSAtomicCompareAndSwap64Barrier (compareval, newval, at);
7a6331
 #elif defined(_WIN32)
7a6331
-    return (InterlockedCompareExchange64 ((volatile LONGLONG *)at, newval, compareval) == compareval);
7a6331
+    return (_InterlockedCompareExchange64 ((volatile LONGLONG *)at, newval, compareval) == compareval);
7a6331
 #else
7a6331
-    error ("No atomics on this platform.")
7a6331
+#   error No atomics on this platform.
7a6331
 #endif
7a6331
 }
7a6331
 
7a6331
diff --git a/src/maketx/CMakeLists.txt b/src/maketx/CMakeLists.txt
7a6331
index c465960..5c408d8 100644
7a6331
--- a/src/maketx/CMakeLists.txt
7a6331
+++ b/src/maketx/CMakeLists.txt
7a6331
@@ -1,3 +1,6 @@
7a6331
+if (NOT USE_TBB)
7a6331
+    add_definitions ("-DUSE_TBB=0")
7a6331
+endif ()
7a6331
 set (maketx_srcs maketx.cpp)
7a6331
 add_executable (maketx ${maketx_srcs})
7a6331
 link_ilmbase (maketx)