Method
release
Source from the content-addressed store, hash-verified
| 175 | |
| 176 | template <typename T> |
| 177 | T* Owned<T>::release() |
| 178 | { |
| 179 | if (data == nullptr) { |
| 180 | // The ownership of this pointer has already been lost. |
| 181 | return nullptr; |
| 182 | } |
| 183 | |
| 184 | // Atomically set the pointer 'data->t' to `nullptr`. |
| 185 | T* old = data->t.exchange(nullptr); |
| 186 | if (old == nullptr) { |
| 187 | // The ownership of this pointer has already been lost. |
| 188 | return nullptr; |
| 189 | } |
| 190 | |
| 191 | data.reset(); |
| 192 | return old; |
| 193 | } |
| 194 | |
| 195 | |
| 196 | template <typename T> |