summaryrefslogtreecommitdiffstats
path: root/src/lib/testutils/threaded_test.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 11:36:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 11:36:04 +0000
commit040eee1aa49b49df4698d83a05af57c220127fd1 (patch)
treef635435954e6ccde5eee9893889e24f30ca68346 /src/lib/testutils/threaded_test.cc
parentInitial commit. (diff)
downloadisc-kea-040eee1aa49b49df4698d83a05af57c220127fd1.tar.xz
isc-kea-040eee1aa49b49df4698d83a05af57c220127fd1.zip
Adding upstream version 2.2.0.upstream/2.2.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/testutils/threaded_test.cc')
-rw-r--r--src/lib/testutils/threaded_test.cc73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/lib/testutils/threaded_test.cc b/src/lib/testutils/threaded_test.cc
new file mode 100644
index 0000000..88cb846
--- /dev/null
+++ b/src/lib/testutils/threaded_test.cc
@@ -0,0 +1,73 @@
+// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <testutils/threaded_test.h>
+
+namespace isc {
+namespace test {
+
+ThreadedTest::ThreadedTest()
+ : thread_(), condvar_(), ready_(false), stopping_(false),
+ stopped_(false) {
+}
+
+void
+ThreadedTest::doSignal(bool& flag) {
+ {
+ std::lock_guard<std::mutex> lock(mutex_);
+ flag = true;
+ }
+ condvar_.notify_one();
+}
+
+void
+ThreadedTest::signalReady() {
+ doSignal(ready_);
+}
+
+void
+ThreadedTest::signalStopping() {
+ doSignal(stopping_);
+}
+
+void
+ThreadedTest::signalStopped() {
+ doSignal(stopped_);
+}
+
+void
+ThreadedTest::doWait(bool& flag) {
+ std::unique_lock<std::mutex> lock(mutex_);
+ while (!flag) {
+ condvar_.wait(lock);
+ }
+}
+
+void
+ThreadedTest::waitReady() {
+ doWait(ready_);
+}
+
+void
+ThreadedTest::waitStopping() {
+ doWait(stopping_);
+}
+
+void
+ThreadedTest::waitStopped() {
+ doWait(stopped_);
+}
+
+bool
+ThreadedTest::isStopping() {
+ std::lock_guard<std::mutex> lock(mutex_);
+ return (stopping_);
+}
+
+} // end of namespace isc::test
+} // end of namespace isc