OLD | NEW |
1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 #ifndef SRC_VM_REFCOUNTED_H_ | 5 #ifndef SRC_VM_REFCOUNTED_H_ |
6 #define SRC_VM_REFCOUNTED_H_ | 6 #define SRC_VM_REFCOUNTED_H_ |
7 | 7 |
8 #include "src/shared/globals.h" | 8 #include "src/shared/globals.h" |
9 #include "src/shared/atomic.h" | 9 #include "src/shared/atomic.h" |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 ref_count_++; | 23 ref_count_++; |
24 } | 24 } |
25 | 25 |
26 static void DecrementRef(T* object) { | 26 static void DecrementRef(T* object) { |
27 ASSERT(object->ref_count_ > 0); | 27 ASSERT(object->ref_count_ > 0); |
28 if (--object->ref_count_ == 0) { | 28 if (--object->ref_count_ == 0) { |
29 delete reinterpret_cast<T*>(object); | 29 delete reinterpret_cast<T*>(object); |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 protected: | |
34 bool DecrementRefWithoutDelete() { | |
35 ASSERT(ref_count_ > 0); | |
36 return --ref_count_ == 0; | |
37 } | |
38 | |
39 private: | 33 private: |
40 Atomic<int> ref_count_; | 34 Atomic<int> ref_count_; |
41 }; | 35 }; |
42 | 36 |
43 } // namespace fletch | 37 } // namespace fletch |
44 | 38 |
45 #endif // SRC_VM_REFCOUNTED_H_ | 39 #endif // SRC_VM_REFCOUNTED_H_ |
OLD | NEW |