mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibCore: IDAllocator should never vend ID 0
This was tripping up CObject which interprets timer ID 0 as "no timer". Once we got ID 0 assigned, it was impossible to turn it off and it would fire on every event loop iteration, causing CPU churn.
This commit is contained in:
parent
c410644c90
commit
1da31ce8ae
Notes:
sideshowbarker
2024-07-19 10:20:35 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/1da31ce8ae7
1 changed files with 3 additions and 0 deletions
|
@ -16,6 +16,9 @@ public:
|
|||
int r = rand();
|
||||
for (int i = 0; i < 100000; ++i) {
|
||||
int allocated_id = r + i;
|
||||
// Make sure we never vend ID 0, as some code may interpret that as "no ID"
|
||||
if (allocated_id == 0)
|
||||
++allocated_id;
|
||||
if (!m_allocated_ids.contains(allocated_id)) {
|
||||
m_allocated_ids.set(allocated_id);
|
||||
return allocated_id;
|
||||
|
|
Loading…
Reference in a new issue