Commit Graph
153 Commits
Author SHA1 Message Date
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
Justin Link 4af15ea7e0 Bug 1881627: Handle the possibility of failing to create the hi-res timer in HiResWindowsMonitor r=smaug,gstoll
Differential Revision: https://phabricator.services.mozilla.com/D278158
2026-03-04 21:14:24 +00:00
Justin Link 71be0e2c2b Bug 1881627: HiResWindowsMonitor switches between hi- and lo-res timers depending on the tolerance of the wait. r=smaug,gstoll
Differential Revision: https://phabricator.services.mozilla.com/D278157
2026-03-04 21:14:21 +00:00
Justin Link e1dfedda99 Bug 1881627: Compute wait delay tolerance in TimerThread r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D278156
2026-03-04 21:14:18 +00:00
Justin Link 01c7c012c9 Bug 1881627: Implemented HiResWindowsMonitor and used it in TimerThread (on Windows) r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D274769
2026-03-04 21:14:16 +00:00
Justin Link 0c9bc750f3 Bug 1881627: Got rid of WindowsTimerFrequencyManager and related machinery r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D274767
2026-03-04 21:14:10 +00:00
agoloman 5fcce17503 Revert "Bug 1881627: Handle the possibility of failing to create the hi-res timer in HiResWindowsMonitor r=smaug,gstoll" for causing multiple failures.
This reverts commit 64f1200593.

Revert "Bug 1881627: HiResWindowsMonitor switches between hi- and lo-res timers depending on the tolerance of the wait. r=smaug,gstoll"

This reverts commit b26c5e86c4.

Revert "Bug 1881627: Compute wait delay tolerance in TimerThread r=smaug"

This reverts commit 35fff48605.

Revert "Bug 1881627: Implemented HiResWindowsMonitor and used it in TimerThread (on Windows) r=smaug"

This reverts commit 9a0f2b30a0.

Revert "Bug 1881627: Templated *MonitorAuto* r=smaug"

This reverts commit 695384e7e0.

Revert "Bug 1881627: Got rid of WindowsTimerFrequencyManager and related machinery r=smaug"

