Skip to content

Commit 68040cb

Browse files
committed
Address PR feedback
1 parent dffb9b3 commit 68040cb

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/libraries/System.Private.CoreLib/src/Resources/Strings.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3411,7 +3411,7 @@
34113411
<value>The timeout must represent a value between -1 and Int32.MaxValue, inclusive.</value>
34123412
</data>
34133413
<data name="SemaphoreSlim_Wait_TimeSpanTimeoutWrong" xml:space="preserve">
3414-
<value>The timeout must represent a value between -1 and Timer.MaxSupportedTimeout, inclusive.</value>
3414+
<value>The timeout must represent a value between -1 and the maximum allowed timer duration.</value>
34153415
</data>
34163416
<data name="Serialization_BadParameterInfo" xml:space="preserve">
34173417
<value>Non existent ParameterInfo. Position bigger than member's parameters length.</value>

src/libraries/System.Private.CoreLib/src/System/Threading/SemaphoreSlim.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,10 @@ private bool Wait(uint millisecondsTimeout, CancellationToken cancellationToken)
338338
return false;
339339
}
340340

341-
uint startTime = 0;
341+
long startTime = 0;
342342
if (millisecondsTimeout != Timeout.UnsignedInfinite && millisecondsTimeout > 0)
343343
{
344-
startTime = TimeoutHelper.GetTime();
344+
startTime = TimeoutHelper.GetTime64();
345345
}
346346

347347
bool waitSuccessful = false;
@@ -465,7 +465,7 @@ private bool Wait(uint millisecondsTimeout, CancellationToken cancellationToken)
465465
/// <param name="cancellationToken">The CancellationToken to observe.</param>
466466
/// <returns>true if the monitor received a signal, false if the timeout expired</returns>
467467
[UnsupportedOSPlatform("browser")]
468-
private bool WaitUntilCountOrTimeout(uint millisecondsTimeout, uint startTime, CancellationToken cancellationToken)
468+
private bool WaitUntilCountOrTimeout(uint millisecondsTimeout, long startTime, CancellationToken cancellationToken)
469469
{
470470
#if TARGET_WASI
471471
if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185
@@ -483,7 +483,7 @@ private bool WaitUntilCountOrTimeout(uint millisecondsTimeout, uint startTime, C
483483
bool timeoutIsCapped = false;
484484
if (millisecondsTimeout != Timeout.UnsignedInfinite)
485485
{
486-
uint remainingWaitMilliseconds = TimeoutHelper.UpdateTimeOut(startTime, millisecondsTimeout);
486+
long remainingWaitMilliseconds = TimeoutHelper.UpdateTimeOut(startTime, millisecondsTimeout);
487487
if (remainingWaitMilliseconds <= 0)
488488
{
489489
// The thread has expires its timeout

src/libraries/System.Private.CoreLib/src/System/Threading/TimeoutHelper.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ public static uint GetTime()
2121
return (uint)Environment.TickCount;
2222
}
2323

24+
/// <summary>
25+
/// Returns <see cref="Environment.TickCount64"/> as a start time in milliseconds.
26+
/// </summary>
27+
public static long GetTime64()
28+
{
29+
return Environment.TickCount64;
30+
}
31+
2432
/// <summary>
2533
/// Helper function to measure and update the elapsed time
2634
/// </summary>
@@ -56,12 +64,12 @@ public static int UpdateTimeOut(uint startTime, int originalWaitMillisecondsTime
5664
/// <param name="startTime"> The first time (in milliseconds) observed when the wait started</param>
5765
/// <param name="originalWaitMillisecondsTimeout">The original wait timeout in milliseconds</param>
5866
/// <returns>The new wait time in milliseconds</returns>
59-
public static uint UpdateTimeOut(uint startTime, uint originalWaitMillisecondsTimeout)
67+
public static long UpdateTimeOut(long startTime, uint originalWaitMillisecondsTimeout)
6068
{
6169
// The function must be called in case the time out is not infinite
6270
Debug.Assert(originalWaitMillisecondsTimeout != Timeout.UnsignedInfinite);
6371

64-
uint elapsedMilliseconds = GetTime() - startTime;
72+
long elapsedMilliseconds = GetTime64() - startTime;
6573

6674
if (originalWaitMillisecondsTimeout <= elapsedMilliseconds)
6775
{

0 commit comments

Comments
 (0)