blob: 8c26efd3e3bbb6e9f50b170dc017f2ca13f9176d [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 */
10#ifndef API_REFCOUNTEDBASE_H_
11#define API_REFCOUNTEDBASE_H_
12
13#include "rtc_base/constructormagic.h"
14#include "rtc_base/refcount.h"
15#include "rtc_base/refcounter.h"
16
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
43#endif // API_REFCOUNTEDBASE_H_