forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
guarddog_test_interlock.h
39 lines (31 loc) · 966 Bytes
/
guarddog_test_interlock.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
#include "envoy/thread/thread.h"
#include "source/server/guarddog_impl.h"
#pragma once
namespace Envoy {
namespace Server {
// Helps make tests using the GuardDog more robust by providing a way of
// blocking in the test on GuardDog loop completion when
// GuardDogImpl::forceCheckForTest() is called. If this interlock is not
// provided, the default interlock is a no-op.
class GuardDogTestInterlock : public GuardDogImpl::TestInterlockHook {
public:
// GuardDogImpl::TestInterlockHook
void signalFromImpl() override {
waiting_for_signal_ = false;
impl_.notifyAll();
}
void waitFromTest(Thread::MutexBasicLockable& mutex) override
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex) {
ASSERT(!waiting_for_signal_);
waiting_for_signal_ = true;
while (waiting_for_signal_) {
impl_.wait(mutex);
}
}
private:
Thread::CondVar impl_;
bool waiting_for_signal_ = false;
};
} // namespace Server
} // namespace Envoy