This reverts commit 2f1747630b.
2026-02-24 21:53:00 +00:00
Justin Link 64f1200593 Bug 1881627: Handle the possibility of failing to create the hi-res timer in HiResWindowsMonitor r=smaug,gstoll
Differential Revision: https://phabricator.services.mozilla.com/D278158
2026-02-24 15:16:44 +00:00
Justin Link b26c5e86c4 Bug 1881627: HiResWindowsMonitor switches between hi- and lo-res timers depending on the tolerance of the wait. r=smaug,gstoll
Differential Revision: https://phabricator.services.mozilla.com/D278157
2026-02-24 15:16:41 +00:00
Justin Link 35fff48605 Bug 1881627: Compute wait delay tolerance in TimerThread r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D278156
2026-02-24 15:16:39 +00:00
Justin Link 9a0f2b30a0 Bug 1881627: Implemented HiResWindowsMonitor and used it in TimerThread (on Windows) r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D274769
2026-02-24 15:16:36 +00:00
Justin Link 2f1747630b Bug 1881627: Got rid of WindowsTimerFrequencyManager and related machinery r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D274767
2026-02-24 15:16:30 +00:00
serge-sans-paille 0257c83b39 Bug 2009953 - Do not use reserved identifiers for macro guard in xpcom r=xpcom-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D278792
2026-01-16 15:12:05 +00:00
serge-sans-paille c961fa4a0b Bug 1993127 - Remove unused inclusion of Attributes.h from xpcom/* r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D269714
2025-10-24 09:33:39 +00:00
Jens Stutte f68da43b49 Bug 1961386 - part 6: Use binary search in Add/RemoveTimerInternal. r=xpcom-reviewers,nika,jlink
The linear scan for the insertion point can be replaced by a binary search.

All the other logic of finding empty slots or removing entries remains unchanged by this.

Resulting complexity:
- Changed: AddTimer becomes minimum O(log[n]) (due to the lower boundary of the binary search) to maximum O(n) depending on the luck we have with finding empty slots.
- Changed: RemoveTimer becomes O(log(n)) always (for the binary search) as we postpone the removal of canceled timers to happen in the Run loop or through re-use.
- Extracting the next timer to fire on the TimerThread remains always O(n) (but happens on the timer thread, where it might disturb less).
- Removing the leading canceled timers remains always O(n) (but happens on the timer thread, where it might disturb less).

Differential Revision: https://phabricator.services.mozilla.com/D249902
2025-07-04 20:10:23 +00:00
Jens Stutte 967b715695 Bug 1961386 - part 5: Simplify TimerThread::Entry and AddTimerInternal. r=xpcom-reviewers,nika,jlink
Entry's lifecycle was strictly bound to (Set)IsInTimerThread. It can become a simple struct which will ease its handling in sorted arrays (or sets).
We simply make explicit calls to SetIsInTimerThread where the add/remove occurs.

AddTimerInternal's many if clauses can be re-arranged in a simpler loop, the way of re-using empty slots should be unchanged by this. This enables us also to not need the ctor for canceled timers in Entry.
Note also that the single loop with swap is faster than scanning first for empty slots and in the not unlikely case of no empty slots moving the tail of timers then.

Differential Revision: https://phabricator.services.mozilla.com/D249901
2025-07-04 20:10:20 +00:00
Jens Stutte 3949ce093c Bug 1961386 - part 3: Substitute timer local mGeneration with TimerThread global sequence. r=xpcom-reviewers,nika,jlink
This will help us later to craft stable and unique sort conditions for TimerThread::mTimers, enabling binary search on the array.

Differential Revision: https://phabricator.services.mozilla.com/D249899
2025-07-04 20:10:14 +00:00
Jens Stutte 4a46ae75c3 Bug 1961386 - part 2: Add MOZ_GUARDED_BY to mTimeout in nsTimerImpl. r=xpcom-reviewers,nika,jlink
Given TimerThread::Entry contains a copy of the timeout, we can use that everywhere we have no lock on nsTimerImpl::mMutex, relying on the invariant that the timeout must not change while the timer is in the TimerThread.
Doing so enables us to annotate it and have stricter checks.
Note that one unsafe, DEBUG-only check remains but it is explicitly annotated as such. TSAN will tell if we are safe enough.

Differential Revision: https://phabricator.services.mozilla.com/D249898
2025-07-04 20:10:11 +00:00
Jens Stutte 9fb0a0eec0 Bug 1961386 - part 1: Remove VerifyTimerListConsistency. r=xpcom-reviewers,nika,jlink
The original intent of this DEBUG only function was to verify our book-keeping.
However, it prevents us from applying strict thread-safety checks on nsTimerImpl::mTimeout.
Given we are going to change our book-keeping up the stack, we can just remove it but:

- add an assertion directly before PostTimerEvent if the timeout remained unchanged
- add placeholder comments where to check for the correct sort order.

Differential Revision: https://phabricator.services.mozilla.com/D249897
2025-07-04 20:10:08 +00:00
Serban Stanca 8507096e4b Revert "Bug 1961386 - part 6: Use binary search in Add/RemoveTimerInternal. r=xpcom-reviewers,nika,jlink" for causing devtools failures in browser_rules_mark_overridden_layers.js.
This reverts commit d0da8faf38.

This reverts commit 290c897a56.

This reverts commit feb3956985.

This reverts commit eb07412c3e.

This reverts commit 31a063c7e3.

This reverts commit c53ea72851.
2025-07-02 18:48:24 +00:00
Jens Stutte d0da8faf38 Bug 1961386 - part 6: Use binary search in Add/RemoveTimerInternal. r=xpcom-reviewers,nika,jlink
The linear scan for the insertion point can be replaced by a binary search.

All the other logic of finding empty slots or removing entries remains unchanged by this.

Resulting complexity:
- Changed: AddTimer becomes minimum O(log[n]) (due to the lower boundary of the binary search) to maximum O(n) depending on the luck we have with finding empty slots.
- Changed: RemoveTimer becomes O(log(n)) always (for the binary search) as we postpone the removal of canceled timers to happen in the Run loop or through re-use.
- Extracting the next timer to fire on the TimerThread remains always O(n) (but happens on the timer thread, where it might disturb less).
- Removing the leading canceled timers remains always O(n) (but happens on the timer thread, where it might disturb less).

Differential Revision: https://phabricator.services.mozilla.com/D249902
2025-07-02 15:08:12 +00:00
Jens Stutte 290c897a56 Bug 1961386 - part 5: Simplify TimerThread::Entry and AddTimerInternal. r=xpcom-reviewers,nika,jlink
Entry's lifecycle was strictly bound to (Set)IsInTimerThread. It can become a simple struct which will ease its handling in sorted arrays (or sets).
We simply make explicit calls to SetIsInTimerThread where the add/remove occurs.

AddTimerInternal's many if clauses can be re-arranged in a simpler loop, the way of re-using empty slots should be unchanged by this. This enables us also to not need the ctor for canceled timers in Entry.
Note also that the single loop with swap is faster than scanning first for empty slots and in the not unlikely case of no empty slots moving the tail of timers then.

Differential Revision: https://phabricator.services.mozilla.com/D249901
2025-07-02 15:08:09 +00:00
Jens Stutte eb07412c3e Bug 1961386 - part 3: Substitute timer local mGeneration with TimerThread global sequence. r=xpcom-reviewers,nika,jlink
This will help us later to craft stable and unique sort conditions for TimerThread::mTimers, enabling binary search on the array.

Differential Revision: https://phabricator.services.mozilla.com/D249899
2025-07-02 15:08:03 +00:00
Jens Stutte 31a063c7e3 Bug 1961386 - part 2: Add MOZ_GUARDED_BY to mTimeout in nsTimerImpl. r=xpcom-reviewers,nika,jlink
Given TimerThread::Entry contains a copy of the timeout, we can use that everywhere we have no lock on nsTimerImpl::mMutex, relying on the invariant that the timeout must not change while the timer is in the TimerThread.
Doing so enables us to annotate it and have stricter checks.
Note that one unsafe, DEBUG-only check remains but it is explicitly annotated as such. TSAN will tell if we are safe enough.

Differential Revision: https://phabricator.services.mozilla.com/D249898
2025-07-02 15:08:00 +00:00
Jens Stutte c53ea72851 Bug 1961386 - part 1: Remove VerifyTimerListConsistency. r=xpcom-reviewers,nika,jlink
The original intent of this DEBUG only function was to verify our book-keeping.
However, it prevents us from applying strict thread-safety checks on nsTimerImpl::mTimeout.
Given we are going to change our book-keeping up the stack, we can just remove it but:

- add an assertion directly before PostTimerEvent if the timeout remained unchanged
- add placeholder comments where to check for the correct sort order.

Differential Revision: https://phabricator.services.mozilla.com/D249897
2025-07-02 15:07:57 +00:00
Justin Link 9d11ed35e1 Bug 1946130: Made ComputeWakeupTimeFromTimers() handle the empty timer list case so that the caller doesn't have to r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D251949
2025-06-25 15:43:46 +00:00
Justin Link cb77d6f01b Bug 1946130: Moved Windows timer frequency management into its own class r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D251947
2025-06-25 15:43:38 +00:00
Justin Link 71d9adc6e5 Bug 1946130: Moved TimerThread telemetry into its own class r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D251946
2025-06-25 15:43:35 +00:00
Justin Link 2f274f3bdf Bug 1946130: Simplified structure of TimerThread::Run() to be clearer where the loop is and what it does r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246708
2025-06-25 15:43:31 +00:00
Justin Link 9952f6d5ac Bug 1946130: Moved TimerThread::Run() waiting into its own function r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246706
2025-06-25 15:43:23 +00:00
Justin Link b5819f7b9f Bug 1946130: Moved some of the TimerThread::Run() statistics code into its own functions r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246705
2025-06-25 15:43:20 +00:00
Justin Link d42603de02 Bug 1946130: Moved telemetry of TimerThread::Run() into its own function r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246704
2025-06-25 15:43:16 +00:00
Serban Stanca bc5b8b89d1 Revert "Bug 1946130: Made ComputeWakeupTimeFromTimers() handle the empty timer list case so that the caller doesn't have to r=smaug" for causing build bustages in TimerThread.cpp.
This reverts commit b9517df139.

This reverts commit 94f1605943.

This reverts commit e7c8089ae5.

This reverts commit 3a5257cf5a.

This reverts commit a3aa7a9eb9.

This reverts commit f2796df814.

This reverts commit 615c0b00a9.

This reverts commit d385fb87cf.

This reverts commit 2de73f03c7.
2025-06-25 05:11:08 +00:00
Justin Link b9517df139 Bug 1946130: Made ComputeWakeupTimeFromTimers() handle the empty timer list case so that the caller doesn't have to r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D251949
2025-06-25 04:37:33 +00:00
Justin Link e7c8089ae5 Bug 1946130: Moved Windows timer frequency management into its own class r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D251947
2025-06-25 04:37:25 +00:00
Justin Link 3a5257cf5a Bug 1946130: Moved TimerThread telemetry into its own class r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D251946
2025-06-25 04:37:22 +00:00
Justin Link a3aa7a9eb9 Bug 1946130: Simplified structure of TimerThread::Run() to be clearer where the loop is and what it does r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246708
2025-06-25 04:37:18 +00:00
Justin Link 615c0b00a9 Bug 1946130: Moved TimerThread::Run() waiting into its own function r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246706
2025-06-25 04:37:10 +00:00
Justin Link d385fb87cf Bug 1946130: Moved some of the TimerThread::Run() statistics code into its own functions r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246705
2025-06-25 04:37:06 +00:00
Justin Link 2de73f03c7 Bug 1946130: Moved telemetry of TimerThread::Run() into its own function r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D246704
2025-06-25 04:37:03 +00:00
Justin Link 9fb0d64095 Bug 1826224: Enable high-precision timers on Windows for foreground processes when not on battery power r=smaug
Initially controlled by a pref and only enabled by default in Nightly.

Differential Revision: https://phabricator.services.mozilla.com/D189555
2023-10-31 14:34:39 +00:00
Natalia Csoregi 1be331f04c Backed out changeset 88295a805fb9 (bug 1826224) for causing bustage on TimerThread.cpp. CLOSED TREE 2023-10-31 06:52:41 +02:00
Justin Link b505dbd7f8 Bug 1826224: Enable high-precision timers on Windows for foreground processes when not on battery power r=smaug
Initially controlled by a pref and only enabled by default in Nightly.

Differential Revision: https://phabricator.services.mozilla.com/D189555
2023-10-31 03:24:34 +00:00
Justin Link dbd41cc54d Bug 1831014: Allowed the first timer in a wake-up to fire slightly early as well. r=smaug
- Prior to this change, we allowed any timer *except* the first to fire early. Being woken up
slightly before our first timer is due was resulting in a lot of "wasted" wake-ups (where we wake
up and do nothing other than go back to sleep).
- This change results in waking up TimerThread 10% less frequently in my test case of watching a
YouTube video.
- Made the allowed early firing tolerance be a constant value rather than calculated at run-time.
- Also cleaned up some includes.

Differential Revision: https://phabricator.services.mozilla.com/D184017
2023-08-04 20:00:10 +00:00
Cristian Tuns b4da885613 Backed out changeset 61d2e733a10c (bug 1831014) for causing build bustages TimerThread.h CLOSED TREE 2023-08-03 14:29:40 -04:00
Justin Link a00c413d29 Bug 1831014: Allowed the first timer in a wake-up to fire slightly early as well. r=smaug
- Prior to this change, we allowed any timer *except* the first to fire early. Being woken up
slightly before our first timer is due was resulting in a lot of "wasted" wake-ups (where we wake
up and do nothing other than go back to sleep).
- This change results in waking up TimerThread 10% less frequently in my test case of watching a
YouTube video.
- Made the allowed early firing tolerance be a constant value rather than calculated at run-time.
- Also cleaned up some includes.

Differential Revision: https://phabricator.services.mozilla.com/D184017
2023-08-03 17:44:18 +00:00
Florian Quèze dc510c9008 Bug 1828013 - Add a scriptable API to list all current nsITimer instances, r=smaug.
Differential Revision: https://phabricator.services.mozilla.com/D175430
2023-04-20 09:43:41 +00:00
Justin Link 8ea083a948 Bug 1783405 - Longer duration timers can have longer firing delays r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D174552
2023-04-11 14:44:44 +00:00
Justin Link 3e1226da16 Bug 1783405 - Look at the upcoming timers to see what can be bundled together when determining when to wake-up. r=smaug,bwc
Differential Revision: https://phabricator.services.mozilla.com/D173105
2023-04-11 14:44:43 +00:00
Justin Link f4a231c66b Bug 1783405 - Added statistics for early wake-ups r=smaug,bwc
Differential Revision: https://phabricator.services.mozilla.com/D173104
2023-04-11 14:44:43 +00:00