Commit Graph
172 Commits
Author SHA1 Message Date
serge-sans-paille fe158e3dd7 Bug 2033996 - Remove unused include of <mutex> r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D295784
2026-04-25 07:09:01 +00:00
Alexandru Marc f1072efdac Revert "Bug 2033996 - Remove unused include of <mutex> r=emilio"
This reverts commit bace1c3556.
2026-04-24 15:08:46 +00:00
serge-sans-paille bace1c3556 Bug 2033996 - Remove unused include of <mutex> r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D295784
2026-04-24 14:19:07 +00:00
Jens Stutte dc942b445b Bug 2029063 - Clear pool thread free pointer before exiting Run(). r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D292733
2026-04-10 06:32:53 +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
Kui-Feng Lee a3c1207a08 Bug 2009073 - Only crash when thread creation fails in empty nsThreadPool. r=xpcom-reviewers,jstutte
When nsThreadPool::PutEvent() fails to create a new thread, the behavior
should depend on whether the pool already has existing threads:

1. If the pool is empty (mThreads.Count() == 0):
   - This is a fatal condition because there are no threads available to
     process the queued event
   - Crash with MOZ_CRASH to make this failure explicit and debuggable

2. If the pool is not empty:
   - The existing threads can still handle the queued event
   - Return NS_OK to allow the caller to continue normally
   - This provides graceful degradation when thread creation fails but
     the pool can still function

Differential Revision: https://phabricator.services.mozilla.com/D278215
2026-01-14 20:05:43 +00:00
Cosmin Sabou 90ce06af45 Revert "Bug 2009073 - Crash instead of returning error when thread creation fails in nsThreadPool::PutEvent(). r=xpcom-reviewers,jstutte" as requested by the developer.
This reverts commit c04c964cc1.
2026-01-09 18:16:54 +00:00
Kui-Feng Lee c04c964cc1 Bug 2009073 - Crash instead of returning error when thread creation fails in nsThreadPool::PutEvent(). r=xpcom-reviewers,jstutte
Change nsThreadPool::PutEvent() to use MOZ_CRASH() instead of returning
NS_ERROR_UNEXPECTED when NS_NewNamedThread() fails to create a new thread.

