Chromium Code Reviews| 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 BASE_MEMORY_REF_COUNTED_H_ | 5 #ifndef BASE_MEMORY_REF_COUNTED_H_ |
| 6 #define BASE_MEMORY_REF_COUNTED_H_ | 6 #define BASE_MEMORY_REF_COUNTED_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <cassert> | 9 #include <cassert> |
| 10 #include <cstdio> | |
| 11 #include <unistd.h> | |
|
scshunt
2012/07/06 16:39:03
Note to self: remove.
| |
| 10 | 12 |
| 11 #include "base/atomic_ref_count.h" | 13 #include "base/atomic_ref_count.h" |
| 12 #include "base/base_export.h" | 14 #include "base/base_export.h" |
| 15 #include "base/logging.h" | |
| 13 #include "base/threading/thread_collision_warner.h" | 16 #include "base/threading/thread_collision_warner.h" |
| 14 | 17 |
| 15 namespace base { | 18 namespace base { |
| 16 | 19 |
| 17 namespace subtle { | 20 namespace subtle { |
| 18 | 21 |
| 19 class BASE_EXPORT RefCountedBase { | 22 class BASE_EXPORT RefCountedBase { |
| 20 public: | 23 public: |
| 21 static bool ImplementsThreadSafeReferenceCounting() { return false; } | 24 static bool ImplementsThreadSafeReferenceCounting() { return false; } |
| 22 | 25 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 } | 252 } |
| 250 | 253 |
| 251 ~scoped_refptr() { | 254 ~scoped_refptr() { |
| 252 if (ptr_) | 255 if (ptr_) |
| 253 ptr_->Release(); | 256 ptr_->Release(); |
| 254 } | 257 } |
| 255 | 258 |
| 256 T* get() const { return ptr_; } | 259 T* get() const { return ptr_; } |
| 257 operator T*() const { return ptr_; } | 260 operator T*() const { return ptr_; } |
| 258 T* operator->() const { | 261 T* operator->() const { |
| 262 DCHECK(ptr_ != NULL); | |
|
Fady Samuel
2012/07/06 15:14:44
Looks unnecessary. Revert please.
scshunt
2012/07/06 16:39:03
It was for debugging; assert() wasn't causing a st
| |
| 259 assert(ptr_ != NULL); | 263 assert(ptr_ != NULL); |
| 260 return ptr_; | 264 return ptr_; |
| 261 } | 265 } |
| 262 | 266 |
| 263 // Release a pointer. | 267 // Release a pointer. |
| 264 // The return value is the current pointer held by this object. | 268 // The return value is the current pointer held by this object. |
| 265 // If this object holds a NULL pointer, the return value is NULL. | 269 // If this object holds a NULL pointer, the return value is NULL. |
| 266 // After this operation, this object will hold a NULL pointer, | 270 // After this operation, this object will hold a NULL pointer, |
| 267 // and will not own the object any more. | 271 // and will not own the object any more. |
| 268 T* release() { | 272 T* release() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 }; | 310 }; |
| 307 | 311 |
| 308 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without | 312 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without |
| 309 // having to retype all the template arguments | 313 // having to retype all the template arguments |
| 310 template <typename T> | 314 template <typename T> |
| 311 scoped_refptr<T> make_scoped_refptr(T* t) { | 315 scoped_refptr<T> make_scoped_refptr(T* t) { |
| 312 return scoped_refptr<T>(t); | 316 return scoped_refptr<T>(t); |
| 313 } | 317 } |
| 314 | 318 |
| 315 #endif // BASE_MEMORY_REF_COUNTED_H_ | 319 #endif // BASE_MEMORY_REF_COUNTED_H_ |
| OLD | NEW |