summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2015-02-10 16:12:42 +0100
committerJose <jose@zeroc.com>2015-02-10 16:12:42 +0100
commit5d20f8d730c593c75be0bd0057c74deb6672c0f3 (patch)
tree9589e9f87c94c7a597a5dfc3d6e3cd77e190882c /cpp
parentRemoved IceDiscovery from android, UDP multicast isn't supported (diff)
downloadice-5d20f8d730c593c75be0bd0057c74deb6672c0f3.tar.bz2
ice-5d20f8d730c593c75be0bd0057c74deb6672c0f3.tar.xz
ice-5d20f8d730c593c75be0bd0057c74deb6672c0f3.zip
Fixed (ICE-5975) - Improve IceUtil::ThreadControl::sleep and wait primitives to better handle negative values
Diffstat (limited to 'cpp')
-rw-r--r--cpp/src/IceUtil/Thread.cpp15
-rw-r--r--cpp/test/IceUtil/thread/Makefile1
-rw-r--r--cpp/test/IceUtil/thread/Makefile.mak1
-rw-r--r--cpp/test/IceUtil/thread/SleepTest.cpp49
-rw-r--r--cpp/test/IceUtil/thread/SleepTest.h26
-rw-r--r--cpp/test/IceUtil/thread/TestSuite.cpp2
6 files changed, 94 insertions, 0 deletions
diff --git a/cpp/src/IceUtil/Thread.cpp b/cpp/src/IceUtil/Thread.cpp
index e428d877162..89b49ec71c7 100644
--- a/cpp/src/IceUtil/Thread.cpp
+++ b/cpp/src/IceUtil/Thread.cpp
@@ -103,6 +103,11 @@ IceUtil::ThreadControl::id() const
void
IceUtil::ThreadControl::sleep(const Time& timeout)
{
+ IceUtil::Int64 msTimeout = timeout.toMilliSeconds();
+ if(msTimeout < 0 || msTimeout > 0x7FFFFFFF)
+ {
+ throw IceUtil::InvalidTimeoutException(__FILE__, __LINE__, timeout);
+ }
this_thread::sleep_for(chrono::microseconds(timeout.toMicroSeconds()));
}
@@ -330,6 +335,11 @@ IceUtil::ThreadControl::id() const
void
IceUtil::ThreadControl::sleep(const Time& timeout)
{
+ IceUtil::Int64 msTimeout = timeout.toMilliSeconds();
+ if(msTimeout < 0 || msTimeout > 0x7FFFFFFF)
+ {
+ throw IceUtil::InvalidTimeoutException(__FILE__, __LINE__, timeout);
+ }
Sleep(static_cast<long>(timeout.toMilliSeconds()));
}
@@ -590,6 +600,11 @@ IceUtil::ThreadControl::id() const
void
IceUtil::ThreadControl::sleep(const Time& timeout)
{
+ IceUtil::Int64 msTimeout = timeout.toMilliSeconds();
+ if(msTimeout < 0 || msTimeout > 0x7FFFFFFF)
+ {
+ throw IceUtil::InvalidTimeoutException(__FILE__, __LINE__, timeout);
+ }
struct timeval tv = timeout;
struct timespec ts;
ts.tv_sec = tv.tv_sec;
diff --git a/cpp/test/IceUtil/thread/Makefile b/cpp/test/IceUtil/thread/Makefile
index 8360584557f..9ed2eb27114 100644
--- a/cpp/test/IceUtil/thread/Makefile
+++ b/cpp/test/IceUtil/thread/Makefile
@@ -17,6 +17,7 @@ OBJS = TestBase.o \
CreateTest.o \
AliveTest.o \
StartTest.o \
+ SleepTest.o \
RecMutexTest.o \
MutexTest.o \
MonitorMutexTest.o \
diff --git a/cpp/test/IceUtil/thread/Makefile.mak b/cpp/test/IceUtil/thread/Makefile.mak
index 7d01e97cbb6..04f6d69799c 100644
--- a/cpp/test/IceUtil/thread/Makefile.mak
+++ b/cpp/test/IceUtil/thread/Makefile.mak
@@ -17,6 +17,7 @@ OBJS = .\TestBase.obj \
.\CreateTest.obj \
.\AliveTest.obj \
.\StartTest.obj \
+ .\SleepTest.obj \
.\RecMutexTest.obj \
.\MutexTest.obj \
.\MonitorMutexTest.obj \
diff --git a/cpp/test/IceUtil/thread/SleepTest.cpp b/cpp/test/IceUtil/thread/SleepTest.cpp
new file mode 100644
index 00000000000..1c6b57b3df7
--- /dev/null
+++ b/cpp/test/IceUtil/thread/SleepTest.cpp
@@ -0,0 +1,49 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#include <IceUtil/IceUtil.h>
+
+#include <stdio.h>
+
+#include <SleepTest.h>
+#include <TestCommon.h>
+
+using namespace std;
+using namespace IceUtil;
+
+static const string createTestName("thread sleep");
+
+SleepTest::SleepTest() :
+ TestBase(createTestName)
+{
+}
+
+void
+SleepTest::run()
+{
+ try
+ {
+ IceUtil::ThreadControl::sleep(IceUtil::Time::secondsDouble(-1));
+ test(false);
+ }
+ catch(const InvalidTimeoutException&)
+ {
+ }
+
+#ifdef _WIN32
+ try
+ {
+ IceUtil::ThreadControl::sleep(IceUtil::Time::secondsDouble(INFINITE));
+ test(false);
+ }
+ catch(const InvalidTimeoutException&)
+ {
+ }
+#endif
+}
diff --git a/cpp/test/IceUtil/thread/SleepTest.h b/cpp/test/IceUtil/thread/SleepTest.h
new file mode 100644
index 00000000000..a708da939ac
--- /dev/null
+++ b/cpp/test/IceUtil/thread/SleepTest.h
@@ -0,0 +1,26 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#ifndef SLEEP_TEST_H
+#define SLEEP_TEST_H
+
+#include <TestBase.h>
+
+class SleepTest : public TestBase
+{
+public:
+
+ SleepTest();
+
+private:
+
+ virtual void run();
+};
+
+#endif
diff --git a/cpp/test/IceUtil/thread/TestSuite.cpp b/cpp/test/IceUtil/thread/TestSuite.cpp
index c3e20b8a798..8a5f16ee09b 100644
--- a/cpp/test/IceUtil/thread/TestSuite.cpp
+++ b/cpp/test/IceUtil/thread/TestSuite.cpp
@@ -14,6 +14,7 @@
#include <CreateTest.h>
#include <AliveTest.h>
#include <StartTest.h>
+#include <SleepTest.h>
#include <MonitorMutexTest.h>
#include <MonitorRecMutexTest.h>
@@ -25,6 +26,7 @@ initializeTestSuite()
allTests.push_back(new MutexTest);
allTests.push_back(new CountDownLatchTest);
allTests.push_back(new StartTest);
+ allTests.push_back(new SleepTest);
allTests.push_back(new CreateTest);
allTests.push_back(new AliveTest);
allTests.push_back(new RecMutexTest);