1 /* 2 * Copyright 2017 The WebRTC Project Authors. All rights reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #ifndef API_REF_COUNTED_BASE_H_ 11 #define API_REF_COUNTED_BASE_H_ 12 13 #include "rtc_base/constructor_magic.h" 14 #include "rtc_base/ref_count.h" 15 #include "rtc_base/ref_counter.h" 16 17 namespace rtc { 18 19 class RefCountedBase { 20 public: 21 RefCountedBase() = default; 22 AddRef()23 void AddRef() const { ref_count_.IncRef(); } Release()24 RefCountReleaseStatus Release() const { 25 const auto status = ref_count_.DecRef(); 26 if (status == RefCountReleaseStatus::kDroppedLastRef) { 27 delete this; 28 } 29 return status; 30 } 31 32 protected: 33 virtual ~RefCountedBase() = default; 34 35 private: 36 mutable webrtc::webrtc_impl::RefCounter ref_count_{0}; 37 38 RTC_DISALLOW_COPY_AND_ASSIGN(RefCountedBase); 39 }; 40 41 } // namespace rtc 42 43 #endif // API_REF_COUNTED_BASE_H_ 44