Bug 1333997 - Part 2: Overload the NewRunnable APIs with a 'Name' as 1st Parameter. r=froydnj

--HG--
extra : rebase_source : b7aaaf3acf2edd6cfaff467db6436d5f2d1addb0
This commit is contained in:
Bevis Tseng 2017-02-07 13:02:57 +08:00
parent a9f9ffc077
commit 2128d8e3a2

View File

@ -324,6 +324,16 @@ using RunnableFunctionImpl =
// Make sure we store a non-reference in nsRunnableFunction. // Make sure we store a non-reference in nsRunnableFunction.
typename detail::RunnableFunction<typename RemoveReference<Function>::Type>; typename detail::RunnableFunction<typename RemoveReference<Function>::Type>;
template <typename T>
inline already_AddRefed<T>
SetRunnableName(already_AddRefed<T>&& aObj, const char* aName)
{
MOZ_RELEASE_ASSERT(aName);
RefPtr<T> ref(aObj);
ref->SetName(aName);
return ref.forget();
}
} // namespace detail } // namespace detail
namespace detail { namespace detail {
@ -422,6 +432,14 @@ NS_NewRunnableFunction(Function&& aFunction)
(mozilla::Forward<Function>(aFunction))); (mozilla::Forward<Function>(aFunction)));
} }
template<typename Function>
already_AddRefed<mozilla::Runnable>
NS_NewRunnableFunction(const char* aName, Function&& aFunction)
{
return mozilla::detail::SetRunnableName(
NS_NewRunnableFunction(mozilla::Forward<Function>(aFunction)), aName);
}
// An event that can be used to call a method on a class. The class type must // An event that can be used to call a method on a class. The class type must
// support reference counting. This event supports Revoke for use // support reference counting. This event supports Revoke for use
// with nsRevocableEventPtr. // with nsRevocableEventPtr.
@ -935,6 +953,14 @@ NewRunnableMethod(PtrType&& aPtr, Method aMethod)
(Forward<PtrType>(aPtr), aMethod)); (Forward<PtrType>(aPtr), aMethod));
} }
template<typename PtrType, typename Method>
already_AddRefed<detail::OwningRunnableMethod<PtrType, Method>>
NewRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod)
{
return detail::SetRunnableName(
NewRunnableMethod(Forward<PtrType>(aPtr), aMethod), aName);
}
template<typename PtrType, typename Method> template<typename PtrType, typename Method>
already_AddRefed<detail::CancelableRunnableMethod<PtrType, Method>> already_AddRefed<detail::CancelableRunnableMethod<PtrType, Method>>
NewCancelableRunnableMethod(PtrType&& aPtr, Method aMethod) NewCancelableRunnableMethod(PtrType&& aPtr, Method aMethod)
@ -944,6 +970,14 @@ NewCancelableRunnableMethod(PtrType&& aPtr, Method aMethod)
(Forward<PtrType>(aPtr), aMethod)); (Forward<PtrType>(aPtr), aMethod));
} }
template<typename PtrType, typename Method>
already_AddRefed<detail::CancelableRunnableMethod<PtrType, Method>>
NewCancelableRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod)
{
return detail::SetRunnableName(
NewCancelableRunnableMethod(Forward<PtrType>(aPtr), aMethod), aName);
}
template<typename PtrType, typename Method> template<typename PtrType, typename Method>
already_AddRefed<detail::NonOwningRunnableMethod<PtrType, Method>> already_AddRefed<detail::NonOwningRunnableMethod<PtrType, Method>>
NewNonOwningRunnableMethod(PtrType&& aPtr, Method aMethod) NewNonOwningRunnableMethod(PtrType&& aPtr, Method aMethod)
@ -953,6 +987,14 @@ NewNonOwningRunnableMethod(PtrType&& aPtr, Method aMethod)
(Forward<PtrType>(aPtr), aMethod)); (Forward<PtrType>(aPtr), aMethod));
} }
template<typename PtrType, typename Method>
already_AddRefed<detail::NonOwningRunnableMethod<PtrType, Method>>
NewNonOwningRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod)
{
return detail::SetRunnableName(
NewNonOwningRunnableMethod(Forward<PtrType>(aPtr), aMethod), aName);
}
template<typename PtrType, typename Method> template<typename PtrType, typename Method>
already_AddRefed<detail::NonOwningCancelableRunnableMethod<PtrType, Method>> already_AddRefed<detail::NonOwningCancelableRunnableMethod<PtrType, Method>>
NewNonOwningCancelableRunnableMethod(PtrType&& aPtr, Method aMethod) NewNonOwningCancelableRunnableMethod(PtrType&& aPtr, Method aMethod)
@ -962,6 +1004,15 @@ NewNonOwningCancelableRunnableMethod(PtrType&& aPtr, Method aMethod)
(Forward<PtrType>(aPtr), aMethod)); (Forward<PtrType>(aPtr), aMethod));
} }
template<typename PtrType, typename Method>
already_AddRefed<detail::NonOwningCancelableRunnableMethod<PtrType, Method>>
NewNonOwningCancelableRunnableMethod(const char* aName, PtrType&& aPtr,
Method aMethod)
{
return detail::SetRunnableName(
NewNonOwningCancelableRunnableMethod(Forward<PtrType>(aPtr), aMethod), aName);
}
// Similar to NewRunnableMethod. Call like so: // Similar to NewRunnableMethod. Call like so:
// nsCOMPtr<nsIRunnable> event = // nsCOMPtr<nsIRunnable> event =
// NewRunnableMethod<Types,...>(myObject, &MyClass::HandleEvent, myArg1,...); // NewRunnableMethod<Types,...>(myObject, &MyClass::HandleEvent, myArg1,...);
@ -977,6 +1028,17 @@ NewRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs)
(Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...)); (Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...));
} }
template<typename... Storages, typename PtrType, typename Method, typename... Args>
already_AddRefed<detail::OwningRunnableMethod<PtrType, Method>>
NewRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod, Args&&... aArgs)
{
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return detail::SetRunnableName(
NewRunnableMethod<Storages...>
(Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...), aName);
}
template<typename... Storages, typename PtrType, typename Method, typename... Args> template<typename... Storages, typename PtrType, typename Method, typename... Args>
already_AddRefed<detail::NonOwningRunnableMethod<PtrType, Method>> already_AddRefed<detail::NonOwningRunnableMethod<PtrType, Method>>
NewNonOwningRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs) NewNonOwningRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs)
@ -988,6 +1050,18 @@ NewNonOwningRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs)
(Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...)); (Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...));
} }
template<typename... Storages, typename PtrType, typename Method, typename... Args>
already_AddRefed<detail::NonOwningRunnableMethod<PtrType, Method>>
NewNonOwningRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod,
Args&&... aArgs)
{
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return detail::SetRunnableName(
NewNonOwningRunnableMethod<Storages...>
(Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...), aName);
}
template<typename... Storages, typename PtrType, typename Method, typename... Args> template<typename... Storages, typename PtrType, typename Method, typename... Args>
already_AddRefed<detail::CancelableRunnableMethod<PtrType, Method>> already_AddRefed<detail::CancelableRunnableMethod<PtrType, Method>>
NewCancelableRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs) NewCancelableRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs)
@ -999,6 +1073,18 @@ NewCancelableRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs)
(Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...)); (Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...));
} }
template<typename... Storages, typename PtrType, typename Method, typename... Args>
already_AddRefed<detail::CancelableRunnableMethod<PtrType, Method>>
NewCancelableRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod,
Args&&... aArgs)
{
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return detail::SetRunnableName(
NewCancelableRunnableMethod<Storages...>
(Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...), aName);
}
template<typename... Storages, typename PtrType, typename Method, typename... Args> template<typename... Storages, typename PtrType, typename Method, typename... Args>
already_AddRefed<detail::NonOwningCancelableRunnableMethod<PtrType, Method>> already_AddRefed<detail::NonOwningCancelableRunnableMethod<PtrType, Method>>
NewNonOwningCancelableRunnableMethod(PtrType&& aPtr, Method aMethod, NewNonOwningCancelableRunnableMethod(PtrType&& aPtr, Method aMethod,
@ -1011,6 +1097,18 @@ NewNonOwningCancelableRunnableMethod(PtrType&& aPtr, Method aMethod,
(Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...)); (Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...));
} }
template<typename... Storages, typename PtrType, typename Method, typename... Args>
already_AddRefed<detail::NonOwningCancelableRunnableMethod<PtrType, Method>>
NewNonOwningCancelableRunnableMethod(const char* aName, PtrType&& aPtr,
Method aMethod, Args&&... aArgs)
{
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return detail::SetRunnableName(
NewNonOwningCancelableRunnableMethod<Storages...>
(Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...), aName);
}
} // namespace mozilla } // namespace mozilla
#endif // XPCOM_GLUE_AVOID_NSPR #endif // XPCOM_GLUE_AVOID_NSPR