Skip to content

Commit

Permalink
Backed out changeset f4521f4c0fc3 (bug 1372405)
Browse files Browse the repository at this point in the history
--HG--
extra : rebase_source : 1762fbc22a4cb72330b6867fb34cb032e97985ce
  • Loading branch information
BavarianTomcat committed Jun 21, 2017
1 parent 47c47f4 commit 8e9d47a
Showing 1 changed file with 177 additions and 49 deletions.
226 changes: 177 additions & 49 deletions xpcom/threads/nsThreadUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,16 +519,12 @@ using RunnableFunctionImpl =

template <typename T>
inline already_AddRefed<T>
SetRunnableName(const char* aName, T* aObj)
SetRunnableName(already_AddRefed<T>&& aObj, const char* aName)
{
#ifdef RELEASE_OR_BETA
return do_AddRef(aObj);
#else
MOZ_RELEASE_ASSERT(aName);
RefPtr<T> ref(aObj);
ref->SetName(aName);
return ref.forget();
#endif
}

} // namespace detail
Expand Down Expand Up @@ -621,14 +617,20 @@ ToSupports(mozilla::Runnable *p)

template<typename Function>
already_AddRefed<mozilla::Runnable>
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<Function>
(mozilla::Forward<Function>(aFunction)));
}

template<typename Function>
already_AddRefed<mozilla::Runnable>
NS_NewRunnableFunction(const char* aName, Function&& aFunction)
{
return mozilla::detail::SetRunnableName(
aName,
new mozilla::detail::RunnableFunctionImpl<Function>(
mozilla::Forward<Function>(aFunction)));
NS_NewRunnableFunctionXXX(mozilla::Forward<Function>(aFunction)), aName);
}

namespace mozilla {
Expand Down Expand Up @@ -1381,34 +1383,62 @@ using NonOwningIdleRunnableMethodWithTimerImpl = RunnableMethodImpl<
// these in older code. The `const char*` overload is preferred and
// should be used in new code exclusively.

template<typename PtrType, typename Method>
already_AddRefed<detail::OwningRunnableMethod<PtrType, Method>>
NewRunnableMethodXXX(PtrType&& aPtr, Method aMethod)
{
return do_AddRef(
new detail::OwningRunnableMethodImpl<PtrType, Method>
(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(
aName,
new detail::OwningRunnableMethodImpl<PtrType, Method>(
Forward<PtrType>(aPtr), aMethod));
NewRunnableMethodXXX(Forward<PtrType>(aPtr), aMethod), aName);
}

template<typename PtrType, typename Method>
already_AddRefed<detail::CancelableRunnableMethod<PtrType, Method>>
NewCancelableRunnableMethodXXX(PtrType&& aPtr, Method aMethod)
{
return do_AddRef(
new detail::CancelableRunnableMethodImpl<PtrType, Method>
(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(
aName,
new detail::CancelableRunnableMethodImpl<PtrType, Method>(
Forward<PtrType>(aPtr), aMethod));
NewCancelableRunnableMethodXXX(Forward<PtrType>(aPtr), aMethod), aName);
}

template<typename PtrType, typename Method>
already_AddRefed<detail::IdleRunnableMethod<PtrType, Method>>
NewIdleRunnableMethodXXX(PtrType&& aPtr, Method aMethod)
{
return do_AddRef(new detail::IdleRunnableMethodImpl<PtrType, Method>(
Forward<PtrType>(aPtr), aMethod));
}

template<typename PtrType, typename Method>
already_AddRefed<detail::IdleRunnableMethod<PtrType, Method>>
NewIdleRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod)
{
return detail::SetRunnableName(
aName,
new detail::IdleRunnableMethodImpl<PtrType, Method>(
Forward<PtrType>(aPtr), aMethod));
NewIdleRunnableMethodXXX(Forward<PtrType>(aPtr), aMethod), aName);
}

template<typename PtrType, typename Method>
already_AddRefed<detail::IdleRunnableMethodWithTimer<PtrType, Method>>
NewIdleRunnableMethodWithTimerXXX(PtrType&& aPtr, Method aMethod)
{
return do_AddRef(new detail::IdleRunnableMethodWithTimerImpl<PtrType, Method>(
Forward<PtrType>(aPtr), aMethod));
}

template<typename PtrType, typename Method>
Expand All @@ -1418,19 +1448,34 @@ NewIdleRunnableMethodWithTimer(const char* aName,
Method aMethod)
{
return detail::SetRunnableName(
aName,
new detail::IdleRunnableMethodWithTimerImpl<PtrType, Method>(
Forward<PtrType>(aPtr), aMethod));
NewIdleRunnableMethodWithTimerXXX(Forward<PtrType>(aPtr), aMethod),
aName);
}

