diff --git a/xpcom/threads/nsThreadUtils.h b/xpcom/threads/nsThreadUtils.h index 029239ae475e..63e5a5298761 100644 --- a/xpcom/threads/nsThreadUtils.h +++ b/xpcom/threads/nsThreadUtils.h @@ -477,16 +477,12 @@ using RunnableFunctionImpl = template inline already_AddRefed -SetRunnableName(const char* aName, T* aObj) +SetRunnableName(already_AddRefed&& aObj, const char* aName) { -#ifdef RELEASE_OR_BETA - return do_AddRef(aObj); -#else MOZ_RELEASE_ASSERT(aName); RefPtr ref(aObj); ref->SetName(aName); return ref.forget(); -#endif } } // namespace detail @@ -579,14 +575,20 @@ ToSupports(mozilla::Runnable *p) template already_AddRefed -NS_NewRunnableFunction(const char* aName, Function&& aFunction) +NS_NewRunnableFunctionXXX(Function&& aFunction) { // We store a non-reference in RunnableFunction, but still forward aFunction // to move if possible. + return do_AddRef(new mozilla::detail::RunnableFunctionImpl + (mozilla::Forward(aFunction))); +} + +template +already_AddRefed +NS_NewRunnableFunction(const char* aName, Function&& aFunction) +{ return mozilla::detail::SetRunnableName( - aName, - new mozilla::detail::RunnableFunctionImpl( - mozilla::Forward(aFunction))); + NS_NewRunnableFunctionXXX(mozilla::Forward(aFunction)), aName); } namespace mozilla { @@ -1339,14 +1341,30 @@ using NonOwningIdleRunnableMethodWithTimerImpl = RunnableMethodImpl< // these in older code. The `const char*` overload is preferred and // should be used in new code exclusively. +template +already_AddRefed> +NewRunnableMethodXXX(PtrType&& aPtr, Method aMethod) +{ + return do_AddRef( + new detail::OwningRunnableMethodImpl + (Forward(aPtr), aMethod)); +} + template already_AddRefed> NewRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod) { return detail::SetRunnableName( - aName, - new detail::OwningRunnableMethodImpl( - Forward(aPtr), aMethod)); + NewRunnableMethodXXX(Forward(aPtr), aMethod), aName); +} + +template +already_AddRefed> +NewCancelableRunnableMethodXXX(PtrType&& aPtr, Method aMethod) +{ + return do_AddRef( + new detail::CancelableRunnableMethodImpl + (Forward(aPtr), aMethod)); } template @@ -1354,9 +1372,15 @@ already_AddRefed> NewCancelableRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod) { return detail::SetRunnableName( - aName, - new detail::CancelableRunnableMethodImpl( - Forward(aPtr), aMethod)); + NewCancelableRunnableMethodXXX(Forward(aPtr), aMethod), aName); +} + +template +already_AddRefed> +NewIdleRunnableMethodXXX(PtrType&& aPtr, Method aMethod) +{ + return do_AddRef(new detail::IdleRunnableMethodImpl( + Forward(aPtr), aMethod)); } template @@ -1364,9 +1388,15 @@ already_AddRefed> NewIdleRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod) { return detail::SetRunnableName( - aName, - new detail::IdleRunnableMethodImpl( - Forward(aPtr), aMethod)); + NewIdleRunnableMethodXXX(Forward(aPtr), aMethod), aName); +} + +template +already_AddRefed> +NewIdleRunnableMethodWithTimerXXX(PtrType&& aPtr, Method aMethod) +{ + return do_AddRef(new detail::IdleRunnableMethodWithTimerImpl( + Forward(aPtr), aMethod)); } template @@ -1376,9 +1406,17 @@ NewIdleRunnableMethodWithTimer(const char* aName, Method aMethod) { return detail::SetRunnableName( - aName, - new detail::IdleRunnableMethodWithTimerImpl( - Forward(aPtr), aMethod)); + NewIdleRunnableMethodWithTimerXXX(Forward(aPtr), aMethod), + aName); +} + +template +already_AddRefed> +NewNonOwningRunnableMethodXXX(PtrType&& aPtr, Method aMethod) +{ + return do_AddRef( + new detail::NonOwningRunnableMethodImpl + (Forward(aPtr), aMethod)); } template @@ -1386,9 +1424,16 @@ already_AddRefed> NewNonOwningRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod) { return detail::SetRunnableName( - aName, - new detail::NonOwningRunnableMethodImpl( - Forward(aPtr), aMethod)); + NewNonOwningRunnableMethodXXX(Forward(aPtr), aMethod), aName); +} + +template +already_AddRefed> +NewNonOwningCancelableRunnableMethodXXX(PtrType&& aPtr, Method aMethod) +{ + return do_AddRef( + new detail::NonOwningCancelableRunnableMethodImpl + (Forward(aPtr), aMethod)); } template @@ -1397,8 +1442,15 @@ NewNonOwningCancelableRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod) { return detail::SetRunnableName( - aName, - new detail::NonOwningCancelableRunnableMethodImpl( + NewNonOwningCancelableRunnableMethodXXX(Forward(aPtr), aMethod), aName); +} + +template +already_AddRefed> +NewNonOwningIdleRunnableMethodXXX(PtrType&& aPtr, Method aMethod) +{ + return do_AddRef( + new detail::NonOwningIdleRunnableMethodImpl( Forward(aPtr), aMethod)); } @@ -1409,9 +1461,17 @@ NewNonOwningIdleRunnableMethod(const char* aName, Method aMethod) { return detail::SetRunnableName( - aName, - new detail::NonOwningIdleRunnableMethodImpl( - Forward(aPtr), aMethod)); + NewNonOwningIdleRunnableMethodXXX(Forward(aPtr), aMethod), aName); +} + +template +already_AddRefed> +NewNonOwningIdleRunnableMethodWithTimerXXX(PtrType&& aPtr, + Method aMethod) +{ + return do_AddRef( + new detail::NonOwningIdleRunnableMethodWithTimerImpl( + Forward(aPtr), aMethod)); } template @@ -1420,16 +1480,26 @@ NewNonOwningIdleRunnableMethodWithTimer(const char* aName, PtrType&& aPtr, Method aMethod) { - return detail::SetRunnableName( - aName, - new detail::NonOwningIdleRunnableMethodWithTimerImpl( - Forward(aPtr), aMethod)); + return detail::SetRunnableName(NewNonOwningIdleRunnableMethodWithTimerXXX( + Forward(aPtr), aMethod), + aName); } // Similar to NewRunnableMethod. Call like so: // nsCOMPtr event = // NewRunnableMethod(myObject, &MyClass::HandleEvent, myArg1,...); // 'Types' are the stored type for each argument, see ParameterStorage for details. +template +already_AddRefed> +NewRunnableMethodXXX(PtrType&& aPtr, Method aMethod, Args&&... aArgs) +{ + static_assert(sizeof...(Storages) == sizeof...(Args), + " size should be equal to number of arguments"); + return do_AddRef( + new detail::OwningRunnableMethodImpl + (Forward(aPtr), aMethod, mozilla::Forward(aArgs)...)); +} + template already_AddRefed> NewRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod, Args&&... aArgs) @@ -1437,9 +1507,19 @@ NewRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod, Args&&... a static_assert(sizeof...(Storages) == sizeof...(Args), " size should be equal to number of arguments"); return detail::SetRunnableName( - aName, - new detail::OwningRunnableMethodImpl( - Forward(aPtr), aMethod, mozilla::Forward(aArgs)...)); + NewRunnableMethodXXX + (Forward(aPtr), aMethod, mozilla::Forward(aArgs)...), aName); +} + +template +already_AddRefed> +NewNonOwningRunnableMethodXXX(PtrType&& aPtr, Method aMethod, Args&&... aArgs) +{ + static_assert(sizeof...(Storages) == sizeof...(Args), + " size should be equal to number of arguments"); + return do_AddRef( + new detail::NonOwningRunnableMethodImpl + (Forward(aPtr), aMethod, mozilla::Forward(aArgs)...)); } template @@ -1450,9 +1530,19 @@ NewNonOwningRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod, static_assert(sizeof...(Storages) == sizeof...(Args), " size should be equal to number of arguments"); return detail::SetRunnableName( - aName, - new detail::NonOwningRunnableMethodImpl( - Forward(aPtr), aMethod, mozilla::Forward(aArgs)...)); + NewNonOwningRunnableMethodXXX + (Forward(aPtr), aMethod, mozilla::Forward(aArgs)...), aName); +} + +template +already_AddRefed> +NewCancelableRunnableMethodXXX(PtrType&& aPtr, Method aMethod, Args&&... aArgs) +{ + static_assert(sizeof...(Storages) == sizeof...(Args), + " size should be equal to number of arguments"); + return do_AddRef( + new detail::CancelableRunnableMethodImpl + (Forward(aPtr), aMethod, mozilla::Forward(aArgs)...)); } template @@ -1463,9 +1553,20 @@ NewCancelableRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod, static_assert(sizeof...(Storages) == sizeof...(Args), " size should be equal to number of arguments"); return detail::SetRunnableName( - aName, - new detail::CancelableRunnableMethodImpl( - Forward(aPtr), aMethod, mozilla::Forward(aArgs)...)); + NewCancelableRunnableMethodXXX + (Forward(aPtr), aMethod, mozilla::Forward(aArgs)...), aName); +} + +template +already_AddRefed> +NewNonOwningCancelableRunnableMethodXXX(PtrType&& aPtr, Method aMethod, + Args&&... aArgs) +{ + static_assert(sizeof...(Storages) == sizeof...(Args), + " size should be equal to number of arguments"); + return do_AddRef( + new detail::NonOwningCancelableRunnableMethodImpl + (Forward(aPtr), aMethod, mozilla::Forward(aArgs)...)); } template @@ -1476,8 +1577,21 @@ NewNonOwningCancelableRunnableMethod(const char* aName, PtrType&& aPtr, static_assert(sizeof...(Storages) == sizeof...(Args), " size should be equal to number of arguments"); return detail::SetRunnableName( - aName, - new detail::NonOwningCancelableRunnableMethodImpl( + NewNonOwningCancelableRunnableMethodXXX + (Forward(aPtr), aMethod, mozilla::Forward(aArgs)...), aName); +} + +template +already_AddRefed> +NewIdleRunnableMethodXXX(PtrType&& aPtr, Method aMethod, Args&&... aArgs) +{ + static_assert(sizeof...(Storages) == sizeof...(Args), + " size should be equal to number of arguments"); + return do_AddRef( + new detail::IdleRunnableMethodImpl( Forward(aPtr), aMethod, mozilla::Forward(aArgs)...)); } @@ -1494,8 +1608,22 @@ NewIdleRunnableMethod(const char* aName, static_assert(sizeof...(Storages) == sizeof...(Args), " size should be equal to number of arguments"); return detail::SetRunnableName( - aName, - new detail::IdleRunnableMethodImpl( + NewIdleRunnableMethodXXX( + Forward(aPtr), aMethod, mozilla::Forward(aArgs)...), + aName); +} + +template +already_AddRefed> +NewNonOwningIdleRunnableMethodXXX(PtrType&& aPtr, Method aMethod, Args&&... aArgs) +{ + static_assert(sizeof...(Storages) == sizeof...(Args), + " size should be equal to number of arguments"); + return do_AddRef( + new detail::NonOwningIdleRunnableMethodImpl( Forward(aPtr), aMethod, mozilla::Forward(aArgs)...)); } @@ -1512,9 +1640,9 @@ NewNonOwningIdleRunnableMethod(const char* aName, static_assert(sizeof...(Storages) == sizeof...(Args), " size should be equal to number of arguments"); return detail::SetRunnableName( - aName, - new detail::NonOwningIdleRunnableMethodImpl( - Forward(aPtr), aMethod, mozilla::Forward(aArgs)...)); + NewNonOwningIdleRunnableMethodXXX( + Forward(aPtr), aMethod, mozilla::Forward(aArgs)...), + aName); } } // namespace mozilla