Commit Graph
65 Commits
Author SHA1 Message Date
Daniel Holbert ac764635e4 Bug 2043772: Use MakeRefPtr to do allocation for various RefPtr variables in xpcom/threads/. r=xpcom-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D303524
2026-05-30 14:29:48 +00:00
Sylvestre Ledru 6149f49299 Bug 2023419 - Remove Emacs/Vim modelines from xpcom/ r=emilio
replaced by .editorconfig
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D287878
2026-03-16 17:22:07 +00:00
Jens Stutte 6829afc661 Bug 1999508 - Introduce nsIEventTarget::GetFeatures. r=xpcom-reviewers,necko-reviewers,dom-worker-reviewers,nika,asuth,valentin
Introduces SUPPORTS_SHUTDOWN_TASKS and SUPPORTS_SHUTDOWN_TASK_DISPATCH flags.

This just wires the function through all event targets without ever being used.

Differential Revision: https://phabricator.services.mozilla.com/D272150
2026-01-28 07:24:07 +00:00
Nika Layzell b66d532c27 Bug 1824189 - Add a NS_DISPATCH_FALLIBLE flag to specify that events should not be leaked on error, r=xpcom-reviewers,necko-reviewers,geckoview-reviewers,media-playback-reviewers,webrtc-reviewers,bwc,padenot,emilio,jstutte,dom-worker-reviewers,asuth,kershaw,ohall
Differential Revision: https://phabricator.services.mozilla.com/D258327
2025-08-26 16:47:30 +00:00
Atila Butkovits a906e9e172 Revert "Bug 1824189 - Add a NS_DISPATCH_FALLIBLE flag to specify that events should not be leaked on error, r=xpcom-reviewers,necko-reviewers,geckoview-reviewers,media-playback-reviewers,webrtc-reviewers,bwc,padenot,emilio,jstutte,dom-worker-reviewers,asuth,kershaw,ohall" for causing leaks complaining about MediaTransportHandlerSTS.
This reverts commit 381d5dd6f0.
2025-08-26 00:43:59 +00:00
Nika Layzell 381d5dd6f0 Bug 1824189 - Add a NS_DISPATCH_FALLIBLE flag to specify that events should not be leaked on error, r=xpcom-reviewers,necko-reviewers,geckoview-reviewers,media-playback-reviewers,webrtc-reviewers,bwc,padenot,emilio,jstutte,dom-worker-reviewers,asuth,kershaw,ohall
Differential Revision: https://phabricator.services.mozilla.com/D258327
2025-08-25 23:20:08 +00:00
Nika Layzell 37b9397bc1 Bug 1856087 - Bypass assertion if NS_DISPATCH_IGNORE_BLOCK_DISPATCH is set, r=xpcom-reviewers,jstutte
The `gXPCOMThreadsShutDownNotified` assertion exists to discourage
dispatching to a background thread after xpcom-shutdown-threads. This
unfortunately poorly interacts with the nsThreadPool implementation. We
use nsThreadPools all of the way until threads are fully shut down
during ShutdownNonMainThreads, and they dispatch a runnable to a
background thread when starting a new thread.

This patch disables the assertion when NS_DISPATCH_IGNORE_BLOCK_DISPATCH
is specified. This flag already effectively indicates "trust me I am
dispatching to a thread which is in a weird state, this dispatch must
succeed", so seems appropriate to use in this situation, and will avoid
the underlying issue.

The nsThreadPool runnable is already dispatched with this flag set.

Differential Revision: https://phabricator.services.mozilla.com/D190303
2023-10-06 20:57:58 +00:00
Nika Layzell 085ce48510 Bug 1825360 - Remove the NS_DISPATCH_SYNC flag, r=necko-reviewers,geckoview-reviewers,media-playback-reviewers,karlt,jesup,m_kato,emilio
This flag is not supported by most event targets and can have unexpected
side effects (namely spinning a nested event loop). All consumers have
been replaced with a new function which is more explicit about this side
effect.

