Exemple #1
0
            private void InitializeProcessThreads()
            {
                var unmanagedThreadId = PlatformDetails.GetCurrentThreadId();

                _currentProcess = Process.GetCurrentProcess();
                foreach (ProcessThread pt in _currentProcess.Threads)
                {
                    if (pt.Id == unmanagedThreadId)
                    {
                        _currentProcessThread = pt;
                        break;
                    }
                }
                if (_currentProcessThread == null)
                {
                    throw new InvalidOperationException("Unable to get the current process thread: " + unmanagedThreadId + ", this should not be possible");
                }
            }
Exemple #2
0
            private void InitializeProcessThreads()
            {
                if (PlatformDetails.RunningOnMacOsx)
                {
                    // Mac OSX threads API doesn't provide a way to set thread affinity
                    // we can use thread_policy_set which will make sure that two threads will run
                    // on different cpus, however we cannot choose which cpus will be used

                    // from thread_policy.h about using THREAD_AFFINITY_POLICY:
                    // This may be used to express affinity relationships between threads in
                    // the task. Threads with the same affinity tag will be scheduled to
                    // share an L2 cache if possible. That is, affinity tags are a hint to
                    // the scheduler for thread placement.

                    return;
                }

                _currentUnmanagedThreadId = PlatformDetails.GetCurrentThreadId();
                _currentProcess           = Process.GetCurrentProcess();

                if (PlatformDetails.RunningOnLinux)
                {
                    // we set the thread affinity by the unmanaged thread id
                    SetLinuxThreadAffinity(_currentProcess.ProcessorAffinity.ToInt64());
                    return;
                }

                foreach (ProcessThread pt in _currentProcess.Threads)
                {
                    if (pt.Id == (uint)_currentUnmanagedThreadId)
                    {
                        _currentProcessThread = pt;
                        break;
                    }
                }

                if (_currentProcessThread == null)
                {
                    throw new InvalidOperationException("Unable to get the current process thread: " + _currentUnmanagedThreadId + ", this should not be possible");
                }
            }
Exemple #3
0
 public ThreadStats()
 {
     _threadInstance = Thread.CurrentThread;
     Id = _threadInstance.ManagedThreadId;
     UnmanagedThreadId = PlatformDetails.GetCurrentThreadId();
 }