Fix Windows build issues
This resolves #333.
diff --git a/include/jemalloc/internal/jemalloc_internal_decls.h b/include/jemalloc/internal/jemalloc_internal_decls.h
index 0bca63e..2b8ca5d 100644
--- a/include/jemalloc/internal/jemalloc_internal_decls.h
+++ b/include/jemalloc/internal/jemalloc_internal_decls.h
@@ -18,6 +18,7 @@
# endif
# include <pthread.h>
# include <errno.h>
+# include <sys/time.h>
#endif
#include <sys/types.h>
@@ -61,6 +62,4 @@
#endif
#include <fcntl.h>
-#include <sys/time.h>
-
#endif /* JEMALLOC_INTERNAL_H */
diff --git a/include/msvc_compat/strings.h b/include/msvc_compat/strings.h
index f01ffdd..a3ee250 100644
--- a/include/msvc_compat/strings.h
+++ b/include/msvc_compat/strings.h
@@ -21,7 +21,37 @@
return (ffsl(x));
}
+# ifdef _M_X64
+# pragma intrinsic(_BitScanForward64)
+# endif
+
+static __forceinline int ffsll(unsigned __int64 x)
+{
+ unsigned long i;
+#ifdef _M_X64
+ if (_BitScanForward64(&i, x))
+ return (i + 1);
+ return (0);
#else
+// Fallback for 32-bit build where 64-bit version not available
+// assuming little endian
+ union {
+ unsigned __int64 ll;
+ unsigned long l[2];
+ } s;
+
+ s.ll = x;
+
+ if (_BitScanForward(&i, s.l[0]))
+ return (i + 1);
+ else if(_BitScanForward(&i, s.l[1]))
+ return (i + 33);
+ return (0);
+#endif
+}
+
+#else
+# define ffsll(x) __builtin_ffsll(x)
# define ffsl(x) __builtin_ffsl(x)
# define ffs(x) __builtin_ffs(x)
#endif
diff --git a/test/include/test/jemalloc_test.h.in b/test/include/test/jemalloc_test.h.in
index 4aaaf95..0a3dbea 100644
--- a/test/include/test/jemalloc_test.h.in
+++ b/test/include/test/jemalloc_test.h.in
@@ -11,7 +11,6 @@
#ifdef _WIN32
# include "msvc_compat/strings.h"
#endif
-#include <sys/time.h>
#ifdef _WIN32
# include <windows.h>
diff --git a/test/include/test/timer.h b/test/include/test/timer.h
index 0b27e01..ace6191 100644
--- a/test/include/test/timer.h
+++ b/test/include/test/timer.h
@@ -1,8 +1,5 @@
/* Simple timer, for use in benchmark reporting. */
-#include <unistd.h>
-#include <sys/time.h>
-
typedef struct {
nstime_t t0;
nstime_t t1;