Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / DEVDIV / depot / DevDiv / releases / whidbey / QFE / 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. //------------------------------------------------------------------------------ //// 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- LogLogRecord.cs
- FileDialog.cs
- GenericUriParser.cs
- DataSourceControl.cs
- GridViewCommandEventArgs.cs
- MSHTMLHost.cs
- WindowsListViewGroup.cs
- DeferrableContent.cs
- StrokeCollectionConverter.cs
- Cursors.cs
- ByteFacetDescriptionElement.cs
- SelectionRange.cs
- NativeMethods.cs
- DataRow.cs
- StorageConditionPropertyMapping.cs
- mda.cs
- JournalEntryStack.cs
- ObfuscationAttribute.cs
- ByteStorage.cs
- xmlglyphRunInfo.cs
- ExtensionDataReader.cs
- Atom10FormatterFactory.cs
- SynchronizedInputAdaptor.cs
- arabicshape.cs
- StrokeNodeOperations2.cs
- FastEncoderStatics.cs
- SubMenuStyleCollection.cs
- CharacterHit.cs
- WebPartConnectionsConfigureVerb.cs
- EmbeddedObject.cs
- XmlException.cs
- DNS.cs
- PingReply.cs
- XmlReaderDelegator.cs
- ToolStripOverflow.cs
- KeyTimeConverter.cs
- COM2FontConverter.cs
- EventHandlersStore.cs
- RegexCompilationInfo.cs
- DetailsViewUpdateEventArgs.cs
- TdsValueSetter.cs
- CookieHandler.cs
- IntPtr.cs
- AsyncResult.cs
- PreservationFileReader.cs
- SafeArchiveContext.cs
- NativeMethods.cs
- LinkDescriptor.cs
- QilTypeChecker.cs
- TitleStyle.cs
- ForwardPositionQuery.cs
- Empty.cs
- InputLanguageSource.cs
- UdpDiscoveryEndpointProvider.cs
- JoinGraph.cs
- SoapMessage.cs
- bidPrivateBase.cs
- TableLayoutStyleCollection.cs
- SelectionRange.cs
- SemanticResultValue.cs
- ActiveXContainer.cs
- SignatureGenerator.cs
- XmlQueryTypeFactory.cs
- ManagedWndProcTracker.cs
- FindCriteria.cs
- UserInitiatedNavigationPermission.cs
- ProfileSettingsCollection.cs
- DetailsViewRow.cs
- SplineQuaternionKeyFrame.cs
- TypeValidationEventArgs.cs
- ZipIOFileItemStream.cs
- SystemIPInterfaceProperties.cs
- TrimSurroundingWhitespaceAttribute.cs
- PositiveTimeSpanValidatorAttribute.cs
- FamilyCollection.cs
- DefaultTraceListener.cs
- UnsafeNativeMethods.cs
- PropertyManager.cs
- WebPartConnectVerb.cs
- ExternalFile.cs
- MimeXmlImporter.cs
- ShapeTypeface.cs
- XamlDesignerSerializationManager.cs
- PositiveTimeSpanValidator.cs
- ServiceDesigner.cs
- AssociationEndMember.cs
- SiteMapSection.cs
- IndicShape.cs
- OdbcConnection.cs
- SessionIDManager.cs
- ImageCodecInfoPrivate.cs
- SqlAliaser.cs
- DebugTracing.cs
- FullTextBreakpoint.cs
- SymbolPair.cs
- GridViewCancelEditEventArgs.cs
- IxmlLineInfo.cs
- ScriptResourceHandler.cs
- HandleDictionary.cs
- TrimSurroundingWhitespaceAttribute.cs