OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ | 5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ |
6 #define MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ | 6 #define MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ |
7 | 7 |
8 #include <assert.h> | 8 #include <assert.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 ~ScopedHandleBase() { CloseIfNecessary(); } | 100 ~ScopedHandleBase() { CloseIfNecessary(); } |
101 | 101 |
102 template <class CompatibleHandleType> | 102 template <class CompatibleHandleType> |
103 explicit ScopedHandleBase(ScopedHandleBase<CompatibleHandleType> other) | 103 explicit ScopedHandleBase(ScopedHandleBase<CompatibleHandleType> other) |
104 : handle_(other.release()) { | 104 : handle_(other.release()) { |
105 } | 105 } |
106 | 106 |
107 // Move-only constructor and operator=. | 107 // Move-only constructor and operator=. |
108 ScopedHandleBase(RValue other) : handle_(other.object->release()) {} | 108 ScopedHandleBase(RValue other) : handle_(other.object->release()) {} |
109 ScopedHandleBase& operator=(RValue other) { | 109 ScopedHandleBase& operator=(RValue other) { |
110 handle_ = other.object->release(); | 110 if (other.object != this) { |
| 111 CloseIfNecessary(); |
| 112 handle_ = other.object->release(); |
| 113 } |
111 return *this; | 114 return *this; |
112 } | 115 } |
113 | 116 |
114 const HandleType& get() const { return handle_; } | 117 const HandleType& get() const { return handle_; } |
115 | 118 |
116 template <typename PassedHandleType> | 119 template <typename PassedHandleType> |
117 static ScopedHandleBase<HandleType> From( | 120 static ScopedHandleBase<HandleType> From( |
118 ScopedHandleBase<PassedHandleType> other) { | 121 ScopedHandleBase<PassedHandleType> other) { |
119 MOJO_COMPILE_ASSERT( | 122 MOJO_COMPILE_ASSERT( |
120 sizeof(static_cast<PassedHandleType*>(static_cast<HandleType*>(0))), | 123 sizeof(static_cast<PassedHandleType*>(static_cast<HandleType*>(0))), |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 CreateSharedBuffer(&options, num_bytes, &handle); | 545 CreateSharedBuffer(&options, num_bytes, &handle); |
543 assert(result == MOJO_RESULT_OK); | 546 assert(result == MOJO_RESULT_OK); |
544 } | 547 } |
545 | 548 |
546 inline SharedBuffer::~SharedBuffer() { | 549 inline SharedBuffer::~SharedBuffer() { |
547 } | 550 } |
548 | 551 |
549 } // namespace mojo | 552 } // namespace mojo |
550 | 553 |
551 #endif // MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ | 554 #endif // MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ |
OLD | NEW |