Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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; } } } // 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
- XmlSchemaRedefine.cs
- TextTreeUndo.cs
- TemplateBuilder.cs
- Helpers.cs
- CompositeActivityCodeGenerator.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- Span.cs
- FixedElement.cs
- XPathSelectionIterator.cs
- SmiRequestExecutor.cs
- HScrollProperties.cs
- InitiatorSessionSymmetricTransportSecurityProtocol.cs
- ModelEditingScope.cs
- XmlSchemaObjectTable.cs
- Triplet.cs
- DispatcherObject.cs
- ElementAction.cs
- SuppressIldasmAttribute.cs
- XmlWrappingReader.cs
- RectangleGeometry.cs
- BitmapCacheBrush.cs
- MiniModule.cs
- BidOverLoads.cs
- CodeCastExpression.cs
- StreamWithDictionary.cs
- KeyInterop.cs
- TraceHandler.cs
- ExpressionBinding.cs
- MetadataItemSerializer.cs
- PartialCachingAttribute.cs
- Misc.cs
- Timer.cs
- LoginUtil.cs
- QuotedPairReader.cs
- ClientApiGenerator.cs
- _CookieModule.cs
- MbpInfo.cs
- ReturnValue.cs
- ReliableSessionElement.cs
- ColumnMapTranslator.cs
- SafeFileMapViewHandle.cs
- EncodingTable.cs
- RealProxy.cs
- ThaiBuddhistCalendar.cs
- CodeLinePragma.cs
- HttpDebugHandler.cs
- DayRenderEvent.cs
- LocalizationComments.cs
- ButtonBaseAutomationPeer.cs
- NullableLongAverageAggregationOperator.cs
- DnsPermission.cs
- UpdateInfo.cs
- XmlDesigner.cs
- ListItem.cs
- WebBrowserPermission.cs
- BitmapEffectGroup.cs
- Identity.cs
- DescendentsWalker.cs
- unitconverter.cs
- TypeReference.cs
- NumericUpDownAcceleration.cs
- FixedSOMTableRow.cs
- Rotation3D.cs
- ErrorWebPart.cs
- DesignTimeTemplateParser.cs
- ManagedFilter.cs
- DataAdapter.cs
- TextContainer.cs
- CollectionBuilder.cs
- SeparatorAutomationPeer.cs
- DataGrid.cs
- Mapping.cs
- PriorityBindingExpression.cs
- _NegoStream.cs
- FieldTemplateUserControl.cs
- ObjectDataSourceChooseMethodsPanel.cs
- ImportContext.cs
- DrawingGroup.cs
- DataGridViewAdvancedBorderStyle.cs
- TreeView.cs
- HttpHandlerAction.cs
- DesignTimeHTMLTextWriter.cs
- XmlElement.cs
- ChannelEndpointElement.cs
- TypefaceMap.cs
- MailWebEventProvider.cs
- FileClassifier.cs
- SocketCache.cs
- PropertyItem.cs
- PropertyPath.cs
- IntegerFacetDescriptionElement.cs
- Header.cs
- VectorCollectionValueSerializer.cs
- XmlIncludeAttribute.cs
- SectionXmlInfo.cs
- Win32Interop.cs
- FormatConvertedBitmap.cs
- CodeTypeDelegate.cs
- CodeIdentifier.cs
- SchemaTableColumn.cs