Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / xsp / System / Web / Util / SystemInfo.cs / 1 / 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; } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- _AutoWebProxyScriptHelper.cs
- TreeNodeCollection.cs
- UserNamePasswordValidationMode.cs
- TextSegment.cs
- AccessControlList.cs
- DoubleLink.cs
- PeerNameRecord.cs
- FormatException.cs
- Evaluator.cs
- TableRow.cs
- FormViewDeletedEventArgs.cs
- DataGridHelper.cs
- ParseElement.cs
- ObjectListTitleAttribute.cs
- ConfigurationLocation.cs
- HtmlElementErrorEventArgs.cs
- ForeignConstraint.cs
- Privilege.cs
- ProcessHost.cs
- ComplexBindingPropertiesAttribute.cs
- ParameterToken.cs
- VirtualPathData.cs
- BinaryParser.cs
- CodeCastExpression.cs
- DataKeyCollection.cs
- SingleResultAttribute.cs
- Typography.cs
- DataSourceHelper.cs
- WindowsGraphics.cs
- MarkedHighlightComponent.cs
- ParameterBuilder.cs
- DataGridViewCellFormattingEventArgs.cs
- ToolStripLabel.cs
- MissingMethodException.cs
- EncryptedType.cs
- DecimalStorage.cs
- CollectionViewGroup.cs
- HwndPanningFeedback.cs
- SqlClientMetaDataCollectionNames.cs
- WorkflowRuntimeServiceElementCollection.cs
- FacetChecker.cs
- DataGridRelationshipRow.cs
- TextEmbeddedObject.cs
- CDSsyncETWBCLProvider.cs
- EventArgs.cs
- AnnotationAdorner.cs
- SQLInt32.cs
- DataGridViewSelectedColumnCollection.cs
- ExtentCqlBlock.cs
- XmlILOptimizerVisitor.cs
- AnnotationResourceChangedEventArgs.cs
- SoapServerMessage.cs
- IndexerNameAttribute.cs
- __Error.cs
- ElementHostAutomationPeer.cs
- metadatamappinghashervisitor.cs
- ContentOperations.cs
- DbXmlEnabledProviderManifest.cs
- SwitchDesigner.xaml.cs
- ToolStripOverflowButton.cs
- XamlPoint3DCollectionSerializer.cs
- EventSinkActivity.cs
- InputBinder.cs
- ListControl.cs
- APCustomTypeDescriptor.cs
- XmlObjectSerializerContext.cs
- SHA256.cs
- Marshal.cs
- GeometryModel3D.cs
- StyleBamlTreeBuilder.cs
- Inflater.cs
- GridView.cs
- NavigationWindowAutomationPeer.cs
- BoundingRectTracker.cs
- GlobalItem.cs
- XmlNamespaceManager.cs
- EditBehavior.cs
- DbCommandTree.cs
- WebServiceParameterData.cs
- XmlNamedNodeMap.cs
- RegexBoyerMoore.cs
- StrongTypingException.cs
- BamlLocalizableResourceKey.cs
- XmlSecureResolver.cs
- Parameter.cs
- ComboBoxItem.cs
- EllipseGeometry.cs
- Attributes.cs
- SamlAuthorityBinding.cs
- UnknownWrapper.cs
- NativeMethodsOther.cs
- ExpressionBindingCollection.cs
- SQLBinaryStorage.cs
- FlowDocumentFormatter.cs
- QuadTree.cs
- XmlDataSourceNodeDescriptor.cs
- IisTraceWebEventProvider.cs
- ActivationServices.cs
- DataGridViewDesigner.cs
- SizeAnimationUsingKeyFrames.cs