OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NATIVE_CLIENT_SRC_INCLUDE_REF_COUNTED_H_ | 5 #ifndef NATIVE_CLIENT_SRC_INCLUDE_REF_COUNTED_H_ |
6 #define NATIVE_CLIENT_SRC_INCLUDE_REF_COUNTED_H_ | 6 #define NATIVE_CLIENT_SRC_INCLUDE_REF_COUNTED_H_ |
7 | 7 |
8 #include "native_client/src/shared/platform/nacl_sync_checked.h" | 8 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
9 | 9 |
10 namespace nacl { | 10 namespace nacl { |
11 | 11 |
12 namespace subtle { | 12 namespace subtle { |
13 | 13 |
14 class RefCountedBase { | 14 class RefCountedBase { |
15 public: | 15 public: |
16 static bool ImplementsThreadSafeReferenceCounting() { return true; } | |
17 | |
18 bool HasOneRef() const { | 16 bool HasOneRef() const { |
19 nacl::ScopedNaClMutexLock ml(&mu_); | 17 nacl::ScopedNaClMutexLock ml(&mu_); |
20 return (ref_count_ == 1); | 18 return (ref_count_ == 1); |
21 } | 19 } |
22 | 20 |
23 protected: | 21 protected: |
24 RefCountedBase() : ref_count_(0) { | 22 RefCountedBase() : ref_count_(0) { |
25 NaClXMutexCtor(&mu_); | 23 NaClXMutexCtor(&mu_); |
26 } | 24 } |
27 ~RefCountedBase() { | 25 ~RefCountedBase() { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 }; | 224 }; |
227 | 225 |
228 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without | 226 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without |
229 // having to retype all the template arguments | 227 // having to retype all the template arguments |
230 template <typename T> | 228 template <typename T> |
231 scoped_refptr<T> make_scoped_refptr(T* t) { | 229 scoped_refptr<T> make_scoped_refptr(T* t) { |
232 return scoped_refptr<T>(t); | 230 return scoped_refptr<T>(t); |
233 } | 231 } |
234 | 232 |
235 #endif // NATIVE_CLIENT_SRC_INCLUDE_REF_COUNTED_H_ | 233 #endif // NATIVE_CLIENT_SRC_INCLUDE_REF_COUNTED_H_ |
OLD | NEW |