Skip to content

Commit

Permalink
Add configurable limit for Atomics.pause iterations (#2047)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma authored Jan 28, 2025
1 parent e6ea23f commit 8925d0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions Jint/Native/Atomics/AtomicsInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private JsValue Pause(JsValue thisObject, JsValue[] arguments)
ExceptionHelper.ThrowRangeError(_realm, "Invalid iteration count");
}

n = System.Math.Min(n, _engine.Options.Constraints.MaxAtomicsPauseIterations);
Thread.SpinWait((int) n);
}
else
Expand Down
5 changes: 5 additions & 0 deletions Jint/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ public class ConstraintOptions
/// The maximum size for JavaScript array, defaults to <see cref="uint.MaxValue"/>.
/// </summary>
public uint MaxArraySize { get; set; } = uint.MaxValue;

/// <summary>
/// How many iterations is Atomics.pause allowed to instruct to wait using <see cref="System.Threading.Thread.SpinWait"/>, defaults to 10 000.
/// </summary>
public int MaxAtomicsPauseIterations { get; set; } = 10_000;
}

/// <summary>
Expand Down

0 comments on commit 8925d0f

Please sign in to comment.