Differential Revision: https://phabricator.services.mozilla.com/D278215
2026-01-09 17:45:48 +00:00
Jens Stutte 770dda45ef Bug 2003539 - Remove unused PutEvent variant. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D274762
2025-12-03 08:43:23 +00:00
Jens Stutte 6ced9e58b4 Bug 2003538 - Correct mIsAPoolThreadFree calculation to include idle threads. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D274761
2025-12-03 08:43:21 +00:00
Jens Stutte b0cc2184b0 Bug 2003536 - Adjust an outdated comment in nsThreadPool::ShutdownThread. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D274760
2025-12-03 08:43:19 +00:00
serge-sans-paille 112b4ba840 Bug 1996697 - Remove unused mfbt inclusion in xpcom/** r=emilio,media-playback-reviewers,profiler-reviewers,profiles-reviewers,chunmin,canaltinova,mossop
Differential Revision: https://phabricator.services.mozilla.com/D270267
2025-10-28 14:33:40 +00:00
Jens Stutte 4735619c87 Bug 1979268 - part 2: Implement shutdown tasks for nsThreadPool. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D258805
2025-09-26 17:39:53 +00:00
Jens Stutte 35da0c577c Bug 1986310 - Allow nsThreadPool dispatch during shutdown untill all threads are gone. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D263279
2025-09-17 09:49:25 +00:00
Jens Stutte 94023d61f1 Bug 1986308 - Simplify nsThreadPool::PutEvent after bug 1510226. r=xpcom-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D263278
2025-09-02 17:29:34 +00:00
Nika Layzell 7d39c30b5b Bug 1979013 - Part 2: Require nsITimer API callers to provide a nsACString, r=xpcom-reviewers,media-playback-reviewers,webrtc-reviewers,profiler-reviewers,dom-storage-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,mstange,emz,bwc,janv,emilio,padenot
This avoids the small overhead and potential for bugs from the previous
approach of assuming all `const char*` arguments passed to `nsITimer`
initializers are string literals, by instead requiring the argument to be a
`const nsACString&`. This involves changing all callsites to pass a `""_ns`
string literal down instead of a bare string literal.

It appears that while there were currently no buggy callers which
would've provided a dynamic string, there was at least one piece of code
(nsRepeatService::Start) which did pass down a raw char* which may be
dynamically allocated (all callers pass down `nsLiteralCString` so we're
actually OK here right now, but this was a footgun).

Differential Revision: https://phabricator.services.mozilla.com/D261032
2025-08-29 16:18:25 +00:00
iulian moraru f5d6849317 Revert "Bug 1979013: apply code formatting via Lando" for causing windows build bustages on MFTEncoder.cpp.
This reverts commit 8c929cc018.

Revert "Bug 1979013 - Part 2: Require nsITimer API callers to provide a nsACString, r=xpcom-reviewers,media-playback-reviewers,webrtc-reviewers,profiler-reviewers,dom-storage-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,mstange,emz,bwc,janv,emilio,padenot"

This reverts commit e01c0a6a32.

Revert "Bug 1979013 - Part 1: Eagerly fetch name for timer callbacks, r=xpcom-reviewers,mccr8"

This reverts commit 9f8e73c163.
2025-08-27 23:00:09 +00:00
Nika Layzell e01c0a6a32 Bug 1979013 - Part 2: Require nsITimer API callers to provide a nsACString, r=xpcom-reviewers,media-playback-reviewers,webrtc-reviewers,profiler-reviewers,dom-storage-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,mstange,emz,bwc,janv,emilio,padenot
This avoids the small overhead and potential for bugs from the previous
approach of assuming all `const char*` arguments passed to `nsITimer`
initializers are string literals, by instead requiring the argument to be a
`const nsACString&`. This involves changing all callsites to pass a `""_ns`
string literal down instead of a bare string literal.

It appears that while there were currently no buggy callers which
would've provided a dynamic string, there was at least one piece of code
(nsRepeatService::Start) which did pass down a raw char* which may be
dynamically allocated (all callers pass down `nsLiteralCString` so we're
actually OK here right now, but this was a footgun).

Differential Revision: https://phabricator.services.mozilla.com/D261032
2025-08-27 22:04:15 +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
Jens Stutte 1e58d42d08 Bug 1976556 - Add thread pool name to SpinEventLoopUntil reason on pool shutdown. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D256701
2025-07-11 08:47:45 +00:00
Jens Stutte 53e1705e16 Bug 1891664 - Have a grace timeout before shutting down excess idle threads. r=xpcom-reviewers,necko-reviewers,dom-storage-reviewers,nika,janv,jesup#!xpcom-reviewers
Have idleThreadGraceTimeout and idleThreadMaximumTimeout instead of just idleThreadTimeout.
Clarify that idleThreadMaximumTimeout is only affecting allowed idle threads.
Make idle threads end only after at minimum idleThreadGraceTimeout even if they are in excess.
Remove the idleThreadTimeoutRegressive setting.

Introduce a "most recently used" priority for notifying idle threads to
avoid excessive round-robin through all available idle threads.
The management of the linked list has constant time, adding thus only
minimal overhead wrt to the previous wasIdle flags we had.

As a side effect (and coming from the investigations in bug 1891732) to
some extent this can help to improve the "logical thread affinity",
together with trying to keep events dispatched with NS_DISPATCH_AT_END
on the dispatching thread as much as possible, which should help
TaskQueue a lot with affinity.

Differential Revision: https://phabricator.services.mozilla.com/D209884
2024-06-01 09:05:53 +00:00
Lee Salzman f65b504a4d Bug 1872327 - Don't leak runnables on shutdown in nsThreadPool. r=aosmond
It looks like this was an oversight in bug 1155059, that in one place an
already_AddRefed does not get converted to a RefPtr.

Differential Revision: https://phabricator.services.mozilla.com/D197374
2023-12-29 06:37:44 +00:00
Norisz Fay 85c1b98629 Backed out 3 changesets (bug 1872087, bug 1767344, bug 1872159) for causing gpu related leak failures CLOSED TREE
Backed out changeset 2c0ef884644c (bug 1872087)
Backed out changeset 0cf50076e7ee (bug 1872159)
Backed out changeset a4148511920c (bug 1767344)
2023-12-28 21:24:33 +02:00
Lee Salzman a23d4d6b07 Bug 1767344 - Don't leak runnables on shutdown. r=aosmond
It looks like this was an oversight in bug 1276549, that in one place an
already_AddRefed does not get converted to a RefPtr.

Differential Revision: https://phabricator.services.mozilla.com/D197374
2023-12-28 16:31:06 +00:00
Emilio Cobos Álvarez d02e297b2d Bug 1624819 - Remove TaskCategory and other quantum dom remnants. r=smaug,media-playback-reviewers,credential-management-reviewers,cookie-reviewers,places-reviewers,win-reviewers,valentin,mhowell,sgalich,alwu
Sorry this is not a particularly easy patch to review. But it should be
mostly straight-forward.

I kept Document::Dispatch mostly for convenience, but could be
cleaned-up too / changed by SchedulerGroup::Dispatch. Similarly maybe
that can just be NS_DispatchToMainThread if we add an NS_IsMainThread
check there or something (to preserve shutdown semantics).

Differential Revision: https://phabricator.services.mozilla.com/D190450
2023-10-10 08:51:12 +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
Nazım Can Altınova 5b013c2457 Bug 1807015 - Do not call Timestamp::Now when profiler is not running for event delay data r=nika,mstange
Differential Revision: https://phabricator.services.mozilla.com/D166950
2023-02-14 09:46:18 +00:00
kriswright e04f04014d Bug 1748378 - Create a way to deprioritize threadpools. r=nika
This will be used to deprioritize whole thread pools. The concept works as such:

- Set a thread pool's priority at any time
- Each thread will ensure their priority mirrors the parent pool's priority when it is finished processing events.

I chose to have threads only set themselves to the background when they finish processing events because an event dispatched at an expected priority should be completed at said priority. This ensures that any event dispatch that may expect normal priority (i.e. not operating in the background) has a chance to run at the established priority.

This patch enrolls the background IO to low priority on its creation. It also includes the MacOS implementation of the thread priorities, which utilizes mac's QoS service. According to MacOS's QoS structure, main threads operate at `user-interactive` and offthread work is done at a `default` state, meaning that the OS decides how to set the thread's priority somewhere between `utility` and `user-interactive`. When a thread is put in the background, it must be manually raised back to the expected priority, which means most threads must set themselves to `default` again and the main thread must set itself to `user-interactive`. I demonstrated this in the `nsThread` implementation by checking for the main thread and if this task is running on the main thread somehow, then we use the correct setting.

Rather than having the thread pools dispatch their own deprioritization tasks, I've decided to make this the job of the nsThread. In following bugs we will put entire processes' nsThreads in the background, which will require more use of the new nsThread codepaths.

This behavior is currently restricted to nightly only. On platforms with no implementation, nothing will change.

Differential Revision: https://phabricator.services.mozilla.com/D146534
2023-02-03 16:36:47 +00:00
Nika Layzell c4e5607998 Bug 1809752 - Part 1: Allow querying the current nsThreadPool, r=mccr8
This was always being tracked internlly to implement
nsThreadPool::IsOnCurrentThread, however this patch exposes the getter
publicly.

This will be used to assert if GetCurrentSerialEventTarget() is called from a
threadpool thread without a TaskQueue in the next part.

Differential Revision: https://phabricator.services.mozilla.com/D166603
2023-01-16 23:14:10 +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 e217d09ffb Bug 1809752 - Part 1: Allow querying the current nsThreadPool, r=mccr8
This was always being tracked internlly to implement
nsThreadPool::IsOnCurrentThread, however this patch exposes the getter
publicly.

This will be used to assert if GetCurrentSerialEventTarget() is called from a
threadpool thread without a TaskQueue in the next part.

Differential Revision: https://phabricator.services.mozilla.com/D166603
2023-01-16 23:14:10 +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
Andrew McCreight 291afe14f4 Bug 1792574, part 3 - Don't include nsMemory where it isn't needed. r=xpcom-reviewers,necko-reviewers,valentin,nika
There are only 3 places where nsMemory.h is still needed (image/RasterImage.cpp,
gfx/thebes/gfxFT2FontList.cpp, and nsMemory.cpp). Remove the rest.

Differential Revision: https://phabricator.services.mozilla.com/D158213
2022-09-28 15:17:46 +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
Randell Jesup dcc2fc9b3e Bug 1746500: xpcom Threadpool cleanup r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D134068
2022-02-18 19:39:50 +00:00
Nika Layzell 48c03cc7c2 Bug 1747526 - Return a handle from asyncShutdown to observe and cancel thread shutdown progress, r=xpcom-reviewers,KrisWright
This change introduces a new interface, nsIThreadShutdown, which is used
to handle the relevant state for communicating thread shutdown state
between the joining and terminating threads. This type is now returned
from `nsIThread::AsyncShutdown` and can be used to register callbacks
for when thread shutdown is complete, as well as cancel shutdown
entirely, leading to the underlying PRThread never being joined using
PR_JoinThread. This leaking limitation may be avoidable if support for
detaching PRThreads is added to NSPR, or nsThread switches to a more
feature-complete threading API.

This patch also uses the new interface to rework nsThreadPool's Shutdown
and ShutdownWithTimeout methods to avoid poking at nsThread internals
and instead use the publicly facing methods. This allows us to start
async shutdown for all threads and spin the event loop until they all
complete, or a timeout timer fires.

Differential Revision: https://phabricator.services.mozilla.com/D136045
2022-02-08 23:58:03 +00:00
Jens Stutte 1365b60a5f Bug 1740899: Make nsThreadPool::Shutdown(WithTimeout) return an error on re-entrance. r=xpcom-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D131589
2021-11-19 18:00:52 +00:00
Florian Quèze 23e763f19d Bug 1738285 - move AUTO_PROFILE_FOLLOWING_RUNNABLE to its own header, r=gerald.
Differential Revision: https://phabricator.services.mozilla.com/D129825
2021-10-28 20:35:06 +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
Daniel Holbert 8715febbdf Bug 1733729: Fix non-unified build bustage in xpcom directory. r=mccr8
These changes were necessary for me to build successfully with this in my
mozconfig:
 ac_add_options --enable-debug
 ac_add_options --disable-unified-build
 ac_add_options --enable-profiling

While I'm here, I removed a duplicate include in InputTaskManager.h, and made
nsThreadPool.cpp include its own header first, to match Gecko common practice.

Differential Revision: https://phabricator.services.mozilla.com/D127503
2021-10-05 00:29:56 +00:00
Gerald Squelart f25e1c0093 Bug 1691589 - Reduce reliance on GeckoProfiler.h when only labels (and maybe markers) are needed - r=necko-reviewers,geckoview-reviewers,sg,agi,florian
There are no code changes, only #include changes.
It was a fairly mechanical process: Search for all "AUTO_PROFILER_LABEL", and in each file, if only labels are used, convert "GeckoProfiler.h" into "ProfilerLabels.h" (or just add that last one where needed).
In some files, there were also some marker calls but no other profiler-related calls, in these cases "GeckoProfiler.h" was replaced with both "ProfilerLabels.h" and "ProfilerMarkers.h", which still helps in reducing the use of the all-encompassing "GeckoProfiler.h".

Differential Revision: https://phabricator.services.mozilla.com/D104588
2021-02-16 04:44:19 +00:00
Florian Quèze bf1a24a932 Bug 1688300 - Add 'Runnable' profiler markers showing when runnables are executed and a 'Task' label frame showing which tasks are started by TaskController, r=bas,gerald.
Differential Revision: https://phabricator.services.mozilla.com/D102803
2021-01-26 08:57:19 +00:00
Simon Giesecke fbb9c742c8 Bug 1679272 - Include ScopeExit.h exactly where used. r=andi
Differential Revision: https://phabricator.services.mozilla.com/D98888
2020-12-07 14:25:59 +00:00