Skip to content

Commit

Permalink
Merge pull request grpc#18993 from soheilhy/refcounted-branch
Browse files Browse the repository at this point in the history
Mark it unlikely for Unref() to return true.
  • Loading branch information
soheilhy authored May 8, 2019
2 parents e9672bf + 983f678 commit 26c43ed
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/core/ext/transport/chttp2/transport/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class Chttp2IncomingByteStream : public ByteStream {
// switch to std::shared_ptr<>.
void Ref() { refs_.Ref(); }
void Unref() {
if (refs_.Unref()) {
if (GPR_UNLIKELY(refs_.Unref())) {
grpc_core::Delete(this);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/lib/gprpp/orphanable.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ class InternallyRefCounted : public Orphanable {
}

void Unref() {
if (refs_.Unref()) {
if (GPR_UNLIKELY(refs_.Unref())) {
Delete(static_cast<Child*>(this));
}
}
void Unref(const DebugLocation& location, const char* reason) {
if (refs_.Unref(location, reason)) {
if (GPR_UNLIKELY(refs_.Unref(location, reason))) {
Delete(static_cast<Child*>(this));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/lib/gprpp/ref_counted.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ class RefCounted : public Impl {
// private, since it will only be used by RefCountedPtr<>, which is a
// friend of this class.
void Unref() {
if (refs_.Unref()) {
if (GPR_UNLIKELY(refs_.Unref())) {
Delete(static_cast<Child*>(this));
}
}
void Unref(const DebugLocation& location, const char* reason) {
if (refs_.Unref(location, reason)) {
if (GPR_UNLIKELY(refs_.Unref(location, reason))) {
Delete(static_cast<Child*>(this));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/lib/transport/metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ void grpc_mdelem_do_unref(grpc_mdelem gmd DEBUG_ARGS) {
case GRPC_MDELEM_STORAGE_INTERNED: {
auto* md = reinterpret_cast<InternedMetadata*> GRPC_MDELEM_DATA(gmd);
uint32_t hash = md->hash();
if (md->Unref(FWD_DEBUG_ARGS)) {
if (GPR_UNLIKELY(md->Unref(FWD_DEBUG_ARGS))) {
/* once the refcount hits zero, some other thread can come along and
free md at any time: it's unsafe from this point on to access it */
note_disposed_interned_metadata(hash);
Expand All @@ -475,7 +475,7 @@ void grpc_mdelem_do_unref(grpc_mdelem gmd DEBUG_ARGS) {
}
case GRPC_MDELEM_STORAGE_ALLOCATED: {
auto* md = reinterpret_cast<AllocatedMetadata*> GRPC_MDELEM_DATA(gmd);
if (md->Unref(FWD_DEBUG_ARGS)) {
if (GPR_UNLIKELY(md->Unref(FWD_DEBUG_ARGS))) {
grpc_core::Delete(md);
}
break;
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/transport/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ inline void grpc_stream_unref(grpc_stream_refcount* refcount,
#else
inline void grpc_stream_unref(grpc_stream_refcount* refcount) {
#endif
if (refcount->refs.Unref()) {
if (GPR_UNLIKELY(refcount->refs.Unref())) {
grpc_stream_destroy(refcount);
}
}
Expand Down

0 comments on commit 26c43ed

Please sign in to comment.