|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace System.Threading
{
public static partial class ThreadPool
{
#if NATIVEAOT
private const bool IsWorkerTrackingEnabledInConfig = false;
#else
private static readonly bool IsWorkerTrackingEnabledInConfig =
AppContextConfigHelper.GetBooleanConfig("System.Threading.ThreadPool.EnableWorkerTracking", "DOTNET_ThreadPool_EnableWorkerTracking");
#endif
#if !(TARGET_BROWSER && FEATURE_WASM_MANAGED_THREADS)
// Indicates whether the thread pool should yield the thread from the dispatch loop to the runtime periodically so that
// the runtime may use the thread for processing other work.
internal static bool YieldFromDispatchLoop => false;
#endif
#if !CORECLR
internal static bool EnsureConfigInitialized() => true;
#endif
internal static object GetOrCreateThreadLocalCompletionCountObject() =>
PortableThreadPool.ThreadPoolInstance.GetOrCreateThreadLocalCompletionCountObject();
public static bool SetMaxThreads(int workerThreads, int completionPortThreads) =>
PortableThreadPool.ThreadPoolInstance.SetMaxThreads(workerThreads, completionPortThreads);
public static void GetMaxThreads(out int workerThreads, out int completionPortThreads)
{
PortableThreadPool.ThreadPoolInstance.GetMaxThreads(out workerThreads, out completionPortThreads);
}
public static bool SetMinThreads(int workerThreads, int completionPortThreads) =>
PortableThreadPool.ThreadPoolInstance.SetMinThreads(workerThreads, completionPortThreads);
public static void GetMinThreads(out int workerThreads, out int completionPortThreads)
{
PortableThreadPool.ThreadPoolInstance.GetMinThreads(out workerThreads, out completionPortThreads);
}
public static void GetAvailableThreads(out int workerThreads, out int completionPortThreads)
{
PortableThreadPool.ThreadPoolInstance.GetAvailableThreads(out workerThreads, out completionPortThreads);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void NotifyWorkItemProgress()
{
PortableThreadPool.ThreadPoolInstance.NotifyWorkItemProgress();
}
internal static bool NotifyThreadBlocked() =>
PortableThreadPool.ThreadPoolInstance.NotifyThreadBlocked();
internal static void NotifyThreadUnblocked()
{
PortableThreadPool.ThreadPoolInstance.NotifyThreadUnblocked();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static bool NotifyWorkItemComplete(object threadLocalCompletionCountObject, int currentTimeMs) =>
PortableThreadPool.ThreadPoolInstance.NotifyWorkItemComplete(threadLocalCompletionCountObject, currentTimeMs);
/// <summary>
/// This method is called to request a new thread pool worker to handle pending work.
/// </summary>
internal static unsafe void RequestWorkerThread()
{
PortableThreadPool.ThreadPoolInstance.RequestWorker();
}
internal static void ReportThreadStatus(bool isWorking)
{
PortableThreadPool.ThreadPoolInstance.ReportThreadStatus(isWorking);
}
internal static RegisteredWaitHandle RegisterWaitForSingleObject(
WaitHandle waitObject,
WaitOrTimerCallback callBack,
object? state,
uint millisecondsTimeOutInterval,
bool executeOnlyOnce,
bool flowExecutionContext)
{
Thread.ThrowIfNoThreadStart();
return PortableThreadPool.RegisterWaitForSingleObject(waitObject, callBack, state, millisecondsTimeOutInterval, executeOnlyOnce, flowExecutionContext);
}
[CLSCompliant(false)]
[SupportedOSPlatform("windows")]
public static unsafe bool UnsafeQueueNativeOverlapped(NativeOverlapped* overlapped) =>
throw new PlatformNotSupportedException(SR.PlatformNotSupported_OverlappedIO);
[Obsolete("ThreadPool.BindHandle(IntPtr) has been deprecated. Use ThreadPool.BindHandle(SafeHandle) instead.")]
[SupportedOSPlatform("windows")]
public static bool BindHandle(IntPtr osHandle) =>
throw new PlatformNotSupportedException(SR.PlatformNotSupported_OverlappedIO);
[SupportedOSPlatform("windows")]
public static bool BindHandle(SafeHandle osHandle) =>
throw new PlatformNotSupportedException(SR.PlatformNotSupported_OverlappedIO);
/// <summary>
/// Gets the number of thread pool threads that currently exist.
/// </summary>
/// <remarks>
/// For a thread pool implementation that may have different types of threads, the count includes all types.
/// </remarks>
public static int ThreadCount
{
get
{
return PortableThreadPool.ThreadPoolInstance.ThreadCount;
}
}
/// <summary>
/// Gets the number of work items that have been processed so far.
/// </summary>
/// <remarks>
/// For a thread pool implementation that may have different types of work items, the count includes all types.
/// </remarks>
public static long CompletedWorkItemCount
{
get
{
return PortableThreadPool.ThreadPoolInstance.CompletedWorkItemCount;
}
}
}
}
|