summaryrefslogtreecommitdiffstats
path: root/fastos
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-12-03 14:24:41 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2019-12-04 18:15:16 +0000
commit8946dbea418f760e4f0a5cbe2eb2bcbcddd25032 (patch)
treefc254ea5dea29ddf6a395b8bcdcb8c7540d22238 /fastos
parent7700f411ea6f4a3e7c0599fae239ec84c18c0038 (diff)
FastOS_THread::Sleep -> std::chrono::sleep_for
Renamed Timer -> ScheduledExecutor. Do not include thread.h when not needed in header files.
Diffstat (limited to 'fastos')
-rw-r--r--fastos/src/tests/processtest.cpp4
-rw-r--r--fastos/src/tests/thread_bounce_test.cpp2
-rw-r--r--fastos/src/tests/thread_mutex_test.cpp4
-rw-r--r--fastos/src/tests/thread_sleep_test.cpp2
-rw-r--r--fastos/src/tests/thread_stats_test.cpp12
-rw-r--r--fastos/src/tests/thread_test_base.hpp15
-rw-r--r--fastos/src/tests/threadtest.cpp4
-rw-r--r--fastos/src/vespa/fastos/thread.h10
-rw-r--r--fastos/src/vespa/fastos/unix_process.cpp4
-rw-r--r--fastos/src/vespa/fastos/unix_thread.cpp12
-rw-r--r--fastos/src/vespa/fastos/unix_thread.h1
11 files changed, 27 insertions, 43 deletions
diff --git a/fastos/src/tests/processtest.cpp b/fastos/src/tests/processtest.cpp
index a6729dbb783..5a78eff1d36 100644
--- a/fastos/src/tests/processtest.cpp
+++ b/fastos/src/tests/processtest.cpp
@@ -3,6 +3,8 @@
#include <vespa/fastos/process.h>
#include <vespa/fastos/timestamp.h>
+using namespace std::chrono_literals;
+
class MyListener : public FastOS_ProcessRedirectListener
{
private:
@@ -119,7 +121,7 @@ public:
xproc->WriteStdin(nullptr, 0);
}
- FastOS_Thread::Sleep(1000);
+ std::this_thread::sleep_for(1s);
}
if(i == 10)
diff --git a/fastos/src/tests/thread_bounce_test.cpp b/fastos/src/tests/thread_bounce_test.cpp
index f7bb7ee1260..84506938455 100644
--- a/fastos/src/tests/thread_bounce_test.cpp
+++ b/fastos/src/tests/thread_bounce_test.cpp
@@ -43,7 +43,7 @@ class Thread_Bounce_Test : public ThreadTestBase
int left = static_cast<int>(checkTime.elapsed().ms());
while (left < 1000) {
- FastOS_Thread::Sleep(1000 - left);
+ std::this_thread::sleep_for(std::chrono::milliseconds(1000 - left));
left = static_cast<int>(checkTime.elapsed().ms());
}
diff --git a/fastos/src/tests/thread_mutex_test.cpp b/fastos/src/tests/thread_mutex_test.cpp
index d49cf37163d..6d3f8c3c5f0 100644
--- a/fastos/src/tests/thread_mutex_test.cpp
+++ b/fastos/src/tests/thread_mutex_test.cpp
@@ -132,7 +132,7 @@ class Thread_Mutex_Test : public ThreadTestBase
{
bool lockrc;
- FastOS_Thread::Sleep(1000);
+ std::this_thread::sleep_for(1s);
for(int i=0; i<5; i++)
{
@@ -145,7 +145,7 @@ class Thread_Mutex_Test : public ThreadTestBase
}
}
- FastOS_Thread::Sleep(2000);
+ std::this_thread::sleep_for(2s);
lockrc = mtx.try_lock();
Progress(lockrc, "We should get the mutex lock now (%s)",
diff --git a/fastos/src/tests/thread_sleep_test.cpp b/fastos/src/tests/thread_sleep_test.cpp
index 7fd3412b7c3..209b7d3f880 100644
--- a/fastos/src/tests/thread_sleep_test.cpp
+++ b/fastos/src/tests/thread_sleep_test.cpp
@@ -20,7 +20,7 @@ class Thread_Sleep_Test : public ThreadTestBase
Progress(rc, "Creating Thread");
Progress(true, "Sleeping 3 seconds");
- FastOS_Thread::Sleep(3000);
+ std::this_thread::sleep_for(3s);
}
Progress(true, "Closing threadpool...");
diff --git a/fastos/src/tests/thread_stats_test.cpp b/fastos/src/tests/thread_stats_test.cpp
index 3633c12bcaa..a9d304d411f 100644
--- a/fastos/src/tests/thread_stats_test.cpp
+++ b/fastos/src/tests/thread_stats_test.cpp
@@ -31,7 +31,7 @@ class Thread_Stats_Test : public ThreadTestBase
job[0].ownThread = pool.NewThread(this,
static_cast<void *>(&job[0]));
- FastOS_Thread::Sleep(1000);
+ std::this_thread::sleep_for(1s);
inactiveThreads = pool.GetNumInactiveThreads();
Progress(inactiveThreads == 0, "Inactive threads = %d", inactiveThreads);
@@ -44,7 +44,7 @@ class Thread_Stats_Test : public ThreadTestBase
job[1].ownThread = pool.NewThread(this,
static_cast<void *>(&job[1]));
- FastOS_Thread::Sleep(1000);
+ std::this_thread::sleep_for(1s);
inactiveThreads = pool.GetNumInactiveThreads();
Progress(inactiveThreads == 0, "Inactive threads = %d", inactiveThreads);
@@ -57,7 +57,7 @@ class Thread_Stats_Test : public ThreadTestBase
job[0].ownThread->SetBreakFlag();
job[1].ownThread->SetBreakFlag();
- FastOS_Thread::Sleep(3000);
+ std::this_thread::sleep_for(3s);
inactiveThreads = pool.GetNumInactiveThreads();
Progress(inactiveThreads == 2, "Inactive threads = %d", inactiveThreads);
@@ -72,7 +72,7 @@ class Thread_Stats_Test : public ThreadTestBase
job[0].code = WAIT_FOR_BREAK_FLAG;
job[0].ownThread = pool.NewThread(this, static_cast<void *>(&job[0]));
- FastOS_Thread::Sleep(1000);
+ std::this_thread::sleep_for(1s);
inactiveThreads = pool.GetNumInactiveThreads();
Progress(inactiveThreads == 1, "Inactive threads = %d", inactiveThreads);
@@ -84,7 +84,7 @@ class Thread_Stats_Test : public ThreadTestBase
job[1].code = WAIT_FOR_BREAK_FLAG;
job[1].ownThread = pool.NewThread(this, static_cast<void *>(&job[1]));
- FastOS_Thread::Sleep(1000);
+ std::this_thread::sleep_for(1s);
inactiveThreads = pool.GetNumInactiveThreads();
Progress(inactiveThreads == 0, "Inactive threads = %d", inactiveThreads);
@@ -97,7 +97,7 @@ class Thread_Stats_Test : public ThreadTestBase
job[0].ownThread->SetBreakFlag();
job[1].ownThread->SetBreakFlag();
- FastOS_Thread::Sleep(3000);
+ std::this_thread::sleep_for(3s);
inactiveThreads = pool.GetNumInactiveThreads();
Progress(inactiveThreads == 2, "Inactive threads = %d", inactiveThreads);
diff --git a/fastos/src/tests/thread_test_base.hpp b/fastos/src/tests/thread_test_base.hpp
index 7966e95b369..c4f7ed76ea7 100644
--- a/fastos/src/tests/thread_test_base.hpp
+++ b/fastos/src/tests/thread_test_base.hpp
@@ -3,6 +3,7 @@
#pragma once
#include <chrono>
+#include <thread>
static volatile int64_t number;
#define INCREASE_NUMBER_AMOUNT 10000
@@ -47,7 +48,7 @@ public:
}
}
- FastOS_Thread::Sleep(500);
+ std::this_thread::sleep_for(500ms);
if(threadsFinished)
break;
@@ -88,7 +89,7 @@ void ThreadTestBase::Run (FastOS_ThreadInterface *thread, void *arg)
Progress(true, "Thread printing message: [%s]", job->message);
job->result = strlen(job->message);
- FastOS_Thread::Sleep(3000);
+ std::this_thread::sleep_for(3s);
break;
}
@@ -109,7 +110,7 @@ void ThreadTestBase::Run (FastOS_ThreadInterface *thread, void *arg)
number = number + 2;
if(i == sleepOn)
- FastOS_Thread::Sleep(1000);
+ std::this_thread::sleep_for(1s);
}
guard = std::unique_lock<std::mutex>();
@@ -123,7 +124,7 @@ void ThreadTestBase::Run (FastOS_ThreadInterface *thread, void *arg)
{
for(;;)
{
- FastOS_Thread::Sleep(1000);
+ std::this_thread::sleep_for(1s);
if(thread->GetBreakFlag())
{
@@ -192,7 +193,7 @@ void ThreadTestBase::Run (FastOS_ThreadInterface *thread, void *arg)
case WAIT2SEC_AND_SIGNALCOND:
{
- FastOS_Thread::Sleep(2000);
+ std::this_thread::sleep_for(2s);
job->condition->notify_one();
job->result = 1;
break;
@@ -202,7 +203,7 @@ void ThreadTestBase::Run (FastOS_ThreadInterface *thread, void *arg)
{
{
std::lock_guard<std::mutex> guard(*job->mutex);
- FastOS_Thread::Sleep(2000);
+ std::this_thread::sleep_for(2s);
}
job->result = 1;
break;
@@ -210,7 +211,7 @@ void ThreadTestBase::Run (FastOS_ThreadInterface *thread, void *arg)
case WAIT_2_SEC:
{
- FastOS_Thread::Sleep(2000);
+ std::this_thread::sleep_for(2s);
job->result = 1;
break;
}
diff --git a/fastos/src/tests/threadtest.cpp b/fastos/src/tests/threadtest.cpp
index 9507bb1e5d7..0a8a0d2bf02 100644
--- a/fastos/src/tests/threadtest.cpp
+++ b/fastos/src/tests/threadtest.cpp
@@ -43,7 +43,7 @@ class ThreadTest : public ThreadTestBase
if(waitingThreads == numWait)
break;
- FastOS_Thread::Sleep(100);
+ std::this_thread::sleep_for(100ms);
}
}
@@ -336,7 +336,7 @@ class ThreadTest : public ThreadTestBase
// Threads are not guaranteed to have entered sleep yet,
// as this test only tests for result code
// Wait another second to be sure.
- FastOS_Thread::Sleep(1000);
+ std::this_thread::sleep_for(1s);
}
void SignalTest ()
diff --git a/fastos/src/vespa/fastos/thread.h b/fastos/src/vespa/fastos/thread.h
index 12866c71b2c..257acbc92d3 100644
--- a/fastos/src/vespa/fastos/thread.h
+++ b/fastos/src/vespa/fastos/thread.h
@@ -347,15 +347,7 @@ public:
/**
* Destructor.
*/
- virtual ~FastOS_ThreadInterface (){}
-
- /**
- * Sleep for x milliseconds. Attempting to sleep for <1 milliseconds
- * will result in failure.
- * @param ms Number of milliseconds to sleep.
- * @return Boolean success/failure
- */
- static bool Sleep(int ms);
+ virtual ~FastOS_ThreadInterface () {}
/**
* Instruct a thread to exit. This could be used in conjunction with
diff --git a/fastos/src/vespa/fastos/unix_process.cpp b/fastos/src/vespa/fastos/unix_process.cpp
index 86d285059b8..4d4197f5354 100644
--- a/fastos/src/vespa/fastos/unix_process.cpp
+++ b/fastos/src/vespa/fastos/unix_process.cpp
@@ -40,6 +40,8 @@ extern char **environ;
#endif
+using namespace std::chrono_literals;
+
static pid_t safe_fork ()
{
pid_t pid;
@@ -1629,7 +1631,7 @@ FastOS_UNIX_ProcessStarter::Wait(FastOS_UNIX_Process *process,
}
}
- FastOS_Thread::Sleep(100);
+ std::this_thread::sleep_for(100ms);
}
return rc;
diff --git a/fastos/src/vespa/fastos/unix_thread.cpp b/fastos/src/vespa/fastos/unix_thread.cpp
index 5218bde2630..9e48727deb3 100644
--- a/fastos/src/vespa/fastos/unix_thread.cpp
+++ b/fastos/src/vespa/fastos/unix_thread.cpp
@@ -83,18 +83,6 @@ FastOS_UNIX_Thread::~FastOS_UNIX_Thread()
}
}
-bool FastOS_UNIX_Thread::Sleep (int ms)
-{
- bool rc=false;
-
- if (ms > 0) {
- usleep(ms*1000);
- rc = true;
- }
-
- return rc;
-}
-
FastOS_ThreadId FastOS_UNIX_Thread::GetThreadId ()
{
return _handle;
diff --git a/fastos/src/vespa/fastos/unix_thread.h b/fastos/src/vespa/fastos/unix_thread.h
index c6e0b040fc7..35df3f5745f 100644
--- a/fastos/src/vespa/fastos/unix_thread.h
+++ b/fastos/src/vespa/fastos/unix_thread.h
@@ -36,7 +36,6 @@ public:
~FastOS_UNIX_Thread();
- static bool Sleep (int ms);
FastOS_ThreadId GetThreadId () override;
static bool CompareThreadIds (FastOS_ThreadId a, FastOS_ThreadId b);
static FastOS_ThreadId GetCurrentThreadId ();