Code:
/ FX-1434 / FX-1434 / 1.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
- DataServiceEntityAttribute.cs
- Utils.cs
- _SingleItemRequestCache.cs
- CheckBox.cs
- ActivityTypeCodeDomSerializer.cs
- ControlBuilderAttribute.cs
- ClientBuildManagerCallback.cs
- SchemaSetCompiler.cs
- TransformerInfo.cs
- SqlIdentifier.cs
- TableSectionStyle.cs
- GeneratedView.cs
- CompareInfo.cs
- DesignerDeviceConfig.cs
- FixedPageAutomationPeer.cs
- DetailsViewModeEventArgs.cs
- OleTxTransaction.cs
- TextServicesManager.cs
- LogStream.cs
- DataServiceProcessingPipeline.cs
- ScopelessEnumAttribute.cs
- ValueProviderWrapper.cs
- Pair.cs
- ExpressionEvaluator.cs
- CurrentChangingEventManager.cs
- DataGridViewElement.cs
- ProgressBarRenderer.cs
- KnownBoxes.cs
- UrlPath.cs
- RuntimeArgumentHandle.cs
- WebHttpBindingElement.cs
- UriSection.cs
- SocketStream.cs
- EntityDataSourceWizardForm.cs
- UpdatePanelTrigger.cs
- ClientReliableChannelBinder.cs
- RightsManagementInformation.cs
- DeadCharTextComposition.cs
- RelationshipConstraintValidator.cs
- DocumentStatusResources.cs
- DmlSqlGenerator.cs
- Point3D.cs
- EventData.cs
- XmlILAnnotation.cs
- ContentOperations.cs
- ValidatingPropertiesEventArgs.cs
- SortedDictionary.cs
- TextElementEnumerator.cs
- DataGrid.cs
- ObjectListFieldCollection.cs
- NameValuePermission.cs
- DataServiceConfiguration.cs
- MediaElement.cs
- MsmqHostedTransportManager.cs
- Preprocessor.cs
- InvalidCastException.cs
- QueryExpr.cs
- SmiContextFactory.cs
- BoundConstants.cs
- ResourceDictionaryCollection.cs
- AnchoredBlock.cs
- PathTooLongException.cs
- NumberFunctions.cs
- ToolStripDropDownItemDesigner.cs
- XmlSchemaAttributeGroup.cs
- MULTI_QI.cs
- OperatingSystem.cs
- MimeObjectFactory.cs
- PaintValueEventArgs.cs
- DropShadowEffect.cs
- NumericExpr.cs
- CodeDOMProvider.cs
- QEncodedStream.cs
- ILGenerator.cs
- TrackingMemoryStreamFactory.cs
- ReverseInheritProperty.cs
- ClientTargetSection.cs
- JsonClassDataContract.cs
- TypedDataSourceCodeGenerator.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- PropertyGroupDescription.cs
- WebHttpDispatchOperationSelector.cs
- Rotation3DKeyFrameCollection.cs
- DeviceOverridableAttribute.cs
- XmlNodeComparer.cs
- MethodBuilder.cs
- BitmapEffectInput.cs
- FaultDescription.cs
- SingleStorage.cs
- AggregateNode.cs
- FixedSOMContainer.cs
- CalendarKeyboardHelper.cs
- SimpleExpression.cs
- ReflectEventDescriptor.cs
- HttpResponseMessageProperty.cs
- UnSafeCharBuffer.cs
- SolidColorBrush.cs
- IdentityValidationException.cs
- KeyGestureConverter.cs
- Operator.cs