Differential Revision: https://phabricator.services.mozilla.com/D173985
2023-03-30 16:53:51 +00:00
Nika Layzell 309d61988a Bug 1809753 - Part 2: Switch some calls to GetCurrentEventTarget() to NS_GetCurrentThread, r=mccr8
These callers are depending on the existing behaviour which always returns a
thread, and does not respect custom TaskQueues. In the next part, all remaining
callers will be switched to GetCurrentSerialEventTarget.

Differential Revision: https://phabricator.services.mozilla.com/D166606
2023-01-16 23:14:11 +00:00
Sandor Molnar f236c54e45 Backed out 6 changesets (bug 1809752, bug 1809753) for causing perma failures in browser/components/firefoxview/tests/browser/browser_feature_callout_position.js
Backed out changeset ea05784d74c4 (bug 1809753)
Backed out changeset 7c9b20eebcc8 (bug 1809753)
Backed out changeset d0267ac2256d (bug 1809753)
Backed out changeset aa9f2971bd6f (bug 1809753)
Backed out changeset f0d9fcfaa6f8 (bug 1809752)
Backed out changeset 6d58c799cffe (bug 1809752)
2023-01-17 03:19:24 +02:00
Nika Layzell 54fc2ba71e Bug 1809753 - Part 2: Switch some calls to GetCurrentEventTarget() to NS_GetCurrentThread, r=mccr8
These callers are depending on the existing behaviour which always returns a
thread, and does not respect custom TaskQueues. In the next part, all remaining
callers will be switched to GetCurrentSerialEventTarget.

Differential Revision: https://phabricator.services.mozilla.com/D166606
2023-01-16 23:14:11 +00:00
Nika Layzell 119713a821 Bug 1799222 - Part 1: Prevent accidental dispatches to threadpool and timer threads, r=xpcom-reviewers,necko-reviewers,geckoview-reviewers,media-playback-reviewers,jesup,m_kato,padenot,kmag
Differential Revision: https://phabricator.services.mozilla.com/D161349
2022-12-16 17:09:16 +00:00
Cristian Tuns de12c42c7f Backed out changeset 42315c023471 (bug 1799222) for causing multiple failures CLOSED TREE 2022-12-06 16:35:58 -05:00
Nika Layzell e8f474cee1 Bug 1799222 - Prevent accidental dispatches to threadpool and timer threads, r=xpcom-reviewers,necko-reviewers,geckoview-reviewers,media-playback-reviewers,jesup,m_kato,padenot,kmag
Differential Revision: https://phabricator.services.mozilla.com/D161349
2022-12-06 20:44:15 +00:00
Jens Stutte dcff8749d8 Bug 1797688 - Part 9: Make gXPCOMThreadsShutDown DEBUG only. r=xpcom-reviewers,mccr8
`gXPCOMThreadsShutDown` is needed for the assertion in `ThreadEventTarget::Dispatch` but we do not want other shutdown checks to rely on it, as it is too specific for this case. If we ever would really need this checkpoint in time during runtime in release we should consider to make it become a new `ShutdownPhase` in between.

We move the state to `ThreadEventTarget` and have a `DEBUG` only method to prime that assertion over there.

Differential Revision: https://phabricator.services.mozilla.com/D160627
2022-11-01 14:08:46 +00:00
Nika Layzell 98bcad1990 Bug 1764119 - Part 2: Don't check gXPCOMThreadsShutdown in ThreadEventTarget::Dispatch, r=xpcom-reviewers,kmag,jstutte
We already have a mechanism for ending threads accepting new messages
when they are shut down, so this only allows tasks started from thread
shutdown tasks during xpcom shutdown to behave consistently.

We already didn't prevent dispatching to the background thread pool at
this time, so it should make little difference there as well, and may
just instead save us from deadlocks where code expects a dispatch to
succeed and it does not during actor shutdown.

This patch both relaxes the check to only be a NS_ASSERTION, and relaxes
it to allow dispatching to the current thread even after
xpcom-shutdown-threads as that thread is definitely still alive.

