Kea 2.5.6
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
10
11namespace isc {
12namespace test {
13
15 : thread_(), condvar_(), ready_(false), stopping_(false),
16 stopped_(false) {
17}
18
19void
21 {
22 std::lock_guard<std::mutex> lock(mutex_);
23 flag = true;
24 }
25 condvar_.notify_one();
26}
27
28void
31}
32
33void
36}
37
38void
41}
42
43void
45 std::unique_lock<std::mutex> lock(mutex_);
46 while (!flag) {
47 condvar_.wait(lock);
48 }
49}
50
51void
54}
55
56void
59}
60
61void
64}
65
66bool
68 std::lock_guard<std::mutex> lock(mutex_);
69 return (stopping_);
70}
71
72} // end of namespace isc::test
73} // end of namespace isc
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.
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
void waitStopped()
Wait for the thread to stop.
bool stopped_
Flag indicating that the thread is stopped.
Definition: threaded_test.h:81
ThreadedTest()
Constructor.
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.
Definition: threaded_test.h:78
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.