--- a/xpcom/threads/nsThreadUtils.h
+++ b/xpcom/threads/nsThreadUtils.h
@@ -413,17 +413,17 @@ protected:
private:
IdlePeriod(const IdlePeriod&) = delete;
IdlePeriod& operator=(const IdlePeriod&) = delete;
IdlePeriod& operator=(const IdlePeriod&&) = delete;
};
// Cancelable runnable methods implement nsICancelableRunnable, and
// Idle and IdleWithTimer also nsIIdleRunnable.
-enum RunnableKind
+enum class RunnableKind
{
Standard,
Cancelable,
Idle,
IdleWithTimer
};
// Implementing nsINamed on Runnable bloats vtables for the hundreds of
@@ -670,17 +670,17 @@ public:
nsITimer* GetTimer() { return nullptr; }
void CancelTimer() {}
protected:
~TimerBehaviour() {}
};
template <>
-class TimerBehaviour<IdleWithTimer>
+class TimerBehaviour<RunnableKind::IdleWithTimer>
{
public:
nsITimer* GetTimer()
{
if (!mTimer) {
mTimer = NS_NewTimer();
}
@@ -707,30 +707,30 @@ private:
} // namespace mozilla
// 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
// with nsRevocableEventPtr.
template<class ClassType,
typename ReturnType = void,
bool Owning = true,
- mozilla::RunnableKind Kind = mozilla::Standard>
+ mozilla::RunnableKind Kind = mozilla::RunnableKind::Standard>
class nsRunnableMethod
- : public mozilla::Conditional<Kind == mozilla::Standard,
+ : public mozilla::Conditional<Kind == mozilla::RunnableKind::Standard,
mozilla::Runnable,
typename mozilla::Conditional<
- Kind == mozilla::Cancelable,
+ Kind == mozilla::RunnableKind::Cancelable,
mozilla::CancelableRunnable,
mozilla::IdleRunnable>::Type>::Type,
protected mozilla::detail::TimerBehaviour<Kind>
{
- using BaseType = typename mozilla::Conditional<Kind == mozilla::Standard,
+ using BaseType = typename mozilla::Conditional<Kind == mozilla::RunnableKind::Standard,
mozilla::Runnable,
typename mozilla::Conditional<
- Kind == mozilla::Cancelable,
+ Kind == mozilla::RunnableKind::Cancelable,
mozilla::CancelableRunnable,
mozilla::IdleRunnable>::Type>::Type;
public:
nsRunnableMethod(const char* aName) : BaseType(aName) {}
virtual void Revoke() = 0;
// These ReturnTypeEnforcer classes set up a blacklist for return types that
@@ -770,87 +770,88 @@ struct nsRunnableMethodReceiver<ClassTyp
explicit nsRunnableMethodReceiver(ClassType* aObj) : mObj(aObj) {}
ClassType* Get() const { return mObj; }
void Revoke() { mObj = nullptr; }
};
static inline constexpr bool
IsIdle(mozilla::RunnableKind aKind)
{
- return aKind == mozilla::Idle || aKind == mozilla::IdleWithTimer;
+ return aKind == mozilla::RunnableKind::Idle ||
+ aKind == mozilla::RunnableKind::IdleWithTimer;
}
template<typename PtrType, typename Method, bool Owning, mozilla::RunnableKind Kind>
struct nsRunnableMethodTraits;
template<typename PtrType, class C, typename R, bool Owning, mozilla::RunnableKind Kind, typename... As>
struct nsRunnableMethodTraits<PtrType, R(C::*)(As...), Owning, Kind>
{
typedef typename mozilla::RemoveRawOrSmartPointer<PtrType>::Type class_type;
static_assert(mozilla::IsBaseOf<C, class_type>::value,
"Stored class must inherit from method's class");
typedef R return_type;
typedef nsRunnableMethod<C, R, Owning, Kind> base_type;
- static const bool can_cancel = Kind == mozilla::Cancelable;
+ static const bool can_cancel = Kind == mozilla::RunnableKind::Cancelable;
};
template<typename PtrType, class C, typename R, bool Owning, mozilla::RunnableKind Kind, typename... As>
struct nsRunnableMethodTraits<PtrType, R(C::*)(As...) const, Owning, Kind>
{
typedef const typename mozilla::RemoveRawOrSmartPointer<PtrType>::Type class_type;
static_assert(mozilla::IsBaseOf<C, class_type>::value,
"Stored class must inherit from method's class");
typedef R return_type;
typedef nsRunnableMethod<C, R, Owning, Kind> base_type;
- static const bool can_cancel = Kind == mozilla::Cancelable;
+ static const bool can_cancel = Kind == mozilla::RunnableKind::Cancelable;
};
#ifdef NS_HAVE_STDCALL
template<typename PtrType, class C, typename R, bool Owning, mozilla::RunnableKind Kind, typename... As>
struct nsRunnableMethodTraits<PtrType, R(__stdcall C::*)(As...), Owning, Kind>
{
typedef typename mozilla::RemoveRawOrSmartPointer<PtrType>::Type class_type;
static_assert(mozilla::IsBaseOf<C, class_type>::value,
"Stored class must inherit from method's class");
typedef R return_type;
typedef nsRunnableMethod<C, R, Owning, Kind> base_type;
- static const bool can_cancel = Kind == mozilla::Cancelable;
+ static const bool can_cancel = Kind == mozilla::RunnableKind::Cancelable;
};
template<typename PtrType, class C, typename R, bool Owning, mozilla::RunnableKind Kind>
struct nsRunnableMethodTraits<PtrType, R(NS_STDCALL C::*)(), Owning, Kind>
{
typedef typename mozilla::RemoveRawOrSmartPointer<PtrType>::Type class_type;
static_assert(mozilla::IsBaseOf<C, class_type>::value,
"Stored class must inherit from method's class");
typedef R return_type;
typedef nsRunnableMethod<C, R, Owning, Kind> base_type;
- static const bool can_cancel = Kind == mozilla::Cancelable;
+ static const bool can_cancel = Kind == mozilla::RunnableKind::Cancelable;
};
template<typename PtrType, class C, typename R, bool Owning, mozilla::RunnableKind Kind, typename... As>
struct nsRunnableMethodTraits<PtrType, R(__stdcall C::*)(As...) const, Owning, Kind>
{
typedef const typename mozilla::RemoveRawOrSmartPointer<PtrType>::Type class_type;
static_assert(mozilla::IsBaseOf<C, class_type>::value,
"Stored class must inherit from method's class");
typedef R return_type;
typedef nsRunnableMethod<C, R, Owning, Kind> base_type;
- static const bool can_cancel = Kind == mozilla::Cancelable;
+ static const bool can_cancel = Kind == mozilla::RunnableKind::Cancelable;
};
template<typename PtrType, class C, typename R, bool Owning, mozilla::RunnableKind Kind>
struct nsRunnableMethodTraits<PtrType, R(NS_STDCALL C::*)() const, Owning, Kind>
{
typedef const typename mozilla::RemoveRawOrSmartPointer<PtrType>::Type class_type;
static_assert(mozilla::IsBaseOf<C, class_type>::value,
"Stored class must inherit from method's class");
typedef R return_type;
typedef nsRunnableMethod<C, R, Owning, Kind> base_type;
- static const bool can_cancel = Kind == mozilla::Cancelable;
+ static const bool can_cancel = Kind == mozilla::RunnableKind::Cancelable;
};
#endif
// IsParameterStorageClass<T>::value is true if T is a parameter-storage class
// that will be recognized by NS_New[NonOwning]RunnableMethodWithArg[s] to
// force a specific storage&passing strategy (instead of inferring one,
// see ParameterStorage).
@@ -1216,17 +1217,17 @@ public:
mArgs.apply(mReceiver.Get(), mMethod);
}
return NS_OK;
}
nsresult Cancel()
{
- static_assert(Kind >= Cancelable, "Don't use me!");
+ static_assert(Kind >= RunnableKind::Cancelable, "Don't use me!");
Revoke();
return NS_OK;
}
void Revoke()
{
CancelTimer();
mReceiver.Revoke();
@@ -1253,76 +1254,76 @@ public:
"detail::RunnableMethodImpl::SetTimer");
}
}
};
// Type aliases for NewRunnableMethod.
template<typename PtrType, typename Method>
using OwningRunnableMethod = typename ::nsRunnableMethodTraits<
- typename RemoveReference<PtrType>::Type, Method, true, Standard>::base_type;
+ typename RemoveReference<PtrType>::Type, Method, true, RunnableKind::Standard>::base_type;
template<typename PtrType, typename Method, typename... Storages>
using OwningRunnableMethodImpl = RunnableMethodImpl<
- typename RemoveReference<PtrType>::Type, Method, true, Standard, Storages...>;
+ typename RemoveReference<PtrType>::Type, Method, true, RunnableKind::Standard, Storages...>;
// Type aliases for NewCancelableRunnableMethod.
template<typename PtrType, typename Method>
using CancelableRunnableMethod = typename ::nsRunnableMethodTraits<
- typename RemoveReference<PtrType>::Type, Method, true, Cancelable>::base_type;
+ typename RemoveReference<PtrType>::Type, Method, true, RunnableKind::Cancelable>::base_type;
template<typename PtrType, typename Method, typename... Storages>
using CancelableRunnableMethodImpl = RunnableMethodImpl<
- typename RemoveReference<PtrType>::Type, Method, true, Cancelable, Storages...>;
+ typename RemoveReference<PtrType>::Type, Method, true, RunnableKind::Cancelable, Storages...>;
// Type aliases for NewIdleRunnableMethod.
template<typename PtrType, typename Method>
using IdleRunnableMethod = typename ::nsRunnableMethodTraits<
- typename RemoveReference<PtrType>::Type, Method, true, Idle>::base_type;
+ typename RemoveReference<PtrType>::Type, Method, true, RunnableKind::Idle>::base_type;
template<typename PtrType, typename Method, typename... Storages>
using IdleRunnableMethodImpl = RunnableMethodImpl<
- typename RemoveReference<PtrType>::Type, Method, true, Idle, Storages...>;
+ typename RemoveReference<PtrType>::Type, Method, true, RunnableKind::Idle, Storages...>;
// Type aliases for NewIdleRunnableMethodWithTimer.
template<typename PtrType, typename Method>
using IdleRunnableMethodWithTimer = typename ::nsRunnableMethodTraits<
- typename RemoveReference<PtrType>::Type, Method, true, IdleWithTimer>::base_type;
+ typename RemoveReference<PtrType>::Type, Method, true, RunnableKind::IdleWithTimer>::base_type;
template<typename PtrType, typename Method, typename... Storages>
using IdleRunnableMethodWithTimerImpl = RunnableMethodImpl<
- typename RemoveReference<PtrType>::Type, Method, true, IdleWithTimer, Storages...>;
+ typename RemoveReference<PtrType>::Type, Method, true, RunnableKind::IdleWithTimer, Storages...>;
// Type aliases for NewNonOwningRunnableMethod.
template<typename PtrType, typename Method>
using NonOwningRunnableMethod = typename ::nsRunnableMethodTraits<
- typename RemoveReference<PtrType>::Type, Method, false, Standard>::base_type;
+ typename RemoveReference<PtrType>::Type, Method, false, RunnableKind::Standard>::base_type;
template<typename PtrType, typename Method, typename... Storages>
using NonOwningRunnableMethodImpl = RunnableMethodImpl<
- typename RemoveReference<PtrType>::Type, Method, false, Standard, Storages...>;
+ typename RemoveReference<PtrType>::Type, Method, false, RunnableKind::Standard, Storages...>;
// Type aliases for NonOwningCancelableRunnableMethod
template<typename PtrType, typename Method>
using NonOwningCancelableRunnableMethod = typename ::nsRunnableMethodTraits<
- typename RemoveReference<PtrType>::Type, Method, false, Cancelable>::base_type;
+ typename RemoveReference<PtrType>::Type, Method, false, RunnableKind::Cancelable>::base_type;
template<typename PtrType, typename Method, typename... Storages>
using NonOwningCancelableRunnableMethodImpl = RunnableMethodImpl<
- typename RemoveReference<PtrType>::Type, Method, false, Cancelable, Storages...>;
+ typename RemoveReference<PtrType>::Type, Method, false, RunnableKind::Cancelable, Storages...>;
// Type aliases for NonOwningIdleRunnableMethod
template<typename PtrType, typename Method>
using NonOwningIdleRunnableMethod = typename ::nsRunnableMethodTraits<
- typename RemoveReference<PtrType>::Type, Method, false, Idle>::base_type;
+ typename RemoveReference<PtrType>::Type, Method, false, RunnableKind::Idle>::base_type;
template<typename PtrType, typename Method, typename... Storages>
using NonOwningIdleRunnableMethodImpl = RunnableMethodImpl<
- typename RemoveReference<PtrType>::Type, Method, false, Idle, Storages...>;
+ typename RemoveReference<PtrType>::Type, Method, false, RunnableKind::Idle, Storages...>;
// Type aliases for NewIdleRunnableMethodWithTimer.
template<typename PtrType, typename Method>
using NonOwningIdleRunnableMethodWithTimer = typename ::nsRunnableMethodTraits<
- typename RemoveReference<PtrType>::Type, Method, false, IdleWithTimer>::base_type;
+ typename RemoveReference<PtrType>::Type, Method, false, RunnableKind::IdleWithTimer>::base_type;
template<typename PtrType, typename Method, typename... Storages>
using NonOwningIdleRunnableMethodWithTimerImpl = RunnableMethodImpl<
- typename RemoveReference<PtrType>::Type, Method, false, IdleWithTimer, Storages...>;
+ typename RemoveReference<PtrType>::Type, Method, false, RunnableKind::IdleWithTimer, Storages...>;
} // namespace detail
// NewRunnableMethod and friends
//
// Very often in Gecko, you'll find yourself in a situation where you want
// to invoke a method (with or without arguments) asynchronously. You
// could write a small helper class inheriting from nsRunnable to handle