Niels Möller | 9155e49 | 2017-10-23 11:22:30 +0200 | [diff] [blame] | 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 | */ |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 10 | #ifndef API_REF_COUNTED_BASE_H_ |
| 11 | #define API_REF_COUNTED_BASE_H_ |
Niels Möller | 9155e49 | 2017-10-23 11:22:30 +0200 | [diff] [blame] | 12 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 13 | #include "rtc_base/constructor_magic.h" |
| 14 | #include "rtc_base/ref_count.h" |
| 15 | #include "rtc_base/ref_counter.h" |
Niels Möller | 9155e49 | 2017-10-23 11:22:30 +0200 | [diff] [blame] | 16 | |
| 17 | namespace rtc { |
| 18 | |
| 19 | class RefCountedBase { |
| 20 | public: |
| 21 | RefCountedBase() = default; |
| 22 | |
| 23 | void AddRef() const { ref_count_.IncRef(); } |
| 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 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 43 | #endif // API_REF_COUNTED_BASE_H_ |