template<typename PtrType, typename Method>
already_AddRefed<detail::NonOwningRunnableMethod<PtrType, Method>>
NewNonOwningRunnableMethodXXX(PtrType&& aPtr, Method aMethod)
{
return do_AddRef(
new detail::NonOwningRunnableMethodImpl<PtrType, Method>
(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(
aName,
new detail::NonOwningRunnableMethodImpl<PtrType, Method>(
Forward<PtrType>(aPtr), aMethod));
NewNonOwningRunnableMethodXXX(Forward<PtrType>(aPtr), aMethod), aName);
}

template<typename PtrType, typename Method>
already_AddRefed<detail::NonOwningCancelableRunnableMethod<PtrType, Method>>
NewNonOwningCancelableRunnableMethodXXX(PtrType&& aPtr, Method aMethod)
{
return do_AddRef(
new detail::NonOwningCancelableRunnableMethodImpl<PtrType, Method>
(Forward<PtrType>(aPtr), aMethod));
}

template<typename PtrType, typename Method>
Expand All @@ -1439,8 +1484,15 @@ NewNonOwningCancelableRunnableMethod(const char* aName, PtrType&& aPtr,
Method aMethod)
{
return detail::SetRunnableName(
aName,
new detail::NonOwningCancelableRunnableMethodImpl<PtrType, Method>(
NewNonOwningCancelableRunnableMethodXXX(Forward<PtrType>(aPtr), aMethod), aName);
}

template<typename PtrType, typename Method>
already_AddRefed<detail::NonOwningIdleRunnableMethod<PtrType, Method>>
NewNonOwningIdleRunnableMethodXXX(PtrType&& aPtr, Method aMethod)
{
return do_AddRef(
new detail::NonOwningIdleRunnableMethodImpl<PtrType, Method>(
Forward<PtrType>(aPtr), aMethod));
}

Expand All @@ -1451,9 +1503,17 @@ NewNonOwningIdleRunnableMethod(const char* aName,
Method aMethod)
{
return detail::SetRunnableName(
aName,
new detail::NonOwningIdleRunnableMethodImpl<PtrType, Method>(
Forward<PtrType>(aPtr), aMethod));
NewNonOwningIdleRunnableMethodXXX(Forward<PtrType>(aPtr), aMethod), aName);
}

template<typename PtrType, typename Method>
already_AddRefed<detail::NonOwningIdleRunnableMethodWithTimer<PtrType, Method>>
NewNonOwningIdleRunnableMethodWithTimerXXX(PtrType&& aPtr,
Method aMethod)
{
return do_AddRef(
new detail::NonOwningIdleRunnableMethodWithTimerImpl<PtrType, Method>(
Forward<PtrType>(aPtr), aMethod));
}

template<typename PtrType, typename Method>
Expand All @@ -1462,26 +1522,46 @@ NewNonOwningIdleRunnableMethodWithTimer(const char* aName,
PtrType&& aPtr,
Method aMethod)
{
return detail::SetRunnableName(
aName,
new detail::NonOwningIdleRunnableMethodWithTimerImpl<PtrType, Method>(
Forward<PtrType>(aPtr), aMethod));
return detail::SetRunnableName(NewNonOwningIdleRunnableMethodWithTimerXXX(
Forward<PtrType>(aPtr), aMethod),
aName);
}

// Similar to NewRunnableMethod. Call like so:
// nsCOMPtr<nsIRunnable> event =
// NewRunnableMethod<Types,...>(myObject, &MyClass::HandleEvent, myArg1,...);
// 'Types' are the stored type for each argument, see ParameterStorage for details.
template<typename... Storages, typename PtrType, typename Method, typename... Args>
already_AddRefed<detail::OwningRunnableMethod<PtrType, Method>>
NewRunnableMethodXXX(PtrType&& aPtr, Method aMethod, Args&&... aArgs)
{
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return do_AddRef(
new detail::OwningRunnableMethodImpl<PtrType, Method, Storages...>
(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(
aName,
new detail::OwningRunnableMethodImpl<PtrType, Method, Storages...>(
Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...));
NewRunnableMethodXXX<Storages...>
(Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...), aName);
}

template<typename... Storages, typename PtrType, typename Method, typename... Args>
already_AddRefed<detail::NonOwningRunnableMethod<PtrType, Method>>
NewNonOwningRunnableMethodXXX(PtrType&& aPtr, Method aMethod, Args&&... aArgs)
{
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return do_AddRef(
new detail::NonOwningRunnableMethodImpl<PtrType, Method, Storages...>
(Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...));
}

template<typename... Storages, typename PtrType, typename Method, typename... Args>
Expand All @@ -1492,9 +1572,19 @@ NewNonOwningRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod,
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return detail::SetRunnableName(
aName,
new detail::NonOwningRunnableMethodImpl<PtrType, Method, Storages...>(
Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...));
NewNonOwningRunnableMethodXXX<Storages...>
(Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...), aName);
}

