Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Util / SystemInfo.cs / 1305376 / SystemInfo.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Util { internal static class SystemInfo { static int _trueNumberOfProcessors; static internal int GetNumProcessCPUs() { if (_trueNumberOfProcessors == 0) { UnsafeNativeMethods.SYSTEM_INFO si; UnsafeNativeMethods.GetSystemInfo(out si); if (si.dwNumberOfProcessors == 1) { _trueNumberOfProcessors = 1; } else { // KERNEL32.DLL:GetCurrentProcess() always returns -1 under NT // Note: not really a handle (no need to CloseHandle()) IntPtr processHandle = UnsafeNativeMethods.INVALID_HANDLE_VALUE; IntPtr processAffinityMask; IntPtr systemAffinityMask; int returnCode = UnsafeNativeMethods.GetProcessAffinityMask( processHandle, out processAffinityMask, out systemAffinityMask); if (returnCode == 0) { _trueNumberOfProcessors = 1; } else { // if cpu affinity is set to a single processor busy waiting is a waste of time int numProcessors = 0; if (IntPtr.Size == 4) { uint mask = (uint) processAffinityMask; for (; mask != 0; mask >>= 1) { if ((mask & 1) == 1) { ++numProcessors; } } } else { ulong mask = (ulong) processAffinityMask; for (; mask != 0; mask >>= 1) { if ((mask & 1) == 1) { ++numProcessors; } } } _trueNumberOfProcessors = numProcessors; } } } Debug.Assert(_trueNumberOfProcessors > 0); return _trueNumberOfProcessors; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Util { internal static class SystemInfo { static int _trueNumberOfProcessors; static internal int GetNumProcessCPUs() { if (_trueNumberOfProcessors == 0) { UnsafeNativeMethods.SYSTEM_INFO si; UnsafeNativeMethods.GetSystemInfo(out si); if (si.dwNumberOfProcessors == 1) { _trueNumberOfProcessors = 1; } else { // KERNEL32.DLL:GetCurrentProcess() always returns -1 under NT // Note: not really a handle (no need to CloseHandle()) IntPtr processHandle = UnsafeNativeMethods.INVALID_HANDLE_VALUE; IntPtr processAffinityMask; IntPtr systemAffinityMask; int returnCode = UnsafeNativeMethods.GetProcessAffinityMask( processHandle, out processAffinityMask, out systemAffinityMask); if (returnCode == 0) { _trueNumberOfProcessors = 1; } else { // if cpu affinity is set to a single processor busy waiting is a waste of time int numProcessors = 0; if (IntPtr.Size == 4) { uint mask = (uint) processAffinityMask; for (; mask != 0; mask >>= 1) { if ((mask & 1) == 1) { ++numProcessors; } } } else { ulong mask = (ulong) processAffinityMask; for (; mask != 0; mask >>= 1) { if ((mask & 1) == 1) { ++numProcessors; } } } _trueNumberOfProcessors = numProcessors; } } } Debug.Assert(_trueNumberOfProcessors > 0); return _trueNumberOfProcessors; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TrustManagerPromptUI.cs
- InvokeProviderWrapper.cs
- XPathNodeInfoAtom.cs
- InputLangChangeEvent.cs
- GPPOINT.cs
- XmlFormatExtensionPrefixAttribute.cs
- FilePrompt.cs
- UpDownBase.cs
- Win32.cs
- FontStyleConverter.cs
- DownloadProgressEventArgs.cs
- RedirectionProxy.cs
- XmlNamespaceDeclarationsAttribute.cs
- COAUTHIDENTITY.cs
- FileDataSourceCache.cs
- OptimalTextSource.cs
- ChangeConflicts.cs
- GridViewUpdateEventArgs.cs
- ZoneLinkButton.cs
- TypeConverterHelper.cs
- ImageConverter.cs
- WebControlsSection.cs
- SqlConnectionHelper.cs
- OpenFileDialog.cs
- DragDrop.cs
- MaterialCollection.cs
- DoubleConverter.cs
- XmlName.cs
- FastEncoderWindow.cs
- Constants.cs
- ObjectListField.cs
- CategoryEditor.cs
- MarkerProperties.cs
- XPathSelfQuery.cs
- OperandQuery.cs
- SequenceDesignerAccessibleObject.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- HashCodeCombiner.cs
- FormatException.cs
- FixedSOMElement.cs
- ContentPresenter.cs
- InvalidFilterCriteriaException.cs
- ListViewInsertedEventArgs.cs
- PropertyGeneratedEventArgs.cs
- EpmCustomContentDeSerializer.cs
- QilSortKey.cs
- CustomPopupPlacement.cs
- NamespaceQuery.cs
- SequenceQuery.cs
- SparseMemoryStream.cs
- RegexCapture.cs
- XPathSingletonIterator.cs
- PermissionSet.cs
- ConfigurationStrings.cs
- CodeSubDirectory.cs
- OdbcHandle.cs
- DataControlLinkButton.cs
- AutomationPatternInfo.cs
- Stroke2.cs
- ZoneLinkButton.cs
- UrlMapping.cs
- ThrowHelper.cs
- NavigationExpr.cs
- sqlstateclientmanager.cs
- DateTimeConstantAttribute.cs
- XPathScanner.cs
- DataGridViewRowsRemovedEventArgs.cs
- QuaternionConverter.cs
- HtmlTextViewAdapter.cs
- TemplatedEditableDesignerRegion.cs
- _AutoWebProxyScriptHelper.cs
- WorkflowTransactionOptions.cs
- UTF7Encoding.cs
- SolidColorBrush.cs
- TypefaceMap.cs
- UnicodeEncoding.cs
- BitmapMetadataBlob.cs
- ExceptionHandlers.cs
- ExpressionPrefixAttribute.cs
- RangeBaseAutomationPeer.cs
- DataSourceCache.cs
- ProfilePropertySettings.cs
- InputLangChangeEvent.cs
- RawKeyboardInputReport.cs
- AuthenticateEventArgs.cs
- DynamicDiscoveryDocument.cs
- SelectionEditingBehavior.cs
- RadioButtonAutomationPeer.cs
- ServerIdentity.cs
- _HeaderInfo.cs
- DelegatingHeader.cs
- ResXDataNode.cs
- ThreadNeutralSemaphore.cs
- RuleSetDialog.Designer.cs
- ProxyAttribute.cs
- TabPageDesigner.cs
- StorageBasedPackageProperties.cs
- MessageBox.cs
- SecurityTokenException.cs
- GeneralTransform.cs