Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / clr / src / BCL / System / Threading / Interlocked.cs / 1 / Interlocked.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== namespace System.Threading { using System; using System.Security.Permissions; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; // After much discussion, we decided the Interlocked class doesn't need // any HPA's for synchronization or external threading. They hurt C#'s // codegen for the yield keyword, and arguably they didn't protect much. // Instead, they penalized people (and compilers) for writing threadsafe // code. public static class Interlocked { /****************************** * Increment * Implemented: int * long *****************************/ [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern int Increment(ref int location); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern long Increment(ref long location); /****************************** * Decrement * Implemented: int * long *****************************/ [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern int Decrement(ref int location); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern long Decrement(ref long location); /****************************** * Exchange * Implemented: int * long * float * double * Object * IntPtr *****************************/ [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern int Exchange(ref int location1, int value); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern long Exchange(ref long location1, long value); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern float Exchange(ref float location1, float value); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern double Exchange(ref double location1, double value); [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern Object Exchange(ref Object location1, Object value); [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern IntPtr Exchange(ref IntPtr location1, IntPtr value); [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [System.Runtime.InteropServices.ComVisible(false)] public static T Exchange(ref T location1, T value) where T : class { _Exchange(__makeref(location1), __makeref(value)); //Since value is a local we use trash its data on return // The Exchange replaces the data with new data // so after the return "value" contains the original location1 //See ExchangeGeneric for more details return value; } [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] private static extern void _Exchange(TypedReference location1, TypedReference value); /****************************** * CompareExchange * Implemented: int * long * float * double * Object * IntPtr *****************************/ [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern int CompareExchange(ref int location1, int value, int comparand); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern long CompareExchange(ref long location1, long value, long comparand); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern float CompareExchange(ref float location1, float value, float comparand); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern double CompareExchange(ref double location1, double value, double comparand); [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern Object CompareExchange(ref Object location1, Object value, Object comparand); [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern IntPtr CompareExchange(ref IntPtr location1, IntPtr value, IntPtr comparand); [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [System.Runtime.InteropServices.ComVisible(false)] public static T CompareExchange (ref T location1, T value, T comparand) where T : class { _CompareExchange(__makeref(location1), __makeref(value), comparand); //Since value is a local we use trash its data on return // The Exchange replaces the data with new data // so after the return "value" contains the original location1 //See CompareExchangeGeneric for more details return value; } [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] private static extern void _CompareExchange(TypedReference location1, TypedReference value, Object comparand); /****************************** * Add * Implemented: int * long *****************************/ [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] internal static extern int ExchangeAdd(ref int location1, int value); [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern long ExchangeAdd(ref long location1, long value); [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static int Add(ref int location1, int value) { return ExchangeAdd(ref location1, value) + value; } [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static long Add(ref long location1, long value) { return ExchangeAdd(ref location1, value) + value; } /****************************** * Read *****************************/ public static long Read(ref long location) { return Interlocked.CompareExchange(ref location,0,0); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== namespace System.Threading { using System; using System.Security.Permissions; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; // After much discussion, we decided the Interlocked class doesn't need // any HPA's for synchronization or external threading. They hurt C#'s // codegen for the yield keyword, and arguably they didn't protect much. // Instead, they penalized people (and compilers) for writing threadsafe // code. public static class Interlocked { /****************************** * Increment * Implemented: int * long *****************************/ [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern int Increment(ref int location); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern long Increment(ref long location); /****************************** * Decrement * Implemented: int * long *****************************/ [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern int Decrement(ref int location); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern long Decrement(ref long location); /****************************** * Exchange * Implemented: int * long * float * double * Object * IntPtr *****************************/ [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern int Exchange(ref int location1, int value); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern long Exchange(ref long location1, long value); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern float Exchange(ref float location1, float value); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern double Exchange(ref double location1, double value); [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern Object Exchange(ref Object location1, Object value); [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern IntPtr Exchange(ref IntPtr location1, IntPtr value); [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [System.Runtime.InteropServices.ComVisible(false)] public static T Exchange (ref T location1, T value) where T : class { _Exchange(__makeref(location1), __makeref(value)); //Since value is a local we use trash its data on return // The Exchange replaces the data with new data // so after the return "value" contains the original location1 //See ExchangeGeneric for more details return value; } [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] private static extern void _Exchange(TypedReference location1, TypedReference value); /****************************** * CompareExchange * Implemented: int * long * float * double * Object * IntPtr *****************************/ [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern int CompareExchange(ref int location1, int value, int comparand); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern long CompareExchange(ref long location1, long value, long comparand); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern float CompareExchange(ref float location1, float value, float comparand); [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern double CompareExchange(ref double location1, double value, double comparand); [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern Object CompareExchange(ref Object location1, Object value, Object comparand); [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern IntPtr CompareExchange(ref IntPtr location1, IntPtr value, IntPtr comparand); [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [System.Runtime.InteropServices.ComVisible(false)] public static T CompareExchange (ref T location1, T value, T comparand) where T : class { _CompareExchange(__makeref(location1), __makeref(value), comparand); //Since value is a local we use trash its data on return // The Exchange replaces the data with new data // so after the return "value" contains the original location1 //See CompareExchangeGeneric for more details return value; } [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] private static extern void _CompareExchange(TypedReference location1, TypedReference value, Object comparand); /****************************** * Add * Implemented: int * long *****************************/ [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] internal static extern int ExchangeAdd(ref int location1, int value); [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern long ExchangeAdd(ref long location1, long value); [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static int Add(ref int location1, int value) { return ExchangeAdd(ref location1, value) + value; } [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static long Add(ref long location1, long value) { return ExchangeAdd(ref location1, value) + value; } /****************************** * Read *****************************/ public static long Read(ref long location) { return Interlocked.CompareExchange(ref location,0,0); } } } // 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
- RemoteAsymmetricSignatureFormatter.cs
- control.ime.cs
- RequestDescription.cs
- Material.cs
- InfoCardX509Validator.cs
- SerializableAttribute.cs
- xsdvalidator.cs
- KeyboardDevice.cs
- ObjectStateFormatter.cs
- WebPartCatalogCloseVerb.cs
- NeutralResourcesLanguageAttribute.cs
- AspCompat.cs
- DispatcherExceptionEventArgs.cs
- AddInStore.cs
- QuotedStringWriteStateInfo.cs
- ContentFilePart.cs
- EdmType.cs
- CanonicalFormWriter.cs
- TreeIterators.cs
- TraceContextRecord.cs
- RowParagraph.cs
- NavigationProgressEventArgs.cs
- ReachSerializer.cs
- GridViewUpdatedEventArgs.cs
- CqlLexer.cs
- RtfFormatStack.cs
- SetterBaseCollection.cs
- SimpleTextLine.cs
- basevalidator.cs
- SafeCryptContextHandle.cs
- Scheduling.cs
- CriticalFinalizerObject.cs
- PeerPresenceInfo.cs
- X509ChainElement.cs
- DetailsViewUpdatedEventArgs.cs
- WebBrowser.cs
- ChangeDirector.cs
- DocumentPageHost.cs
- VideoDrawing.cs
- TextEditor.cs
- NameGenerator.cs
- FixedSOMSemanticBox.cs
- RightsDocument.cs
- Bezier.cs
- HGlobalSafeHandle.cs
- AsnEncodedData.cs
- OracleTimeSpan.cs
- SafeEventLogWriteHandle.cs
- MatcherBuilder.cs
- WebPartDescriptionCollection.cs
- LookupNode.cs
- DependencyPropertyDescriptor.cs
- ToolboxItemAttribute.cs
- WorkflowHostingEndpoint.cs
- DesignerActionPanel.cs
- DbModificationCommandTree.cs
- WebPartTransformerCollection.cs
- _LocalDataStore.cs
- OdbcStatementHandle.cs
- HTTPNotFoundHandler.cs
- ParseChildrenAsPropertiesAttribute.cs
- InternalConfigRoot.cs
- XmlValueConverter.cs
- EdgeModeValidation.cs
- Win32PrintDialog.cs
- FlowDocumentReaderAutomationPeer.cs
- ImageCodecInfoPrivate.cs
- GraphicsContainer.cs
- StorageEntityContainerMapping.cs
- QueryCacheManager.cs
- ZoneLinkButton.cs
- Schema.cs
- RecognizedAudio.cs
- DiagnosticsElement.cs
- Brushes.cs
- IPEndPoint.cs
- MetadataHelper.cs
- WsatServiceAddress.cs
- _KerberosClient.cs
- TypeContext.cs
- SmtpTransport.cs
- XPathDocumentNavigator.cs
- List.cs
- ProfessionalColorTable.cs
- GeometryDrawing.cs
- ChildTable.cs
- ProfileModule.cs
- NavigationExpr.cs
- FileDialogCustomPlaces.cs
- IndicShape.cs
- XmlTypeAttribute.cs
- DbDeleteCommandTree.cs
- WithStatement.cs
- NativeActivityMetadata.cs
- WebZone.cs
- EntityDataSourceChangingEventArgs.cs
- ClientCultureInfo.cs
- SecurityTokenTypes.cs
- ArrangedElement.cs
- HwndHost.cs