Exemplo n.º 1
0
        private KernelResult SetThreadCoreMask(int handle, int preferredCore, long affinityMask)
        {
            KProcess currentProcess = _system.Scheduler.GetCurrentProcess();

            if (preferredCore == -2)
            {
                preferredCore = currentProcess.DefaultCpuCore;

                affinityMask = 1 << preferredCore;
            }
            else
            {
                if ((currentProcess.Capabilities.AllowedCpuCoresMask | affinityMask) !=
                    currentProcess.Capabilities.AllowedCpuCoresMask)
                {
                    return(KernelResult.InvalidCpuCore);
                }

                if (affinityMask == 0)
                {
                    return(KernelResult.InvalidCombination);
                }

                if ((uint)preferredCore > 3)
                {
                    if ((preferredCore | 2) != -1)
                    {
                        return(KernelResult.InvalidCpuCore);
                    }
                }
                else if ((affinityMask & (1 << preferredCore)) == 0)
                {
                    return(KernelResult.InvalidCombination);
                }
            }

            KThread thread = _process.HandleTable.GetKThread(handle);

            if (thread == null)
            {
                return(KernelResult.InvalidHandle);
            }

            return(thread.SetCoreAndAffinityMask(preferredCore, affinityMask));
        }