diff --git a/xpcom/glue/nsThreadUtils.h b/xpcom/glue/nsThreadUtils.h index ab8d333dceec..168ceeffc4c3 100644 --- a/xpcom/glue/nsThreadUtils.h +++ b/xpcom/glue/nsThreadUtils.h @@ -704,49 +704,52 @@ struct ParameterStorage } /* namespace detail */ +namespace mozilla { + +namespace detail { + // struct used to store arguments and later apply them to a method. template -struct nsRunnableMethodArguments +struct RunnableMethodArguments { - mozilla::Tuple::Type...> mArguments; + Tuple::Type...> mArguments; template - explicit nsRunnableMethodArguments(As&&... aArguments) - : mArguments(mozilla::Forward(aArguments)...) + explicit RunnableMethodArguments(As&&... aArguments) + : mArguments(Forward(aArguments)...) {} template static auto - applyImpl(C* o, M m, mozilla::Tuple& args, - mozilla::IndexSequence) - -> decltype(((*o).*m)(mozilla::Get(args).PassAsParameter()...)) + applyImpl(C* o, M m, Tuple& args, IndexSequence) + -> decltype(((*o).*m)(Get(args).PassAsParameter()...)) { - return ((*o).*m)(mozilla::Get(args).PassAsParameter()...); + return ((*o).*m)(Get(args).PassAsParameter()...); } template auto apply(C* o, M m) -> decltype(applyImpl(o, m, mArguments, - typename mozilla::IndexSequenceFor::Type())) + typename IndexSequenceFor::Type())) { return applyImpl(o, m, mArguments, - typename mozilla::IndexSequenceFor::Type()); + typename IndexSequenceFor::Type()); } }; template -class nsRunnableMethodImpl - : public nsRunnableMethodTraits::base_type +class RunnableMethodImpl + : public ::nsRunnableMethodTraits::base_type { - typedef typename nsRunnableMethodTraits::class_type + typedef typename ::nsRunnableMethodTraits::class_type ClassType; - nsRunnableMethodReceiver mReceiver; + ::nsRunnableMethodReceiver mReceiver; Method mMethod; - nsRunnableMethodArguments mArgs; + RunnableMethodArguments mArgs; public: - virtual ~nsRunnableMethodImpl() { Revoke(); }; + virtual ~RunnableMethodImpl() { Revoke(); }; template - explicit nsRunnableMethodImpl(ClassType* aObj, Method aMethod, - Args&&... aArgs) + explicit RunnableMethodImpl(ClassType* aObj, Method aMethod, + Args&&... aArgs) : mReceiver(aObj) , mMethod(aMethod) - , mArgs(mozilla::Forward(aArgs)...) + , mArgs(Forward(aArgs)...) { static_assert(sizeof...(Storages) == sizeof...(Args), "Storages and Args should have equal sizes"); } @@ -765,6 +768,8 @@ public: void Revoke() { mReceiver.Revoke(); } }; +} // namespace detail + // Use this template function like so: // // nsCOMPtr event = @@ -773,37 +778,35 @@ public: // // Statically enforced constraints: // - myObject must be of (or implicitly convertible to) type MyClass -// - MyClass must defined AddRef and Release methods +// - MyClass must define AddRef and Release methods // -namespace mozilla { - template -already_AddRefed::base_type> +already_AddRefed::base_type> NewRunnableMethod(PtrType aPtr, Method aMethod) { - return do_AddRef(new nsRunnableMethodImpl(aPtr, aMethod)); + return do_AddRef(new detail::RunnableMethodImpl(aPtr, aMethod)); } template -already_AddRefed::base_type> +already_AddRefed::base_type> NewCancelableRunnableMethod(PtrType aPtr, Method aMethod) { - return do_AddRef(new nsRunnableMethodImpl(aPtr, aMethod)); + return do_AddRef(new detail::RunnableMethodImpl(aPtr, aMethod)); } template -already_AddRefed::base_type> +already_AddRefed::base_type> NewNonOwningRunnableMethod(PtrType&& aPtr, Method aMethod) { - return do_AddRef(new nsRunnableMethodImpl(aPtr, aMethod)); + return do_AddRef(new detail::RunnableMethodImpl(aPtr, aMethod)); } template -already_AddRefed::base_type> +already_AddRefed::base_type> NewNonOwningCancelableRunnableMethod(PtrType&& aPtr, Method aMethod) { - return do_AddRef(new nsRunnableMethodImpl(aPtr, aMethod)); + return do_AddRef(new detail::RunnableMethodImpl(aPtr, aMethod)); } // Similar to NewRunnableMethod. Call like so: @@ -811,43 +814,43 @@ NewNonOwningCancelableRunnableMethod(PtrType&& aPtr, Method aMethod) // NewRunnableMethod(myObject, &MyClass::HandleEvent, myArg1,...); // 'Types' are the stored type for each argument, see ParameterStorage for details. template -already_AddRefed::base_type> +already_AddRefed::base_type> NewRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs) { static_assert(sizeof...(Storages) == sizeof...(Args), " size should be equal to number of arguments"); - return do_AddRef(new nsRunnableMethodImpl( + return do_AddRef(new detail::RunnableMethodImpl( aPtr, aMethod, mozilla::Forward(aArgs)...)); } template -already_AddRefed::base_type> +already_AddRefed::base_type> NewNonOwningRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs) { static_assert(sizeof...(Storages) == sizeof...(Args), " size should be equal to number of arguments"); - return do_AddRef(new nsRunnableMethodImpl( + return do_AddRef(new detail::RunnableMethodImpl( aPtr, aMethod, mozilla::Forward(aArgs)...)); } template -already_AddRefed::base_type> +already_AddRefed::base_type> NewCancelableRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs) { static_assert(sizeof...(Storages) == sizeof...(Args), " size should be equal to number of arguments"); - return do_AddRef(new nsRunnableMethodImpl( + return do_AddRef(new detail::RunnableMethodImpl( aPtr, aMethod, mozilla::Forward(aArgs)...)); } template -already_AddRefed::base_type> +already_AddRefed::base_type> NewNonOwningCancelableRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs) { static_assert(sizeof...(Storages) == sizeof...(Args), " size should be equal to number of arguments"); - return do_AddRef(new nsRunnableMethodImpl( + return do_AddRef(new detail::RunnableMethodImpl( aPtr, aMethod, mozilla::Forward(aArgs)...)); }