Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XPathMultyIterator.cs
- ApplicationSecurityInfo.cs
- OutOfProcStateClientManager.cs
- Publisher.cs
- TextBounds.cs
- EntityDataSourceReferenceGroup.cs
- FlowDocument.cs
- ChannelBinding.cs
- ContextItemManager.cs
- SqlDependency.cs
- LineBreak.cs
- cache.cs
- GACIdentityPermission.cs
- SdlChannelSink.cs
- ClientData.cs
- ValueQuery.cs
- Permission.cs
- SingleResultAttribute.cs
- DataServiceEntityAttribute.cs
- DrawingImage.cs
- DockAndAnchorLayout.cs
- GridViewColumn.cs
- FormsAuthentication.cs
- TypeDelegator.cs
- DataSet.cs
- OleDbStruct.cs
- DiscardableAttribute.cs
- ContainerParagraph.cs
- XmlNavigatorStack.cs
- Queue.cs
- SHA384.cs
- Keywords.cs
- RangeContentEnumerator.cs
- XslAstAnalyzer.cs
- FunctionDescription.cs
- OrderPreservingSpoolingTask.cs
- XmlTypeMapping.cs
- BehaviorEditorPart.cs
- ClientTargetSection.cs
- IRCollection.cs
- TypeLibConverter.cs
- SafeNativeMethods.cs
- QueryStringParameter.cs
- invalidudtexception.cs
- XamlToRtfWriter.cs
- XmlDeclaration.cs
- XmlSchemaProviderAttribute.cs
- FilterElement.cs
- Base64Encoder.cs
- DataGridBoolColumn.cs
- PageRanges.cs
- CodeIdentifier.cs
- MarkupCompilePass1.cs
- XmlHierarchyData.cs
- DbConnectionPoolIdentity.cs
- CommentAction.cs
- SoapReflectionImporter.cs
- VScrollBar.cs
- XmlSchemaObjectTable.cs
- StrongNamePublicKeyBlob.cs
- StandardCommands.cs
- ItemCollection.cs
- KernelTypeValidation.cs
- HostingEnvironment.cs
- smtppermission.cs
- EncryptedKey.cs
- SettingsAttributes.cs
- MetadataPropertyAttribute.cs
- _ListenerAsyncResult.cs
- ToolStripArrowRenderEventArgs.cs
- ListBox.cs
- RowTypePropertyElement.cs
- RuntimeComponentFilter.cs
- SystemDiagnosticsSection.cs
- Empty.cs
- OptimizerPatterns.cs
- SqlSupersetValidator.cs
- RequestNavigateEventArgs.cs
- _DigestClient.cs
- ValidatorAttribute.cs
- ValuePattern.cs
- PagesSection.cs
- XmlSchemaGroupRef.cs
- MessageEncoderFactory.cs
- ActivatedMessageQueue.cs
- Listbox.cs
- HttpModuleAction.cs
- HtmlWindow.cs
- SqlDataReader.cs
- _ChunkParse.cs
- DefaultTextStore.cs
- HtmlTernaryTree.cs
- RootDesignerSerializerAttribute.cs
- EventPropertyMap.cs
- ISAPIWorkerRequest.cs
- XPathScanner.cs
- MarkerProperties.cs
- APCustomTypeDescriptor.cs
- HashAlgorithm.cs
- StructuralCache.cs