1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef XPCOM_THREADS_DELAYEDRUNNABLE_H_
8 #define XPCOM_THREADS_DELAYEDRUNNABLE_H_
10 #include "mozilla/TimeStamp.h"
12 #include "nsIRunnable.h"
13 #include "nsITargetShutdownTask.h"
15 #include "nsThreadUtils.h"
19 class DelayedRunnable
: public Runnable
,
20 public nsITimerCallback
,
21 public nsITargetShutdownTask
{
23 DelayedRunnable(already_AddRefed
<nsISerialEventTarget
> aTarget
,
24 already_AddRefed
<nsIRunnable
> aRunnable
, uint32_t aDelay
);
26 NS_DECL_ISUPPORTS_INHERITED
28 NS_DECL_NSITIMERCALLBACK
33 * Called when the target is going away so the runnable can be released safely
34 * on the target thread.
36 void TargetShutdown() override
;
39 ~DelayedRunnable() = default;
42 const nsCOMPtr
<nsISerialEventTarget
> mTarget
;
43 const TimeStamp mDelayedFrom
;
44 const uint32_t mDelay
;
46 mozilla::Mutex mMutex
{"DelayedRunnable"};
47 nsCOMPtr
<nsIRunnable
> mWrappedRunnable
;
48 nsCOMPtr
<nsITimer
> mTimer
;
51 } // namespace mozilla