aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2016-12-09 14:52:15 -0800
committerGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2016-12-09 14:52:15 -0800
commit4deafd35b75cde9c9d40360a37c364594fd8161a (patch)
tree331800e21f91f2493625ce78154a7f404d77cde2
parentaafa97f4d292bfe8f20756191ca34cf147e7778d (diff)
Introduce a portable EIGEN_SLEEP macro.
-rw-r--r--unsupported/Eigen/CXX11/Tensor2
-rw-r--r--unsupported/Eigen/CXX11/src/Tensor/TensorDeviceCuda.h6
-rw-r--r--unsupported/Eigen/CXX11/src/Tensor/TensorMacros.h6
-rw-r--r--unsupported/test/cxx11_non_blocking_thread_pool.cpp4
-rw-r--r--unsupported/test/cxx11_tensor_notification.cpp17
5 files changed, 15 insertions, 20 deletions
diff --git a/unsupported/Eigen/CXX11/Tensor b/unsupported/Eigen/CXX11/Tensor
index 8b36093f0..f98eb03bd 100644
--- a/unsupported/Eigen/CXX11/Tensor
+++ b/unsupported/Eigen/CXX11/Tensor
@@ -53,8 +53,10 @@ typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
+#include <windows.h>
#else
#include <stdint.h>
+#include <unistd.h>
#endif
#if __cplusplus > 199711 || EIGEN_COMP_MSVC >= 1900
diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceCuda.h b/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceCuda.h
index ec732f17d..e6cee11ef 100644
--- a/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceCuda.h
+++ b/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceCuda.h
@@ -88,11 +88,7 @@ static void initializeDeviceProp() {
#if __cplusplus >= 201103L
std::atomic_thread_fence(std::memory_order_acquire);
#endif
-#if EIGEN_OS_WIN || EIGEN_OS_WIN64
- Sleep(1000);
-#else
- sleep(1);
-#endif
+ EIGEN_SLEEP(1000);
}
}
}
diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorMacros.h b/unsupported/Eigen/CXX11/src/Tensor/TensorMacros.h
index ee0078bbc..090e7a835 100644
--- a/unsupported/Eigen/CXX11/src/Tensor/TensorMacros.h
+++ b/unsupported/Eigen/CXX11/src/Tensor/TensorMacros.h
@@ -51,4 +51,10 @@
#endif
+#if EIGEN_OS_WIN || EIGEN_OS_WIN64
+#define EIGEN_SLEEP(n) Sleep(n)
+#else
+#define EIGEN_SLEEP(n) sleep(n*1000)
+#endif
+
#endif
diff --git a/unsupported/test/cxx11_non_blocking_thread_pool.cpp b/unsupported/test/cxx11_non_blocking_thread_pool.cpp
index 80d0ee080..2c5765ce4 100644
--- a/unsupported/test/cxx11_non_blocking_thread_pool.cpp
+++ b/unsupported/test/cxx11_non_blocking_thread_pool.cpp
@@ -10,8 +10,8 @@
#define EIGEN_USE_THREADS
#include "main.h"
-#include <unistd.h>
#include "Eigen/CXX11/ThreadPool"
+#include "Eigen/CXX11/Tensor"
static void test_create_destroy_empty_pool()
{
@@ -109,7 +109,7 @@ static void test_cancel()
// Schedule a large number of closure that each sleeps for one second. This
// will keep the thread pool busy for much longer than the default test timeout.
for (int i = 0; i < 1000; ++i) {
- tp.Schedule([]() { sleep(2); });
+ tp.Schedule([]() { EIGEN_SLEEP(2000); });
}
// Cancel the processing of all the closures that are still pending.
diff --git a/unsupported/test/cxx11_tensor_notification.cpp b/unsupported/test/cxx11_tensor_notification.cpp
index c946007b8..183ef02c1 100644
--- a/unsupported/test/cxx11_tensor_notification.cpp
+++ b/unsupported/test/cxx11_tensor_notification.cpp
@@ -13,15 +13,6 @@
#include "main.h"
#include <Eigen/CXX11/Tensor>
-#if EIGEN_OS_WIN || EIGEN_OS_WIN64
-#include <windows.h>
-void sleep(int seconds) {
- Sleep(seconds*1000);
-}
-#else
-#include <unistd.h>
-#endif
-
namespace {
@@ -40,7 +31,7 @@ static void test_notification_single()
Eigen::Notification n;
std::function<void()> func = std::bind(&WaitAndAdd, &n, &counter);
thread_pool.Schedule(func);
- sleep(1);
+ EIGEN_SLEEP(1000);
// The thread should be waiting for the notification.
VERIFY_IS_EQUAL(counter, 0);
@@ -48,7 +39,7 @@ static void test_notification_single()
// Unblock the thread
n.Notify();
- sleep(1);
+ EIGEN_SLEEP(1000);
// Verify the counter has been incremented
VERIFY_IS_EQUAL(counter, 1);
@@ -67,10 +58,10 @@ static void test_notification_multiple()
thread_pool.Schedule(func);
thread_pool.Schedule(func);
thread_pool.Schedule(func);
- sleep(1);
+ EIGEN_SLEEP(1000);
VERIFY_IS_EQUAL(counter, 0);
n.Notify();
- sleep(1);
+ EIGEN_SLEEP(1000);
VERIFY_IS_EQUAL(counter, 4);
}