Kea  1.9.9-git
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 
16 namespace isc {
17 namespace test {
18 
24 class ThreadedTest : public ::testing::Test {
25 protected:
26 
28  ThreadedTest();
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 
78  bool stopping_;
79 
81  bool stopped_;
82 };
83 
84 
85 } // end of namespace isc::test
86 } // end of namespace isc
87 
88 #endif
bool stopped_
Flag indicating that the thread is stopped.
Definition: threaded_test.h:81
void waitReady()
Wait for the thread to be ready.
void doWait(bool &flag)
Wait for a selected flag to be set.
bool stopping_
Flag indicating that the thread is stopping.
Definition: threaded_test.h:78
void waitStopping()
Wait for the thread to be stopping.
void doSignal(bool &flag)
Sets selected flag to true and signals condition variable.
ThreadedTest()
Constructor.
void waitStopped()
Wait for the thread to stop.
boost::shared_ptr< std::thread > thread_
Pointer to server thread.
Definition: threaded_test.h:66
void signalReady()
Signal that thread is ready.
std::condition_variable condvar_
Conditional variable for thread waits.
Definition: threaded_test.h:72
std::mutex mutex_
Mutex used to synchronize threads.
Definition: threaded_test.h:69
bool ready_
Flag indicating that the thread is ready.
Definition: threaded_test.h:75
Defines the logger used by the top-level component of kea-dhcp-ddns.
void signalStopped()
Signal that thread is stopped.
void signalStopping()
Signal that thread is stopping.
Base class for tests requiring threads.
Definition: threaded_test.h:24
bool isStopping()
Checks if the thread is stopping.