| Index: base/scoped_ptr.h
|
| ===================================================================
|
| --- base/scoped_ptr.h (revision 3911)
|
| +++ base/scoped_ptr.h (working copy)
|
| @@ -36,6 +36,8 @@
|
| #ifndef BASE_SCOPED_PTR_H_
|
| #define BASE_SCOPED_PTR_H_
|
|
|
| +#include "base/thread_collision_warner.h"
|
| +
|
| // This is an implementation designed to match the anticipated future TR2
|
| // implementation of the scoped_ptr class, and its closely-related brethren,
|
| // scoped_array, scoped_ptr_malloc.
|
| @@ -76,6 +78,7 @@
|
| // Then takes ownership of a new object, if given.
|
| // this->reset(this->get()) works.
|
| void reset(C* p = NULL) {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_);
|
| if (p != ptr_) {
|
| enum { type_must_be_complete = sizeof(C) };
|
| delete ptr_;
|
| @@ -86,23 +89,36 @@
|
| // Accessors to get the owned object.
|
| // operator* and operator-> will assert() if there is no current object.
|
| C& operator*() const {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_);
|
| assert(ptr_ != NULL);
|
| return *ptr_;
|
| }
|
| C* operator->() const {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_);
|
| assert(ptr_ != NULL);
|
| return ptr_;
|
| }
|
| - C* get() const { return ptr_; }
|
| + C* get() const {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_);
|
| + return ptr_;
|
| + }
|
|
|
| // Comparison operators.
|
| // These return whether two scoped_ptr refer to the same object, not just to
|
| // two different but equal objects.
|
| - bool operator==(C* p) const { return ptr_ == p; }
|
| - bool operator!=(C* p) const { return ptr_ != p; }
|
| + bool operator==(C* p) const {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_);
|
| + return ptr_ == p;
|
| + }
|
| + bool operator!=(C* p) const {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_);
|
| + return ptr_ != p;
|
| + }
|
|
|
| // Swap two scoped pointers.
|
| void swap(scoped_ptr& p2) {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_);
|
| +
|
| C* tmp = ptr_;
|
| ptr_ = p2.ptr_;
|
| p2.ptr_ = tmp;
|
| @@ -114,6 +130,8 @@
|
| // After this operation, this object will hold a NULL pointer,
|
| // and will not own the object any more.
|
| C* release() {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_);
|
| +
|
| C* retVal = ptr_;
|
| ptr_ = NULL;
|
| return retVal;
|
| @@ -131,6 +149,8 @@
|
| // Disallow evil constructors
|
| scoped_ptr(const scoped_ptr&);
|
| void operator=(const scoped_ptr&);
|
| +
|
| + D_DEFINE_CRITICAL_SECTION(scoped_ptr_);
|
| };
|
|
|
| // Free functions
|
| @@ -181,6 +201,7 @@
|
| // Then takes ownership of a new object, if given.
|
| // this->reset(this->get()) works.
|
| void reset(C* p = NULL) {
|
| + D_BOOK_CRITICAL_SECTION(scoped_array_);
|
| if (p != array_) {
|
| enum { type_must_be_complete = sizeof(C) };
|
| delete[] array_;
|
| @@ -191,6 +212,7 @@
|
| // Get one element of the current object.
|
| // Will assert() if there is no current object, or index i is negative.
|
| C& operator[](std::ptrdiff_t i) const {
|
| + D_BOOK_CRITICAL_SECTION(scoped_array_);
|
| assert(i >= 0);
|
| assert(array_ != NULL);
|
| return array_[i];
|
| @@ -199,17 +221,25 @@
|
| // Get a pointer to the zeroth element of the current object.
|
| // If there is no current object, return NULL.
|
| C* get() const {
|
| + D_BOOK_CRITICAL_SECTION(scoped_array_);
|
| return array_;
|
| }
|
|
|
| // Comparison operators.
|
| // These return whether two scoped_array refer to the same object, not just to
|
| // two different but equal objects.
|
| - bool operator==(C* p) const { return array_ == p; }
|
| - bool operator!=(C* p) const { return array_ != p; }
|
| + bool operator==(C* p) const {
|
| + D_BOOK_CRITICAL_SECTION(scoped_array_);
|
| + return array_ == p;
|
| + }
|
| + bool operator!=(C* p) const {
|
| + D_BOOK_CRITICAL_SECTION(scoped_array_);
|
| + return array_ != p;
|
| + }
|
|
|
| // Swap two scoped arrays.
|
| void swap(scoped_array& p2) {
|
| + D_BOOK_CRITICAL_SECTION(scoped_array_);
|
| C* tmp = array_;
|
| array_ = p2.array_;
|
| p2.array_ = tmp;
|
| @@ -221,6 +251,7 @@
|
| // After this operation, this object will hold a NULL pointer,
|
| // and will not own the object any more.
|
| C* release() {
|
| + D_BOOK_CRITICAL_SECTION(scoped_array_);
|
| C* retVal = array_;
|
| array_ = NULL;
|
| return retVal;
|
| @@ -236,6 +267,8 @@
|
| // Disallow evil constructors
|
| scoped_array(const scoped_array&);
|
| void operator=(const scoped_array&);
|
| +
|
| + D_DEFINE_CRITICAL_SECTION(scoped_array_);
|
| };
|
|
|
| // Free functions
|
| @@ -289,6 +322,7 @@
|
| // Then takes ownership of a new object, if given.
|
| // this->reset(this->get()) works.
|
| void reset(C* p = NULL) {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_malloc_);
|
| if (ptr_ != p) {
|
| free_(ptr_);
|
| ptr_ = p;
|
| @@ -299,16 +333,19 @@
|
| // operator* and operator-> will cause an assert() failure if there is
|
| // no current object.
|
| C& operator*() const {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_malloc_);
|
| assert(ptr_ != NULL);
|
| return *ptr_;
|
| }
|
|
|
| C* operator->() const {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_malloc_);
|
| assert(ptr_ != NULL);
|
| return ptr_;
|
| }
|
|
|
| C* get() const {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_malloc_);
|
| return ptr_;
|
| }
|
|
|
| @@ -318,15 +355,18 @@
|
| // For compatibility wwith the boost-derived implementation, these
|
| // take non-const arguments.
|
| bool operator==(C* p) const {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_malloc_);
|
| return ptr_ == p;
|
| }
|
|
|
| bool operator!=(C* p) const {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_malloc_);
|
| return ptr_ != p;
|
| }
|
|
|
| // Swap two scoped pointers.
|
| void swap(scoped_ptr_malloc & b) {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_malloc_);
|
| C* tmp = b.ptr_;
|
| b.ptr_ = ptr_;
|
| ptr_ = tmp;
|
| @@ -338,6 +378,7 @@
|
| // After this operation, this object will hold a NULL pointer,
|
| // and will not own the object any more.
|
| C* release() {
|
| + D_BOOK_CRITICAL_SECTION(scoped_ptr_malloc_);
|
| C* tmp = ptr_;
|
| ptr_ = NULL;
|
| return tmp;
|
| @@ -357,6 +398,8 @@
|
| // Disallow evil constructors
|
| scoped_ptr_malloc(const scoped_ptr_malloc&);
|
| void operator=(const scoped_ptr_malloc&);
|
| +
|
| + D_DEFINE_CRITICAL_SECTION(scoped_ptr_malloc_);
|
| };
|
|
|
| template<class C, class FP>
|
|
|