Now displaying sensor node background in green if FrontView enabled.
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-2014 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),
35 uIntPtrMask = (UIntPtr)mask;
36 } catch (OverflowException) {
37 throw new ArgumentOutOfRangeException("mask");
39 return (ulong)NativeMethods.SetThreadAffinityMask(
40 NativeMethods.GetCurrentThread(), uIntPtrMask);
44 private static class NativeMethods {
45 private const string KERNEL = "kernel32.dll";
47 [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
48 public static extern UIntPtr
49 SetThreadAffinityMask(IntPtr handle, UIntPtr mask);
51 [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
52 public static extern IntPtr GetCurrentThread();
54 private const string LIBC = "libc";
57 public static extern int sched_getaffinity(int pid, IntPtr maskSize,
61 public static extern int sched_setaffinity(int pid, IntPtr maskSize,