+FCIMPL0(UINT32, SystemNative::GetCurrentProcessorNumber)
+{
+ FCALL_CONTRACT;
+
+ return ::GetCurrentProcessorNumber();
+}
+FCIMPLEND;
+
+
+
FCIMPL0(UINT32, SystemNative::GetTickCount)
{
FCALL_CONTRACT;
public:
// Functions on the System.Environment class
static FCDECL0(INT64, __GetSystemTimeAsFileTime);
+ static FCDECL0(UINT32, GetCurrentProcessorNumber);
static FCDECL0(UINT32, GetTickCount);
static FCDECL1(FC_BOOL_RET, GetOSVersion, OSVERSIONINFOObject *osVer);
static FCDECL1(FC_BOOL_RET, GetOSVersionEx, OSVERSIONINFOEXObject *osVer);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
- // On Unix, GetCurrentProcessorNumber is implemented in terms of sched_getcpu, which
+ // On Unix, CurrentProcessorNumber is implemented in terms of sched_getcpu, which
// doesn't exist on all platforms. On those it doesn't exist on, GetCurrentProcessorNumber
// returns -1. As a fallback in that case and to spread the threads across the buckets
// by default, we use the current managed thread ID as a proxy.
- int id = GetCurrentProcessorNumber();
+ int id = CurrentProcessorNumber;
if (id < 0) id = Environment.CurrentManagedThreadId;
return id;
}
private static int ExecutionId
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- get { return GetCurrentProcessorNumber(); }
+ get { return CurrentProcessorNumber; }
}
}
}
// - Explore dumping stale buffers from the global queue, similar to PinnableBufferCache (maybe merging them).
// - Explore changing the size of each per-core bucket, potentially dynamically or based on other factors like array size.
// - Explore changing number of buckets and what sizes of arrays are cached.
- // - Measure making GetCurrentProcessorNumber an FCall rather than a P/Invoke.
// - Investigate whether false sharing is causing any issues, in particular on LockedStack's count and the contents of its array.
// ...
/// <summary>Gets the processor number associated with the current thread.</summary>
/// <remarks>Uses a cached value if one exists on the current thread.</remarks>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int GetCurrentProcessorNumber()
+ private static int CurrentProcessorNumber
{
- int? num = t_cachedProcessorNumber;
- if (!num.HasValue)
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ get
{
- t_cachedProcessorNumber = num = Win32Native.GetCurrentProcessorNumber();
+ int? num = t_cachedProcessorNumber;
+ if (!num.HasValue)
+ {
+ t_cachedProcessorNumber = num = Environment.CurrentProcessorNumber;
+ }
+ return num.GetValueOrDefault();
}
- return num.GetValueOrDefault();
}
public override T[] Rent(int minimumLength)
[DllImport(KERNEL32, SetLastError=true)]
internal static extern void GetSystemInfo(ref SYSTEM_INFO lpSystemInfo);
- [DllImport(KERNEL32)]
- internal static extern int GetCurrentProcessorNumber();
-
[DllImport(KERNEL32, CharSet=CharSet.Auto, BestFitMapping=true)]
internal static extern int FormatMessage(int dwFlags, IntPtr lpSource,
int dwMessageId, int dwLanguageId, [Out]StringBuilder lpBuffer,
}
}
+ internal static extern int CurrentProcessorNumber
+ {
+ [System.Security.SecuritySafeCritical]
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]
+ get;
+ }
}
}
FCFuncElement("GetResourceFromDefault", GetResourceFromDefault)
#endif // !FEATURE_CORECLR
FCFuncElement("GetCommandLineArgsNative", SystemNative::GetCommandLineArgs)
+ FCFuncElement("get_CurrentProcessorNumber", SystemNative::GetCurrentProcessorNumber)
#if defined(FEATURE_COMINTEROP) && !defined(FEATURE_CORESYSTEM)
QCFuncElement("WinRTSupported", SystemNative::WinRTSupported)