aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar ncteisen <ncteisen@gmail.com>2018-05-17 09:55:24 -0700
committerGravatar ncteisen <ncteisen@gmail.com>2018-05-17 15:07:54 -0700
commit3a3bbaf11cfcaa39351cbdadcd2f0d5a47e951a5 (patch)
tree67cff99ae89405da2b8a7cdfedd47b7b9b606450 /src
parent7243c5f1f6bc4e384800900e4fda295a5c24c0ff (diff)
reviewer feedback
Diffstat (limited to 'src')
-rw-r--r--src/core/lib/channel/channel_trace.cc4
-rw-r--r--src/core/lib/channel/channelz_registry.cc2
-rw-r--r--src/core/lib/channel/channelz_registry.h41
3 files changed, 30 insertions, 17 deletions
diff --git a/src/core/lib/channel/channel_trace.cc b/src/core/lib/channel/channel_trace.cc
index 8b459c10c5..eb7214b355 100644
--- a/src/core/lib/channel/channel_trace.cc
+++ b/src/core/lib/channel/channel_trace.cc
@@ -70,7 +70,7 @@ ChannelTrace::ChannelTrace(size_t max_events)
tail_trace_(nullptr) {
if (max_list_size_ == 0) return; // tracing is disabled if max_events == 0
gpr_mu_init(&tracer_mu_);
- channel_uuid_ = ChannelzRegistry::Default()->Register(this);
+ channel_uuid_ = ChannelzRegistry::Register(this);
time_created_ = grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(),
GPR_CLOCK_REALTIME);
}
@@ -83,7 +83,7 @@ ChannelTrace::~ChannelTrace() {
it = it->next();
Delete<TraceEvent>(to_free);
}
- ChannelzRegistry::Default()->Unregister(channel_uuid_);
+ ChannelzRegistry::Unregister(channel_uuid_);
gpr_mu_destroy(&tracer_mu_);
}
diff --git a/src/core/lib/channel/channelz_registry.cc b/src/core/lib/channel/channelz_registry.cc
index c02322924e..31d66e847a 100644
--- a/src/core/lib/channel/channelz_registry.cc
+++ b/src/core/lib/channel/channelz_registry.cc
@@ -68,7 +68,7 @@ ChannelzRegistry::~ChannelzRegistry() {
gpr_mu_destroy(&mu_);
}
-void ChannelzRegistry::Unregister(intptr_t uuid) {
+void ChannelzRegistry::InternalUnregister(intptr_t uuid) {
gpr_mu_lock(&mu_);
avl_ = grpc_avl_remove(avl_, (void*)uuid, nullptr);
gpr_mu_unlock(&mu_);
diff --git a/src/core/lib/channel/channelz_registry.h b/src/core/lib/channel/channelz_registry.h
index e23c373a19..4de7d478c5 100644
--- a/src/core/lib/channel/channelz_registry.h
+++ b/src/core/lib/channel/channelz_registry.h
@@ -32,22 +32,41 @@ namespace grpc_core {
// channelz bookkeeping. All objects share globally distributed uuids.
class ChannelzRegistry {
public:
- // These functions ensure singleton like behavior. We cannot use the normal
- // pattern of a get functions with a static function variable due to build
- // complications.
-
// To be called in grpc_init()
static void Init();
// To be callen in grpc_shutdown();
static void Shutdown();
+ // globally registers a channelz Object. Returns its unique uuid
+ template <typename Object>
+ static intptr_t Register(Object* object) {
+ return Default()->InternalRegister(object);
+ }
+
+ // globally unregisters the object that is associated to uuid.
+ static void Unregister(intptr_t uuid) { Default()->InternalUnregister(uuid); }
+
+ // if object with uuid has previously been registered, returns the
+ // Object associated with that uuid. Else returns nullptr.
+ template <typename Object>
+ static Object* Get(intptr_t uuid) {
+ return Default()->InternalGet<Object>(uuid);
+ }
+
+ private:
+ GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW
+ GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
+
+ ChannelzRegistry();
+ ~ChannelzRegistry();
+
// Returned the singleton instance of ChannelzRegistry;
static ChannelzRegistry* Default();
// globally registers a channelz Object. Returns its unique uuid
template <typename Object>
- intptr_t Register(Object* object) {
+ intptr_t InternalRegister(Object* object) {
intptr_t prior = gpr_atm_no_barrier_fetch_add(&uuid_, 1);
gpr_mu_lock(&mu_);
avl_ = grpc_avl_add(avl_, (void*)prior, object, nullptr);
@@ -56,12 +75,12 @@ class ChannelzRegistry {
}
// globally unregisters the object that is associated to uuid.
- void Unregister(intptr_t uuid);
+ void InternalUnregister(intptr_t uuid);
// if object with uuid has previously been registered, returns the
// Object associated with that uuid. Else returns nullptr.
template <typename Object>
- Object* Get(intptr_t uuid) {
+ Object* InternalGet(intptr_t uuid) {
gpr_mu_lock(&mu_);
Object* ret =
static_cast<Object*>(grpc_avl_get(avl_, (void*)uuid, nullptr));
@@ -69,16 +88,10 @@ class ChannelzRegistry {
return ret;
}
- private:
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
-
+ // private members
gpr_mu mu_;
grpc_avl avl_;
gpr_atm uuid_;
-
- ChannelzRegistry();
- ~ChannelzRegistry();
};
} // namespace grpc_core