Differential Revision: https://phabricator.services.mozilla.com/D144592
2022-05-02 20:38:43 +00:00
criss 79d73b87ae Backed out 2 changesets (bug 1764119) for causing build bustages. CLOSED TREE
Backed out changeset 62743521627e (bug 1764119)
Backed out changeset f8ba6b0a8c6f (bug 1764119)
2022-05-02 19:35:23 +03:00
Nika Layzell 890b99c20a Bug 1764119 - Part 2: Don't check gXPCOMThreadsShutdown in ThreadEventTarget::Dispatch, r=xpcom-reviewers,kmag,jstutte
We already have a mechanism for ending threads accepting new messages
when they are shut down, so this only allows tasks started from thread
shutdown tasks during xpcom shutdown to behave consistently.

We already didn't prevent dispatching to the background thread pool at
this time, so it should make little difference there as well, and may
just instead save us from deadlocks where code expects a dispatch to
succeed and it does not during actor shutdown.

This patch both relaxes the check to only be a NS_ASSERTION, and relaxes
it to allow dispatching to the current thread even after
xpcom-shutdown-threads as that thread is definitely still alive.

Differential Revision: https://phabricator.services.mozilla.com/D144592
2022-05-02 16:09:03 +00:00
Nika Layzell c320f56d5b Bug 1738103 - Part 4: Add XPCOM support for shutdown tasks, r=necko-reviewers,KrisWright
Tasks registered with shutdown tasks are called when the target
nsISerialEventTarget is about to be destroyed.

