Kea 2.7.6
threaded_test.h
Go to the documentation of this file.
1// Copyright (C) 2018-2019,2021 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#ifndef THREADED_TEST_H
8#define THREADED_TEST_H
9
10#include <boost/shared_ptr.hpp>
11#include <gtest/gtest.h>
12#include <thread>
13#include <mutex>
14#include <condition_variable>
15
16namespace isc {
17namespace test {
18
24class ThreadedTest : public ::testing::Test {
25protected:
26
29
34 void doSignal(bool& flag);
35
37 void signalReady();
38
40 void signalStopping();
41
43 void signalStopped();
44
49 void doWait(bool& flag);
50
52 void waitReady();
53
55 void waitStopping();
56
58 void waitStopped();
59
63 bool isStopping();
64
66 boost::shared_ptr<std::thread> thread_;
67
69 std::mutex mutex_;
70
72 std::condition_variable condvar_;
73
75 bool ready_;
76
79
82};
83
84
85} // end of namespace isc::test
86} // end of namespace isc
87
88#endif
Base class for tests requiring threads.
void doWait(bool &flag)
Wait for a selected flag to be set.
void doSignal(bool &flag)
Sets selected flag to true and signals condition variable.
boost::shared_ptr< std::thread > thread_
Pointer to server thread.
std::condition_variable condvar_
Conditional variable for thread waits.
std::mutex mutex_
Mutex used to synchronize threads.
bool ready_
Flag indicating that the thread is ready.
void waitStopped()
Wait for the thread to stop.
bool stopped_
Flag indicating that the thread is stopped.
void waitStopping()
Wait for the thread to be stopping.
void signalStopped()
Signal that thread is stopped.
bool stopping_
Flag indicating that the thread is stopping.
bool isStopping()
Checks if the thread is stopping.
void waitReady()
Wait for the thread to be ready.
void signalStopping()
Signal that thread is stopping.
void signalReady()
Signal that thread is ready.
Defines the logger used by the top-level component of kea-lfc.