2018-05-10 08:37:03 +00:00
|
|
|
using System;
|
|
|
|
using System.Threading;
|
|
|
|
|
2017-06-07 13:16:24 +00:00
|
|
|
namespace Internal.Runtime.Augments
|
|
|
|
{
|
2018-08-07 15:19:03 +00:00
|
|
|
sealed class RuntimeThread
|
2018-01-29 19:03:06 +00:00
|
|
|
{
|
2019-02-04 20:11:37 +00:00
|
|
|
// Note: Magic number copied from CoreRT's RuntimeThread.cs. See the original source code for an explanation.
|
|
|
|
internal static readonly int OptimalMaxSpinWaitsPerSpinIteration = 64;
|
|
|
|
|
2018-05-10 08:37:03 +00:00
|
|
|
readonly Thread thread;
|
|
|
|
|
|
|
|
RuntimeThread (Thread t) { thread = t; }
|
|
|
|
|
|
|
|
public void ResetThreadPoolThread () {}
|
|
|
|
|
|
|
|
public static RuntimeThread InitializeThreadPoolThread () => default;
|
|
|
|
|
|
|
|
public static RuntimeThread Create (ParameterizedThreadStart start, int maxStackSize)
|
|
|
|
=> new RuntimeThread (new Thread (start, maxStackSize));
|
|
|
|
|
|
|
|
public bool IsBackground
|
2018-01-29 19:03:06 +00:00
|
|
|
{
|
2018-05-10 08:37:03 +00:00
|
|
|
get => thread.IsBackground;
|
|
|
|
set => thread.IsBackground = value;
|
2018-01-29 19:03:06 +00:00
|
|
|
}
|
|
|
|
|
2018-05-10 08:37:03 +00:00
|
|
|
public void Start () => thread.Start ();
|
|
|
|
|
|
|
|
public void Start (object state) => thread.Start (state);
|
|
|
|
|
2019-02-04 20:11:37 +00:00
|
|
|
public static void Sleep(int millisecondsTimeout) => Thread.Sleep (millisecondsTimeout);
|
|
|
|
|
2018-05-10 08:37:03 +00:00
|
|
|
public static bool Yield () => Thread.Yield ();
|
|
|
|
|
|
|
|
public static bool SpinWait (int iterations)
|
2018-01-29 19:03:06 +00:00
|
|
|
{
|
2018-05-10 08:37:03 +00:00
|
|
|
Thread.SpinWait (iterations);
|
|
|
|
return true;
|
2018-01-29 19:03:06 +00:00
|
|
|
}
|
2018-08-07 15:19:03 +00:00
|
|
|
|
|
|
|
public static int GetCurrentProcessorId ()
|
|
|
|
{
|
|
|
|
// TODO: Implement correctly
|
|
|
|
return 1;
|
|
|
|
}
|
2018-01-29 19:03:06 +00:00
|
|
|
}
|
2017-06-07 13:16:24 +00:00
|
|
|
}
|