Changed a few types to internal (instead of public) in the Open Hardware Monitor library.
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 Copyright (C) 2010 Michael Möller <mmoeller@openhardwaremonitor.org>
12 using System.Runtime.InteropServices;
14 namespace OpenHardwareMonitor.Hardware {
16 internal static class ThreadAffinity {
18 public static ulong Set(ulong mask) {
22 int p = (int)Environment.OSVersion.Platform;
23 if ((p == 4) || (p == 128)) { // Unix
25 if (NativeMethods.sched_getaffinity(0, (IntPtr)Marshal.SizeOf(result),
28 if (NativeMethods.sched_setaffinity(0, (IntPtr)Marshal.SizeOf(mask),
33 return (ulong)NativeMethods.SetThreadAffinityMask(
34 NativeMethods.GetCurrentThread(), (UIntPtr)mask);
38 private static class NativeMethods {
39 private const string KERNEL = "kernel32.dll";
41 [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
42 public static extern UIntPtr
43 SetThreadAffinityMask(IntPtr handle, UIntPtr mask);
45 [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
46 public static extern IntPtr GetCurrentThread();
48 private const string LIBC = "libc";
51 public static extern int sched_getaffinity(int pid, IntPtr maskSize,
55 public static extern int sched_setaffinity(int pid, IntPtr maskSize,