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/. */ 6 7 #ifndef THREADSAFEREFCOUNTINGWITHMAINTHREADDESTRUCTION_H_ 8 #define THREADSAFEREFCOUNTINGWITHMAINTHREADDESTRUCTION_H_ 9 10 #include "nsISupportsImpl.h" 11 #include "MainThreadUtils.h" 12 #include "nsThreadUtils.h" 13 14 #define NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_MAIN_THREAD_DESTRUCTION( \ 15 _class) \ 16 private: \ 17 void DeleteOnMainThread() { \ 18 if (NS_IsMainThread()) { \ 19 delete this; \ 20 return; \ 21 } \ 22 NS_DispatchToMainThread(NewNonOwningRunnableMethod( \ 23 #_class "::DeleteOnMainThread", this, &_class::DeleteOnMainThread)); \ 24 } \ 25 \ 26 NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_DESTROY(_class, \ 27 DeleteOnMainThread()) 28 29 #endif 30