Differential Revision: https://phabricator.services.mozilla.com/D129840
2022-03-23 22:22:04 +00:00
Jens Stutte 25c0c4359e Bug 1731564: Use motivated SpinEventLoopUntil inside xpcom/*. r=xpcom-reviewers,nika
Depends on D127236

Differential Revision: https://phabricator.services.mozilla.com/D127237
2021-10-07 08:06:16 +00:00
Marian-Vasile Laza 7de6967c5a Backed out 18 changesets (bug 1731564) for causing build bustages on SpinEventLoopUntil. CLOSED TREE
Backed out changeset 0464dbdc8584 (bug 1731564)
Backed out changeset 0d996df13545 (bug 1731564)
Backed out changeset 5630a0e7a109 (bug 1731564)
Backed out changeset 37b41d187cdb (bug 1731564)
Backed out changeset d37700fa60b6 (bug 1731564)
Backed out changeset b0ce7db44b99 (bug 1731564)
Backed out changeset aa5ec3aa1535 (bug 1731564)
Backed out changeset 73b648f1fa70 (bug 1731564)
Backed out changeset bb8fb0f9833e (bug 1731564)
Backed out changeset 0d8905144f5d (bug 1731564)
Backed out changeset 2cfb094a1ec3 (bug 1731564)
Backed out changeset 78d3b0257a6a (bug 1731564)
Backed out changeset e9d32926e93c (bug 1731564)
Backed out changeset 874cab520ce5 (bug 1731564)
Backed out changeset d8071cc32bd9 (bug 1731564)
Backed out changeset 283c5393cbbc (bug 1731564)
Backed out changeset 317bc38e3de5 (bug 1731564)
Backed out changeset 53e3f4862439 (bug 1731564)
2021-10-07 00:09:19 +03:00
Jens Stutte 5031cded6d Bug 1731564: Use motivated SpinEventLoopUntil inside xpcom/*. r=xpcom-reviewers,nika
Depends on D127236

Differential Revision: https://phabricator.services.mozilla.com/D127237
2021-10-06 19:45:18 +00:00
Florian Quèze 76d92a054e Bug 1715257 - Remove Task Tracer code from the profiler, r=gerald,necko-reviewers.
Differential Revision: https://phabricator.services.mozilla.com/D117996
2021-06-17 09:33:00 +00:00
Iulian Moraru 4b5e996bef Backed out changeset 617a466d0cce (bug 1715257) for causing build bustages. CLOSED TREE 2021-06-17 10:58:16 +03:00
Florian Quèze 2b195470a1 Bug 1715257 - Remove Task Tracer code from the profiler, r=gerald,necko-reviewers.
Differential Revision: https://phabricator.services.mozilla.com/D117996
2021-06-17 06:12:10 +00:00
Kris Wright 7f6e31498f Bug 1704887 - Discard results of RemoveElement for DelayedRunnable r=necko-reviewers,xpcom-reviewers,mccr8,valentin
This silences a lint error on the previous patches in the series.

Differential Revision: https://phabricator.services.mozilla.com/D113160
2021-05-28 19:05:29 +00:00
Andreas Pehrson ec63d0f3e4 Bug 1704887 - Remove assertions in OnDelayedRunnableRan. r=KrisWright,necko-reviewers,valentin
DelayedDispatch, in all current implementations, will set up a timer sync and
then Dispatch() a runnable. Since the timer is set up before the Dispatch, there
is a theoretical chance that the timer fires and dispatches a TimerEvent to the
target thread before DelayedDispatch managed to do so. When this happens the
internal DelayedDispatch runnable exits early, i.e., in practice it never runs.

The chance increases dramatically if the Dispatch() to the target in question is
tail dispatched, since the time between DelayedDispatch and the tail could be
non-trivial.

This patch removes the assert that checks that all DelayedRunnables that have
run have also been scheduled, since per the above no such guarantee exists.

Differential Revision: https://phabricator.services.mozilla.com/D112876
2021-05-28 19:05:29 +00:00
Andreea Pavel 79c809c265 Backed out 3 changesets (bug 1704887) for Gtest failures on a CLOSED TREE
Backed out changeset 211dcc933514 (bug 1704887)
Backed out changeset bde076bfca7e (bug 1704887)
Backed out changeset 34e875f85b88 (bug 1704887)
2021-04-23 03:40:57 +03:00
Kris Wright 05d1049acb Bug 1704887 - Discard results of RemoveElement for DelayedRunnable r=necko-reviewers,xpcom-reviewers,mccr8,valentin
This silences a lint error on the previous patches in the series.

Differential Revision: https://phabricator.services.mozilla.com/D113160
2021-04-22 21:32:39 +00:00
Andreas Pehrson 6f44e0e8d2 Bug 1704887 - Remove assertions in OnDelayedRunnableRan. r=KrisWright,necko-reviewers,valentin
DelayedDispatch, in all current implementations, will set up a timer sync and
then Dispatch() a runnable. Since the timer is set up before the Dispatch, there
is a theoretical chance that the timer fires and dispatches a TimerEvent to the
target thread before DelayedDispatch managed to do so. When this happens the
internal DelayedDispatch runnable exits early, i.e., in practice it never runs.

The chance increases dramatically if the Dispatch() to the target in question is
tail dispatched, since the time between DelayedDispatch and the tail could be
non-trivial.

This patch removes the assert that checks that all DelayedRunnables that have
run have also been scheduled, since per the above no such guarantee exists.

Differential Revision: https://phabricator.services.mozilla.com/D112876
2021-04-22 21:32:39 +00:00
Andreas Pehrson 6b5a6f5a8a Bug 1695580 - In xpcom, cancel pending DelayedRunnable timers on shutdown. r=KrisWright
Because DelayedRunnables are fire-and-forget, there is no way for a targeted
EventTarget to clean them up on shutdown. Thus if a timer fires after
EventTarget shutdown it will fail to dispatch the timer event, and avoid
releasing the timer callback because it's not on the targeted thread. This
causes a leak as there is a ref-cycle between nsTimerImpl::mCallback and
DelayedRunnable::mTimer.

This patch adds nsIDelayedRunnableObserver for a target to observe which
DelayedRunnables are relying on their timer to run them. This allows the target
to schedule a shutdown task to cancel those timers and release the runnables on
the target thread.

Supported DelayedRunnable targets with this patch are TaskQueues,
eventqueue-based nsThreads and XPCOMThreadWrappers that wrap a supported
nsThread.

An assertion makes sure at runtime that future new uses of DelayedRunnable
target nsIDelayedRunnableObserver-supported event targets.

Differential Revision: https://phabricator.services.mozilla.com/D109781
2021-04-06 20:15:11 +00:00
Andreas Pehrson b445a0aea4 Bug 1695580 - Break out DelayedRunnable into its own files. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D109778
2021-04-06 20:15:09 +00:00
Brindusan Cristian 13b2a5f0b2 Backed out 8 changesets (bug 1695580) for causing build bustages on DataMutex.h. CLOSED TREE
Backed out changeset ec0b0fcc8d88 (bug 1695580)
Backed out changeset 982a46056fcb (bug 1695580)
Backed out changeset e38e8b90f119 (bug 1695580)
Backed out changeset 6fdd154aa151 (bug 1695580)
Backed out changeset d04f7a7ec375 (bug 1695580)
Backed out changeset 2103cd9e58b7 (bug 1695580)
Backed out changeset de9a7dd7fc79 (bug 1695580)
Backed out changeset ae16f09be41b (bug 1695580)
2021-04-06 17:41:19 +03:00
Andreas Pehrson 42799c4a6e Bug 1695580 - In xpcom, cancel pending DelayedRunnable timers on shutdown. r=KrisWright
Because DelayedRunnables are fire-and-forget, there is no way for a targeted
EventTarget to clean them up on shutdown. Thus if a timer fires after
EventTarget shutdown it will fail to dispatch the timer event, and avoid
releasing the timer callback because it's not on the targeted thread. This
causes a leak as there is a ref-cycle between nsTimerImpl::mCallback and
DelayedRunnable::mTimer.

This patch adds nsIDelayedRunnableObserver for a target to observe which
DelayedRunnables are relying on their timer to run them. This allows the target
to schedule a shutdown task to cancel those timers and release the runnables on
the target thread.

Supported DelayedRunnable targets with this patch are TaskQueues,
eventqueue-based nsThreads and XPCOMThreadWrappers that wrap a supported
nsThread.

An assertion makes sure at runtime that future new uses of DelayedRunnable
target nsIDelayedRunnableObserver-supported event targets.

Differential Revision: https://phabricator.services.mozilla.com/D109781
2021-04-06 12:16:11 +00:00
Andreas Pehrson 9a7c9068c4 Bug 1695580 - Break out DelayedRunnable into its own files. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D109778
2021-04-06 12:16:10 +00:00
Doug Thayer 19984c9099 Bug 1510226 - Do not block main thread in nsThread::Init r=froydnj,KrisWright
Differential Revision: https://phabricator.services.mozilla.com/D41248
2021-01-25 21:44:15 +00:00
Simon Giesecke c83a083a0c Bug 1676365 - Move SpinEventLoopUntil to separate header. r=#xpcom-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D96556

Depends on D96554
2020-11-23 16:10:41 +00:00
Jean-Yves Avenard 934acd24fc Bug 1649671 - Add DelayedDispatch support to AbstractThread (and TaskQueue). r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D81811
2020-07-02 00:08:54 +00:00
Jean-Yves Avenard 05adafa9ef Bug 1637500 - P2. Rename methods as they are not always dealing with "threads". r=froydnj
Before P1, GetCurrentThreadSerialEventTarget would have always returned the same data as NS_GetCurrentThread, making the comment incorrect Now it will properly return the running TaskQueue if any.

This change of name more clearly exposes what they are doing, as we aren't always dealing with threads directly; but a nsISerialEventTarget

Differential Revision: https://phabricator.services.mozilla.com/D80354
2020-06-23 05:05:36 +00:00
Honza Bambas 3869f6b082 Bug 1634950 - Add event dispatch-and-run MOZ_LOG to our xpcom threads, r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D73622
2020-05-12 12:48:49 +00:00
Jean-Yves Avenard c62888d151 Bug 1634253 - P3. Don't cause assertion when delay is 0. r=froydnj
already_AddRefed destructor assert that it's nullptr.
DelayedDispatch check that the value passed isn't 0 and return an error code, leaving the already_AddRefed untouched.

Differential Revision: https://phabricator.services.mozilla.com/D73821
2020-05-08 20:20:30 +00:00
Narcis Beleuzu 221d9102fa Backed out 9 changesets (bug 1634253) for bc failures on browser_bug295977_autoscroll_overflow.js . CLOSED TREE
Backed out changeset d41b75c1f7ec (bug 1634253)
Backed out changeset 5f8a1ee17b81 (bug 1634253)
Backed out changeset 43eda078b405 (bug 1634253)
Backed out changeset e98212a74709 (bug 1634253)
Backed out changeset 855e222ceb14 (bug 1634253)
Backed out changeset 9f01acdf4367 (bug 1634253)
Backed out changeset ea62cb1ec472 (bug 1634253)
Backed out changeset fa3e7588e7d6 (bug 1634253)
Backed out changeset 139e7035e736 (bug 1634253)
2020-05-08 23:09:31 +03:00
Jean-Yves Avenard 946e070d6d Bug 1634253 - P3. Don't cause assertion when delay is 0. r=froydnj
already_AddRefed destructor assert that it's nullptr.
DelayedDispatch check that the value passed isn't 0 and return an error code, leaving the already_AddRefed untouched.

Differential Revision: https://phabricator.services.mozilla.com/D73821
2020-05-07 08:04:37 +00:00
Dorel Luca 68273599af Backed out 11 changesets (bug 1635001, bug 1634253) for Browser-chrome failures in browser_bug295977_autoscroll_overflow.js
Backed out changeset c3c27cb46db6 (bug 1635001)
Backed out changeset 6cea251e5910 (bug 1635001)
Backed out changeset 3cb0a05be7fc (bug 1635001)
Backed out changeset 1cbb2866a3ad (bug 1634253)
Backed out changeset 53fd00dcf95c (bug 1634253)
Backed out changeset e3acd9db7065 (bug 1634253)
Backed out changeset 5c0b7aa99406 (bug 1634253)
Backed out changeset dc7e17f772be (bug 1634253)
Backed out changeset 6e47af64396a (bug 1634253)
Backed out changeset 8865de9ae0ef (bug 1634253)
Backed out changeset 6fac93b596c2 (bug 1634253)
2020-05-07 11:00:04 +03:00
Jean-Yves Avenard 4d61896603 Bug 1634253 - P3. Don't cause assertion when delay is 0. r=froydnj
already_AddRefed destructor assert that it's nullptr.
DelayedDispatch check that the value passed isn't 0 and return an error code, leaving the already_AddRefed untouched.

Differential Revision: https://phabricator.services.mozilla.com/D73821
2020-05-07 05:02:39 +00:00
Simon Giesecke 9bcfd47601 Bug 1611415 - Prefer using std::move over forget. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D60980
2020-02-13 14:38:48 +00:00
shindli 6bb3487209 Backed out changeset 0c982bc69cb3 (bug 1611415) for causing build bustages in /builds/worker/workspace/build/src/obj-firefox/dist/include/nsCOMPtr CLOSED TREE 2020-02-12 20:13:29 +02:00
Simon Giesecke d45525793f Bug 1611415 - Applied FixItHints from mozilla-non-std-move. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D60980
2020-02-12 17:24:41 +00:00
Simon Giesecke 81bd203f46 Bug 1613985 - Use default for equivalent-to-default constructors/destructors in xpcom. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D62543
2020-02-12 11:13:33 +00:00
Karl Tomlinson 8034c52d50 Bug 1604005 implement ThreadEventTarget::IsOnCurrentThreadInfallible() to handle case of null mThread r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D58999
2020-01-08 15:25:27 +00:00