public static EcmaValue Wait(TypedArray array, EcmaValue index, EcmaValue value, EcmaValue timeout) { int pos = ValidateWaitableArrayAndIndex(array, index); bool isInt32 = array.ArrayKind == TypedArrayKind.Int32Array; long longValue = isInt32 ? value.ToInt32() : value.ToBigInt64().ToInt64(); timeout = timeout.ToNumber(); if (!RuntimeExecution.Current.CanSuspend) { throw new EcmaTypeErrorException("Atomics.wait cannot be called in this context"); } bool comparandEquals, result; int milliseconds = timeout.IsNaN || timeout > Int32.MaxValue ? -1 : timeout < 0 ? 0 : timeout.ToInt32(); SharedArrayBuffer buffer = (SharedArrayBuffer)array.Buffer; if (isInt32) { result = buffer.Wait(array.GetByteOffset(pos), (int)longValue, milliseconds, out comparandEquals); } else { result = buffer.Wait(array.GetByteOffset(pos), longValue, milliseconds, out comparandEquals); } return(result ? "ok" : comparandEquals ? "timed-out" : "not-equal"); }
public SharedArrayBuffer(SharedArrayBuffer buffer) : base(WellKnownObject.SharedArrayBufferPrototype, (byte[])buffer?.SyncRoot) { Dictionary <long, List <WaiterHandle> > waiterLists = new Dictionary <long, List <WaiterHandle> >(); Interlocked.CompareExchange(ref buffer.waiterLists, waiterLists, null); this.waiterLists = buffer.waiterLists; }
public static EcmaValue Notify(TypedArray array, EcmaValue index, EcmaValue count) { int pos = ValidateWaitableArrayAndIndex(array, index); count = count == default ? Int32.MaxValue : count.ToNumber(); int countValue = count.IsNaN || count <= 0 ? 0 : count > Int32.MaxValue ? Int32.MaxValue : count.ToInt32(); SharedArrayBuffer buffer = (SharedArrayBuffer)array.Buffer; return(buffer.Notify(array.GetByteOffset(pos), countValue)); }