| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // }; | 36 // }; |
| 37 // MyImplementation* CreateMyImplementation() { | 37 // MyImplementation* CreateMyImplementation() { |
| 38 // RefCountImpl<MyImplementation>* implementation = | 38 // RefCountImpl<MyImplementation>* implementation = |
| 39 // new RefCountImpl<MyImplementation>(); | 39 // new RefCountImpl<MyImplementation>(); |
| 40 // return implementation; | 40 // return implementation; |
| 41 // } | 41 // } |
| 42 | 42 |
| 43 template <class T> | 43 template <class T> |
| 44 class RefCountImpl : public T { | 44 class RefCountImpl : public T { |
| 45 public: | 45 public: |
| 46 RefCountImpl() : ref_count_(0) {} | 46 RefCountImpl() : ref_count_(1) {} |
| 47 | 47 |
| 48 template<typename P> | 48 template<typename P> |
| 49 explicit RefCountImpl(P p) : T(p), ref_count_(0) {} | 49 explicit RefCountImpl(P p) : T(p), ref_count_(1) {} |
| 50 | 50 |
| 51 template<typename P1, typename P2> | 51 template<typename P1, typename P2> |
| 52 RefCountImpl(P1 p1, P2 p2) : T(p1, p2), ref_count_(0) {} | 52 RefCountImpl(P1 p1, P2 p2) : T(p1, p2), ref_count_(1) {} |
| 53 | 53 |
| 54 template<typename P1, typename P2, typename P3> | 54 template<typename P1, typename P2, typename P3> |
| 55 RefCountImpl(P1 p1, P2 p2, P3 p3) : T(p1, p2, p3), ref_count_(0) {} | 55 RefCountImpl(P1 p1, P2 p2, P3 p3) : T(p1, p2, p3), ref_count_(1) {} |
| 56 | 56 |
| 57 template<typename P1, typename P2, typename P3, typename P4> | 57 template<typename P1, typename P2, typename P3, typename P4> |
| 58 RefCountImpl(P1 p1, P2 p2, P3 p3, P4 p4) : T(p1, p2, p3, p4), ref_count_(0) {} | 58 RefCountImpl(P1 p1, P2 p2, P3 p3, P4 p4) : T(p1, p2, p3, p4), ref_count_(1) {} |
| 59 | 59 |
| 60 template<typename P1, typename P2, typename P3, typename P4, typename P5> | 60 template<typename P1, typename P2, typename P3, typename P4, typename P5> |
| 61 RefCountImpl(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) | 61 RefCountImpl(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) |
| 62 : T(p1, p2, p3, p4, p5), ref_count_(0) {} | 62 : T(p1, p2, p3, p4, p5), ref_count_(1) {} |
| 63 | 63 |
| 64 int32_t AddRef() const override { | 64 int32_t AddRef() const override { |
| 65 return ++ref_count_; | 65 return ++ref_count_; |
| 66 } | 66 } |
| 67 | 67 |
| 68 int32_t Release() const override { | 68 int32_t Release() const override { |
| 69 int32_t ref_count; | 69 int32_t ref_count; |
| 70 ref_count = --ref_count_; | 70 ref_count = --ref_count_; |
| 71 if (ref_count == 0) | 71 if (ref_count == 0) |
| 72 delete this; | 72 delete this; |
| 73 return ref_count; | 73 return ref_count; |
| 74 } | 74 } |
| 75 | 75 |
| 76 protected: | 76 protected: |
| 77 mutable Atomic32 ref_count_; | 77 mutable Atomic32 ref_count_; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 } // namespace webrtc | 80 } // namespace webrtc |
| 81 | 81 |
| 82 #endif // SYSTEM_WRAPPERS_INCLUDE_REF_COUNT_H_ | 82 #endif // SYSTEM_WRAPPERS_INCLUDE_REF_COUNT_H_ |
| OLD | NEW |