Bug 1932613 - temporarily disable browser_ml_end_to_end.js for permanent failures...
[gecko.git] / xpcom / threads / LeakRefPtr.h
blobee260dad7ee0bc4010fff0728810e7fc3002d0e6
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* Smart pointer which leaks its owning refcounted object by default. */
9 #ifndef LeakRefPtr_h
10 #define LeakRefPtr_h
12 #include "mozilla/AlreadyAddRefed.h"
14 namespace mozilla {
16 /**
17 * Instance of this class behaves like a raw pointer which leaks the
18 * resource it's owning if not explicitly released.
20 template <class T>
21 class LeakRefPtr {
22 public:
23 explicit LeakRefPtr(already_AddRefed<T>&& aPtr) : mRawPtr(aPtr.take()) {}
25 explicit operator bool() const { return !!mRawPtr; }
27 LeakRefPtr<T>& operator=(already_AddRefed<T>&& aPtr) {
28 mRawPtr = aPtr.take();
29 return *this;
32 T* get() const { return mRawPtr; }
34 already_AddRefed<T> take() {
35 T* rawPtr = mRawPtr;
36 mRawPtr = nullptr;
37 return already_AddRefed<T>(rawPtr);
40 void release() { NS_RELEASE(mRawPtr); }
42 private:
43 T* MOZ_OWNING_REF mRawPtr;
46 } // namespace mozilla
48 #endif // LeakRefPtr_h