Backed out 3 changesets (bug 1877678, bug 1849175) for causing failures on browser_op...
[gecko.git] / xpcom / threads / DelayedRunnable.h
blob242278fa5b0fa5e19c7ddaed1dde6afb7bc4bff7
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"
11 #include "nsCOMPtr.h"
12 #include "nsIRunnable.h"
13 #include "nsITargetShutdownTask.h"
14 #include "nsITimer.h"
15 #include "nsThreadUtils.h"
17 namespace mozilla {
19 class DelayedRunnable : public Runnable,
20 public nsITimerCallback,
21 public nsITargetShutdownTask {
22 public:
23 DelayedRunnable(already_AddRefed<nsISerialEventTarget> aTarget,
24 already_AddRefed<nsIRunnable> aRunnable, uint32_t aDelay);
26 NS_DECL_ISUPPORTS_INHERITED
27 NS_DECL_NSIRUNNABLE
28 NS_DECL_NSITIMERCALLBACK
30 nsresult Init();
32 /**
33 * Called when the target is going away so the runnable can be released safely
34 * on the target thread.
36 void TargetShutdown() override;
38 private:
39 ~DelayedRunnable() = default;
40 nsresult DoRun();
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
53 #endif