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
- TemplateControlParser.cs
- ReferenceList.cs
- CounterCreationDataConverter.cs
- ExpressionPrefixAttribute.cs
- SelfIssuedTokenFactoryCredential.cs
- graph.cs
- FrugalMap.cs
- HttpFormatExtensions.cs
- ServiceModelEnhancedConfigurationElementCollection.cs
- SignedInfo.cs
- ForeignKeyConstraint.cs
- BrowserDefinition.cs
- TransactedBatchContext.cs
- XmlNamespaceManager.cs
- ParagraphVisual.cs
- HostedHttpTransportManager.cs
- BuildManager.cs
- ActivityWithResultWrapper.cs
- AnimationStorage.cs
- SerializationEventsCache.cs
- DataServiceRequestOfT.cs
- CodeRemoveEventStatement.cs
- RegexNode.cs
- COM2ICategorizePropertiesHandler.cs
- StateChangeEvent.cs
- WindowsListViewSubItem.cs
- StorageComplexTypeMapping.cs
- UIAgentMonitorHandle.cs
- XmlTextEncoder.cs
- UIntPtr.cs
- XmlSchemaImport.cs
- Int64KeyFrameCollection.cs
- MD5CryptoServiceProvider.cs
- FileDataSourceCache.cs
- XmlTextReaderImpl.cs
- DataGridViewTextBoxEditingControl.cs
- Codec.cs
- BinarySecretSecurityToken.cs
- DataGridCell.cs
- ValueQuery.cs
- HtmlControlPersistable.cs
- ProtectedConfigurationProviderCollection.cs
- CorrelationTokenTypeConvertor.cs
- followingquery.cs
- ToolStripRenderEventArgs.cs
- PersonalizationState.cs
- StreamAsIStream.cs
- WebConfigurationFileMap.cs
- CollectionViewGroupRoot.cs
- CharUnicodeInfo.cs
- StrokeRenderer.cs
- MemberRelationshipService.cs
- HttpCachePolicy.cs
- SQLSingle.cs
- DataGridViewRowStateChangedEventArgs.cs
- HttpSysSettings.cs
- SplitterCancelEvent.cs
- TableRow.cs
- ContentType.cs
- XmlTextReaderImplHelpers.cs
- hresults.cs
- SerializerProvider.cs
- LogSwitch.cs
- ConnectionStringsSection.cs
- RegisteredArrayDeclaration.cs
- IODescriptionAttribute.cs
- SByte.cs
- DataView.cs
- XamlPointCollectionSerializer.cs
- DesignerTransactionCloseEvent.cs
- ListViewItem.cs
- DataGridCaption.cs
- RawTextInputReport.cs
- ImageInfo.cs
- FixedFindEngine.cs
- StandardToolWindows.cs
- RectAnimationBase.cs
- RenderTargetBitmap.cs
- CheckBox.cs
- NextPreviousPagerField.cs
- HttpListenerContext.cs
- SQLCharsStorage.cs
- DefaultObjectMappingItemCollection.cs
- HGlobalSafeHandle.cs
- AdvancedBindingEditor.cs
- WindowsComboBox.cs
- QuaternionAnimation.cs
- HierarchicalDataTemplate.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- ToolStripSystemRenderer.cs
- WmlCalendarAdapter.cs
- DiagnosticTraceSchemas.cs
- NameTable.cs
- TextDecorationLocationValidation.cs
- DefaultMergeHelper.cs
- RelatedView.cs
- MenuItemStyleCollection.cs
- PageHandlerFactory.cs
- CompositeFontInfo.cs
- SqlNodeTypeOperators.cs