Browse Source

Add configurable limit for Atomics.pause iterations (#2047)

Marko Lahma 6 months ago
parent
commit
8925d0fa89
2 changed files with 6 additions and 0 deletions
  1. 1 0
      Jint/Native/Atomics/AtomicsInstance.cs
  2. 5 0
      Jint/Options.cs

+ 1 - 0
Jint/Native/Atomics/AtomicsInstance.cs

@@ -53,6 +53,7 @@ internal sealed class AtomicsInstance : ObjectInstance
                 ExceptionHelper.ThrowRangeError(_realm, "Invalid iteration count");
                 ExceptionHelper.ThrowRangeError(_realm, "Invalid iteration count");
             }
             }
 
 
+            n = System.Math.Min(n, _engine.Options.Constraints.MaxAtomicsPauseIterations);
             Thread.SpinWait((int) n);
             Thread.SpinWait((int) n);
         }
         }
         else
         else

+ 5 - 0
Jint/Options.cs

@@ -433,6 +433,11 @@ public class Options
         /// The maximum size for JavaScript array, defaults to <see cref="uint.MaxValue"/>.
         /// The maximum size for JavaScript array, defaults to <see cref="uint.MaxValue"/>.
         /// </summary>
         /// </summary>
         public uint MaxArraySize { get; set; } = uint.MaxValue;
         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>
     /// <summary>