template<typename... Storages, typename PtrType, typename Method, typename... Args>
already_AddRefed<detail::CancelableRunnableMethod<PtrType, Method>>
NewCancelableRunnableMethodXXX(PtrType&& aPtr, Method aMethod, Args&&... aArgs)
{
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return do_AddRef(
new detail::CancelableRunnableMethodImpl<PtrType, Method, Storages...>
(Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...));
}

template<typename... Storages, typename PtrType, typename Method, typename... Args>
Expand All @@ -1505,9 +1595,20 @@ NewCancelableRunnableMethod(const char* aName, PtrType&& aPtr, Method aMethod,
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return detail::SetRunnableName(
aName,
new detail::CancelableRunnableMethodImpl<PtrType, Method, Storages...>(
Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...));
NewCancelableRunnableMethodXXX<Storages...>
(Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...), aName);
}

template<typename... Storages, typename PtrType, typename Method, typename... Args>
already_AddRefed<detail::NonOwningCancelableRunnableMethod<PtrType, Method>>
NewNonOwningCancelableRunnableMethodXXX(PtrType&& aPtr, Method aMethod,
Args&&... aArgs)
{
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return do_AddRef(
new detail::NonOwningCancelableRunnableMethodImpl<PtrType, Method, Storages...>
(Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...));
}

template<typename... Storages, typename PtrType, typename Method, typename... Args>
Expand All @@ -1518,8 +1619,21 @@ NewNonOwningCancelableRunnableMethod(const char* aName, PtrType&& aPtr,
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return detail::SetRunnableName(
aName,
new detail::NonOwningCancelableRunnableMethodImpl<PtrType, Method, Storages...>(
NewNonOwningCancelableRunnableMethodXXX<Storages...>
(Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...), aName);
}

template<typename... Storages,
typename PtrType,
typename Method,
typename... Args>
already_AddRefed<detail::IdleRunnableMethod<PtrType, Method>>
NewIdleRunnableMethodXXX(PtrType&& aPtr, Method aMethod, Args&&... aArgs)
{
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return do_AddRef(
new detail::IdleRunnableMethodImpl<PtrType, Method, Storages...>(
Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...));
}

Expand All @@ -1536,8 +1650,22 @@ NewIdleRunnableMethod(const char* aName,
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return detail::SetRunnableName(
aName,
new detail::IdleRunnableMethodImpl<PtrType, Method, Storages...>(
NewIdleRunnableMethodXXX<Storages...>(
Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...),
aName);
}

template<typename... Storages,
typename PtrType,
typename Method,
typename... Args>
already_AddRefed<detail::NonOwningIdleRunnableMethod<PtrType, Method>>
NewNonOwningIdleRunnableMethodXXX(PtrType&& aPtr, Method aMethod, Args&&... aArgs)
{
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return do_AddRef(
new detail::NonOwningIdleRunnableMethodImpl<PtrType, Method, Storages...>(
Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...));
}

Expand All @@ -1554,9 +1682,9 @@ NewNonOwningIdleRunnableMethod(const char* aName,
static_assert(sizeof...(Storages) == sizeof...(Args),
"<Storages...> size should be equal to number of arguments");
return detail::SetRunnableName(
aName,
new detail::NonOwningIdleRunnableMethodImpl<PtrType, Method, Storages...>(
Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...));
NewNonOwningIdleRunnableMethodXXX<Storages...>(
Forward<PtrType>(aPtr), aMethod, mozilla::Forward<Args>(aArgs)...),
aName);
}

} // namespace mozilla
Expand Down

0 comments on commit 8e9d47a

Please sign in to comment.