Introduce a portable EIGEN_SLEEP macro.

This commit is contained in:
Benoit Steiner
2016-12-09 14:52:15 -08:00
parent aafa97f4d2
commit 4deafd35b7
5 changed files with 15 additions and 20 deletions

View File

@@ -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);
}