blob: a1761db851eacd9f1ca78d61e9a6c1acfb665482 [file] [log] [blame]
Niels Möller9155e492017-10-23 11:22:30 +02001/*
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 Anton10542f22019-01-11 09:11:00 -080010#ifndef API_REF_COUNTED_BASE_H_
11#define API_REF_COUNTED_BASE_H_
Niels Möller9155e492017-10-23 11:22:30 +020012
Steve Anton10542f22019-01-11 09:11:00 -080013#include "rtc_base/constructor_magic.h"
14#include "rtc_base/ref_count.h"
15#include "rtc_base/ref_counter.h"
Niels Möller9155e492017-10-23 11:22:30 +020016
17namespace rtc {
18
19class 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 Anton10542f22019-01-11 09:11:00 -080043#endif // API_REF_COUNTED_BASE_H_