Kea: threaded_test.cc Source File

| Kea 3.2.0-git

threaded_test.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <testutils/threaded_test.h>
10
11namespace isc {
12namespace test {
13
14ThreadedTest::ThreadedTest()
15 : thread_(), condvar_(), ready_(false), stopping_(false),
16 stopped_(false) {
17}
18
19void
20ThreadedTest::doSignal(bool& flag) {
21 {
22 std::lock_guard<std::mutex> lock(mutex_);
23 flag = true;
24 }
25 condvar_.notify_one();
26}
27
28void
29ThreadedTest::signalReady() {
30 doSignal(ready_);
31}
32
33void
34ThreadedTest::signalStopping() {
35 doSignal(stopping_);
36}
37
38void
39ThreadedTest::signalStopped() {
40 doSignal(stopped_);
41}
42
43void
44ThreadedTest::doWait(bool& flag) {
45 std::unique_lock<std::mutex> lock(mutex_);
46 condvar_.wait(lock, [&]() { return (flag); });
47}
48
49void
50ThreadedTest::waitReady() {
51 doWait(ready_);
52}
53
54void
55ThreadedTest::waitStopping() {
56 doWait(stopping_);
57}
58
59void
60ThreadedTest::waitStopped() {
61 doWait(stopped_);
62}
63
64bool
65ThreadedTest::isStopping() {
66 std::lock_guard<std::mutex> lock(mutex_);
67 return (stopping_);
68}
69
70} // end of namespace isc::test
71} // end of namespace isc
isc::test::ThreadedTest::doWait
void doWait(bool &flag)
Wait for a selected flag to be set.
Definition threaded_test.cc:44
isc::test::ThreadedTest::doSignal
void doSignal(bool &flag)
Sets selected flag to true and signals condition variable.
Definition threaded_test.cc:20
isc::test::ThreadedTest::thread_
boost::shared_ptr< std::thread > thread_
Pointer to server thread.
Definition threaded_test.h:69
isc::test::ThreadedTest::condvar_
std::condition_variable condvar_
Conditional variable for thread waits.
Definition threaded_test.h:75
isc::test::ThreadedTest::mutex_
std::mutex mutex_
Mutex used to synchronize threads.
Definition threaded_test.h:72
isc::test::ThreadedTest::ready_
bool ready_
Flag indicating that the thread is ready.
Definition threaded_test.h:78
isc::test::ThreadedTest::waitStopped
void waitStopped()
Wait for the thread to stop.
Definition threaded_test.cc:60
isc::test::ThreadedTest::stopped_
bool stopped_
Flag indicating that the thread is stopped.
Definition threaded_test.h:84
isc::test::ThreadedTest::ThreadedTest
ThreadedTest()
Constructor.
Definition threaded_test.cc:14
isc::test::ThreadedTest::waitStopping
void waitStopping()
Wait for the thread to be stopping.
Definition threaded_test.cc:55
isc::test::ThreadedTest::signalStopped
void signalStopped()
Signal that thread is stopped.
Definition threaded_test.cc:39
isc::test::ThreadedTest::stopping_
bool stopping_
Flag indicating that the thread is stopping.
Definition threaded_test.h:81
isc::test::ThreadedTest::isStopping
bool isStopping()
Checks if the thread is stopping.
Definition threaded_test.cc:65
isc::test::ThreadedTest::waitReady
void waitReady()
Wait for the thread to be ready.
Definition threaded_test.cc:50
isc::test::ThreadedTest::signalStopping
void signalStopping()
Signal that thread is stopping.
Definition threaded_test.cc:34
isc::test::ThreadedTest::signalReady
void signalReady()
Signal that thread is ready.
Definition threaded_test.cc:29
isc::test
Definition env_var_wrapper.cc:14
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
threaded_test.h