1
#pragma once
2

            
3
#include "source/common/common/thread.h"
4

            
5
namespace Envoy {
6
namespace Grpc {
7

            
8
// Captures global grpc initialization and shutdown. Note that grpc
9
// initialization starts several threads, so it is a little annoying to run them
10
// alongside unrelated tests, particularly if they are trying to track memory
11
// usage, or you are exploiting otherwise consistent run-to-run pointer values
12
// during debug.
13
//
14
// Instantiating this class makes it easy to ensure classes that depend on grpc
15
// libraries get them initialized.
16
class GoogleGrpcContext {
17
public:
18
  GoogleGrpcContext();
19
  ~GoogleGrpcContext();
20

            
21
private:
22
  struct InstanceTracker {
23
    Thread::MutexBasicLockable mutex_;
24
    uint64_t live_instances_ ABSL_GUARDED_BY(mutex_) = 0;
25
  };
26

            
27
  static InstanceTracker& instanceTracker();
28

            
29
  InstanceTracker& instance_tracker_;
30
};
31

            
32
} // namespace Grpc
33
} // namespace Envoy