| 99 | } |
| 100 | |
| 101 | inline bool RefCounted::Unref() const { |
| 102 | DCHECK_GT(ref_.load(), 0); |
| 103 | // If ref_==1, this object is owned only by the caller. Bypass a locked op |
| 104 | // in that case. |
| 105 | if (RefCountIsOne() || ref_.fetch_sub(1) == 1) { |
| 106 | // Make DCHECK in ~RefCounted happy |
| 107 | DCHECK((ref_.store(0), true)); |
| 108 | delete this; |
| 109 | return true; |
| 110 | } else { |
| 111 | return false; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | inline bool RefCounted::RefCountIsOne() const { |
| 116 | return (ref_.load(std::memory_order_acquire) == 1); |