From c85c19baef5edf867c3a9a217cbe235a892d0c1e Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Tue, 11 Apr 2017 17:44:40 -0700 Subject: [PATCH] Move files to shared CoreLib partition (#10885) --- src/mscorlib/System.Private.CoreLib.csproj | 26 --- .../shared/System.Private.CoreLib.Shared.projitems | 30 ++++ .../Serialization/IDeserializationCallback.cs | 11 ++ .../Serialization/OnDeserializedAttribute.cs | 11 ++ .../Serialization/OnDeserializingAttribute.cs | 11 ++ .../Runtime/Serialization/OnSerializedAttribute.cs | 11 ++ .../Serialization/OnSerializingAttribute.cs | 11 ++ .../Serialization/OptionalFieldAttribute.cs | 25 +++ .../Serialization/SerializationException.cs | 22 +-- .../Serialization/SerializationInfoEnumerator.cs | 127 +++++++++++++++ .../Runtime/Serialization/StreamingContext.cs | 53 +++++++ .../Runtime/Versioning/NonVersionableAttribute.cs | 0 .../System/Threading/AbandonedMutexException.cs | 39 ++--- .../System/Threading/ApartmentState.cs | 11 -- .../{src => shared}/System/Threading/AsyncLocal.cs | 3 - .../System/Threading/AutoResetEvent.cs | 13 -- .../System/Threading/EventResetMode.cs | 5 - .../System/Threading/ExecutionContext.cs | 27 +--- .../System/Threading/LazyThreadSafetyMode.cs | 44 ++++++ .../System/Threading/LockRecursionException.cs | 28 ++-- .../System/Threading/ManualResetEvent.cs | 13 -- .../System/Threading/ParameterizedThreadStart.cs | 6 - .../System/Threading/SemaphoreFullException.cs | 3 - .../System/Threading/SendOrPostCallback.cs | 8 - .../Threading/SynchronizationLockException.cs | 5 - .../System/Threading/ThreadPriority.cs | 13 -- .../System/Threading/ThreadStart.cs | 6 - .../System/Threading/ThreadStartException.cs | 11 +- .../System/Threading/ThreadState.cs | 11 -- .../System/Threading/ThreadStateException.cs | 5 +- .../shared/System/Threading/TimeoutHelper.cs | 54 +++++++ .../Threading/WaitHandleCannotBeOpenedException.cs | 7 - .../Serialization/IDeserializationCallback.cs | 25 --- .../Serialization/SerializationAttributes.cs | 61 ------- .../Serialization/SerializationInfoEnumerator.cs | 176 --------------------- .../Runtime/Serialization/StreamingContext.cs | 84 ---------- .../src/System/Threading/LazyInitializer.cs | 31 ---- src/mscorlib/src/System/Threading/SpinWait.cs | 48 +----- 38 files changed, 432 insertions(+), 643 deletions(-) create mode 100644 src/mscorlib/shared/System/Runtime/Serialization/IDeserializationCallback.cs create mode 100644 src/mscorlib/shared/System/Runtime/Serialization/OnDeserializedAttribute.cs create mode 100644 src/mscorlib/shared/System/Runtime/Serialization/OnDeserializingAttribute.cs create mode 100644 src/mscorlib/shared/System/Runtime/Serialization/OnSerializedAttribute.cs create mode 100644 src/mscorlib/shared/System/Runtime/Serialization/OnSerializingAttribute.cs create mode 100644 src/mscorlib/shared/System/Runtime/Serialization/OptionalFieldAttribute.cs rename src/mscorlib/{src => shared}/System/Runtime/Serialization/SerializationException.cs (66%) create mode 100644 src/mscorlib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs create mode 100644 src/mscorlib/shared/System/Runtime/Serialization/StreamingContext.cs rename src/mscorlib/{src => shared}/System/Runtime/Versioning/NonVersionableAttribute.cs (100%) rename src/mscorlib/{src => shared}/System/Threading/AbandonedMutexException.cs (81%) rename src/mscorlib/{src => shared}/System/Threading/ApartmentState.cs (67%) rename src/mscorlib/{src => shared}/System/Threading/AsyncLocal.cs (99%) rename src/mscorlib/{src => shared}/System/Threading/AutoResetEvent.cs (59%) rename src/mscorlib/{src => shared}/System/Threading/EventResetMode.cs (88%) rename src/mscorlib/{src => shared}/System/Threading/ExecutionContext.cs (96%) create mode 100644 src/mscorlib/shared/System/Threading/LazyThreadSafetyMode.cs rename src/mscorlib/{src => shared}/System/Threading/LockRecursionException.cs (52%) rename src/mscorlib/{src => shared}/System/Threading/ManualResetEvent.cs (59%) rename src/mscorlib/{src => shared}/System/Threading/ParameterizedThreadStart.cs (85%) rename src/mscorlib/{src => shared}/System/Threading/SemaphoreFullException.cs (92%) rename src/mscorlib/{src => shared}/System/Threading/SendOrPostCallback.cs (53%) rename src/mscorlib/{src => shared}/System/Threading/SynchronizationLockException.cs (98%) rename src/mscorlib/{src => shared}/System/Threading/ThreadPriority.cs (68%) rename src/mscorlib/{src => shared}/System/Threading/ThreadStart.cs (76%) rename src/mscorlib/{src => shared}/System/Threading/ThreadStartException.cs (80%) rename src/mscorlib/{src => shared}/System/Threading/ThreadState.cs (74%) rename src/mscorlib/{src => shared}/System/Threading/ThreadStateException.cs (95%) create mode 100644 src/mscorlib/shared/System/Threading/TimeoutHelper.cs rename src/mscorlib/{src => shared}/System/Threading/WaitHandleCannotBeOpenedException.cs (92%) delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/IDeserializationCallback.cs delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/SerializationAttributes.cs delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/SerializationInfoEnumerator.cs delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/StreamingContext.cs diff --git a/src/mscorlib/System.Private.CoreLib.csproj b/src/mscorlib/System.Private.CoreLib.csproj index 14f0c7b..3a0917f 100644 --- a/src/mscorlib/System.Private.CoreLib.csproj +++ b/src/mscorlib/System.Private.CoreLib.csproj @@ -493,37 +493,19 @@ - - - - - - - - - - - - - - - - - - @@ -617,15 +599,7 @@ - - - - - - - - diff --git a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems index a481ef4..6ef7fc1 100644 --- a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems @@ -307,11 +307,21 @@ + + + + + + + + + + @@ -345,12 +355,32 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/mscorlib/shared/System/Runtime/Serialization/IDeserializationCallback.cs b/src/mscorlib/shared/System/Runtime/Serialization/IDeserializationCallback.cs new file mode 100644 index 0000000..a1c1671 --- /dev/null +++ b/src/mscorlib/shared/System/Runtime/Serialization/IDeserializationCallback.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Runtime.Serialization +{ + public interface IDeserializationCallback + { + void OnDeserialization(object sender); + } +} diff --git a/src/mscorlib/shared/System/Runtime/Serialization/OnDeserializedAttribute.cs b/src/mscorlib/shared/System/Runtime/Serialization/OnDeserializedAttribute.cs new file mode 100644 index 0000000..408a55c --- /dev/null +++ b/src/mscorlib/shared/System/Runtime/Serialization/OnDeserializedAttribute.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Runtime.Serialization +{ + [AttributeUsage(AttributeTargets.Method, Inherited = false)] + public sealed class OnDeserializedAttribute : Attribute + { + } +} diff --git a/src/mscorlib/shared/System/Runtime/Serialization/OnDeserializingAttribute.cs b/src/mscorlib/shared/System/Runtime/Serialization/OnDeserializingAttribute.cs new file mode 100644 index 0000000..162857e --- /dev/null +++ b/src/mscorlib/shared/System/Runtime/Serialization/OnDeserializingAttribute.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Runtime.Serialization +{ + [AttributeUsage(AttributeTargets.Method, Inherited = false)] + public sealed class OnDeserializingAttribute : Attribute + { + } +} diff --git a/src/mscorlib/shared/System/Runtime/Serialization/OnSerializedAttribute.cs b/src/mscorlib/shared/System/Runtime/Serialization/OnSerializedAttribute.cs new file mode 100644 index 0000000..020dd02 --- /dev/null +++ b/src/mscorlib/shared/System/Runtime/Serialization/OnSerializedAttribute.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Runtime.Serialization +{ + [AttributeUsage(AttributeTargets.Method, Inherited = false)] + public sealed class OnSerializedAttribute : Attribute + { + } +} diff --git a/src/mscorlib/shared/System/Runtime/Serialization/OnSerializingAttribute.cs b/src/mscorlib/shared/System/Runtime/Serialization/OnSerializingAttribute.cs new file mode 100644 index 0000000..8dc8af3 --- /dev/null +++ b/src/mscorlib/shared/System/Runtime/Serialization/OnSerializingAttribute.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Runtime.Serialization +{ + [AttributeUsage(AttributeTargets.Method, Inherited = false)] + public sealed class OnSerializingAttribute : Attribute + { + } +} diff --git a/src/mscorlib/shared/System/Runtime/Serialization/OptionalFieldAttribute.cs b/src/mscorlib/shared/System/Runtime/Serialization/OptionalFieldAttribute.cs new file mode 100644 index 0000000..84daa53 --- /dev/null +++ b/src/mscorlib/shared/System/Runtime/Serialization/OptionalFieldAttribute.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Runtime.Serialization +{ + [AttributeUsage(AttributeTargets.Field, Inherited = false)] + public sealed class OptionalFieldAttribute : Attribute + { + private int _versionAdded = 1; + + public int VersionAdded + { + get { return _versionAdded; } + set + { + if (value < 1) + { + throw new ArgumentException(SR.Serialization_OptionalFieldVersionValue); + } + _versionAdded = value; + } + } + } +} diff --git a/src/mscorlib/src/System/Runtime/Serialization/SerializationException.cs b/src/mscorlib/shared/System/Runtime/Serialization/SerializationException.cs similarity index 66% rename from src/mscorlib/src/System/Runtime/Serialization/SerializationException.cs rename to src/mscorlib/shared/System/Runtime/Serialization/SerializationException.cs index 48de8a7..83cf2c6 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/SerializationException.cs +++ b/src/mscorlib/shared/System/Runtime/Serialization/SerializationException.cs @@ -2,18 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -/*============================================================================= -** -** -** -** Purpose: Thrown when something goes wrong during serialization or -** deserialization. -** -** -=============================================================================*/ - - -using System; using System.Runtime.Serialization; namespace System.Runtime.Serialization @@ -21,12 +9,12 @@ namespace System.Runtime.Serialization [Serializable] public class SerializationException : SystemException { - private static String _nullMessage = SR.Arg_SerializationException; + private static String s_nullMessage = SR.Arg_SerializationException; // Creates a new SerializationException with its message // string set to a default message. public SerializationException() - : base(_nullMessage) + : base(s_nullMessage) { HResult = __HResults.COR_E_SERIALIZATION; } @@ -37,12 +25,14 @@ namespace System.Runtime.Serialization HResult = __HResults.COR_E_SERIALIZATION; } - public SerializationException(String message, Exception innerException) : base(message, innerException) + public SerializationException(String message, Exception innerException) + : base(message, innerException) { HResult = __HResults.COR_E_SERIALIZATION; } - protected SerializationException(SerializationInfo info, StreamingContext context) : base(info, context) + protected SerializationException(SerializationInfo info, StreamingContext context) + : base(info, context) { } } diff --git a/src/mscorlib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs b/src/mscorlib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs new file mode 100644 index 0000000..6399510 --- /dev/null +++ b/src/mscorlib/shared/System/Runtime/Serialization/SerializationInfoEnumerator.cs @@ -0,0 +1,127 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections; +using System.Diagnostics; + +namespace System.Runtime.Serialization +{ + public struct SerializationEntry + { + private string _name; + private object _value; + private Type _type; + + internal SerializationEntry(string entryName, object entryValue, Type entryType) + { + _name = entryName; + _value = entryValue; + _type = entryType; + } + + public object Value => _value; + public string Name => _name; + public Type ObjectType => _type; + } + + public sealed class SerializationInfoEnumerator : IEnumerator + { + private readonly string[] _members; + private readonly object[] _data; + private readonly Type[] _types; + private readonly int _numItems; + private int _currItem; + private bool _current; + + internal SerializationInfoEnumerator(string[] members, object[] info, Type[] types, int numItems) + { + Debug.Assert(members != null, "[SerializationInfoEnumerator.ctor]members!=null"); + Debug.Assert(info != null, "[SerializationInfoEnumerator.ctor]info!=null"); + Debug.Assert(types != null, "[SerializationInfoEnumerator.ctor]types!=null"); + Debug.Assert(numItems >= 0, "[SerializationInfoEnumerator.ctor]numItems>=0"); + Debug.Assert(members.Length >= numItems, "[SerializationInfoEnumerator.ctor]members.Length>=numItems"); + Debug.Assert(info.Length >= numItems, "[SerializationInfoEnumerator.ctor]info.Length>=numItems"); + Debug.Assert(types.Length >= numItems, "[SerializationInfoEnumerator.ctor]types.Length>=numItems"); + + _members = members; + _data = info; + _types = types; + + //The MoveNext semantic is much easier if we enforce that [0..m_numItems] are valid entries + //in the enumerator, hence we subtract 1. + _numItems = numItems - 1; + _currItem = -1; + _current = false; + } + + public bool MoveNext() + { + if (_currItem < _numItems) + { + _currItem++; + _current = true; + } + else + { + _current = false; + } + + return _current; + } + + object IEnumerator.Current => Current; + + public SerializationEntry Current + { + get + { + if (_current == false) + { + throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); + } + return new SerializationEntry(_members[_currItem], _data[_currItem], _types[_currItem]); + } + } + + public void Reset() + { + _currItem = -1; + _current = false; + } + + public string Name + { + get + { + if (_current == false) + { + throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); + } + return _members[_currItem]; + } + } + public object Value + { + get + { + if (_current == false) + { + throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); + } + return _data[_currItem]; + } + } + public Type ObjectType + { + get + { + if (_current == false) + { + throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); + } + return _types[_currItem]; + } + } + } +} diff --git a/src/mscorlib/shared/System/Runtime/Serialization/StreamingContext.cs b/src/mscorlib/shared/System/Runtime/Serialization/StreamingContext.cs new file mode 100644 index 0000000..1026a87 --- /dev/null +++ b/src/mscorlib/shared/System/Runtime/Serialization/StreamingContext.cs @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Runtime.Serialization +{ + [Serializable] + public struct StreamingContext + { + private readonly object _additionalContext; + private readonly StreamingContextStates _state; + + public StreamingContext(StreamingContextStates state) : this(state, null) + { + } + + public StreamingContext(StreamingContextStates state, object additional) + { + _state = state; + _additionalContext = additional; + } + + public override bool Equals(object obj) + { + if (!(obj is StreamingContext)) + { + return false; + } + StreamingContext ctx = (StreamingContext)obj; + return ctx._additionalContext == _additionalContext && ctx._state == _state; + } + + public override int GetHashCode() => (int)_state; + + public StreamingContextStates State => _state; + + public object Context => _additionalContext; + } + + [Flags] + public enum StreamingContextStates + { + CrossProcess = 0x01, + CrossMachine = 0x02, + File = 0x04, + Persistence = 0x08, + Remoting = 0x10, + Other = 0x20, + Clone = 0x40, + CrossAppDomain = 0x80, + All = 0xFF, + } +} diff --git a/src/mscorlib/src/System/Runtime/Versioning/NonVersionableAttribute.cs b/src/mscorlib/shared/System/Runtime/Versioning/NonVersionableAttribute.cs similarity index 100% rename from src/mscorlib/src/System/Runtime/Versioning/NonVersionableAttribute.cs rename to src/mscorlib/shared/System/Runtime/Versioning/NonVersionableAttribute.cs diff --git a/src/mscorlib/src/System/Threading/AbandonedMutexException.cs b/src/mscorlib/shared/System/Threading/AbandonedMutexException.cs similarity index 81% rename from src/mscorlib/src/System/Threading/AbandonedMutexException.cs rename to src/mscorlib/shared/System/Threading/AbandonedMutexException.cs index 60808ad..8056a3b 100644 --- a/src/mscorlib/src/System/Threading/AbandonedMutexException.cs +++ b/src/mscorlib/shared/System/Threading/AbandonedMutexException.cs @@ -1,28 +1,24 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - -// // // AbandonedMutexException // Thrown when a wait completes because one or more mutexes was abandoned. // AbandonedMutexs indicate serious error in user code or machine state. //////////////////////////////////////////////////////////////////////////////// - using System; -using System.Runtime.Serialization; using System.Threading; using System.Runtime.InteropServices; +using System.Runtime.Serialization; namespace System.Threading { [Serializable] - [ComVisibleAttribute(false)] public class AbandonedMutexException : SystemException { - private int m_MutexIndex = -1; - private Mutex m_Mutex = null; + private int _mutexIndex = -1; + private Mutex _mutex = null; public AbandonedMutexException() : base(SR.Threading_AbandonedMutexException) @@ -63,32 +59,19 @@ namespace System.Threading SetupException(location, handle); } - private void SetupException(int location, WaitHandle handle) + protected AbandonedMutexException(SerializationInfo info, StreamingContext context) + : base(info, context) { - m_MutexIndex = location; - if (handle != null) - m_Mutex = handle as Mutex; } - protected AbandonedMutexException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } - - public Mutex Mutex + private void SetupException(int location, WaitHandle handle) { - get - { - return m_Mutex; - } + _mutexIndex = location; + if (handle != null) + _mutex = handle as Mutex; } - public int MutexIndex - { - get - { - return m_MutexIndex; - } - } + public Mutex Mutex => _mutex; + public int MutexIndex => _mutexIndex; } } - diff --git a/src/mscorlib/src/System/Threading/ApartmentState.cs b/src/mscorlib/shared/System/Threading/ApartmentState.cs similarity index 67% rename from src/mscorlib/src/System/Threading/ApartmentState.cs rename to src/mscorlib/shared/System/Threading/ApartmentState.cs index 445d70f..47c1677 100644 --- a/src/mscorlib/src/System/Threading/ApartmentState.cs +++ b/src/mscorlib/shared/System/Threading/ApartmentState.cs @@ -2,19 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// -/*============================================================================= -** -** -** -** Purpose: Enum to represent the different threading models -** -** -=============================================================================*/ - namespace System.Threading { - [Serializable] public enum ApartmentState { /*========================================================================= diff --git a/src/mscorlib/src/System/Threading/AsyncLocal.cs b/src/mscorlib/shared/System/Threading/AsyncLocal.cs similarity index 99% rename from src/mscorlib/src/System/Threading/AsyncLocal.cs rename to src/mscorlib/shared/System/Threading/AsyncLocal.cs index b1d90b3..59c8fb3 100644 --- a/src/mscorlib/src/System/Threading/AsyncLocal.cs +++ b/src/mscorlib/shared/System/Threading/AsyncLocal.cs @@ -2,11 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Generic; using System.Diagnostics; -using System.Diagnostics.Contracts; -using System.Security; namespace System.Threading { diff --git a/src/mscorlib/src/System/Threading/AutoResetEvent.cs b/src/mscorlib/shared/System/Threading/AutoResetEvent.cs similarity index 59% rename from src/mscorlib/src/System/Threading/AutoResetEvent.cs rename to src/mscorlib/shared/System/Threading/AutoResetEvent.cs index 41a012c..8320d7a 100644 --- a/src/mscorlib/src/System/Threading/AutoResetEvent.cs +++ b/src/mscorlib/shared/System/Threading/AutoResetEvent.cs @@ -2,19 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// -/*============================================================================= -** -** -** -** Purpose: An example of a WaitHandle class -** -** -=============================================================================*/ - -using System; -using System.Runtime.InteropServices; - namespace System.Threading { public sealed class AutoResetEvent : EventWaitHandle diff --git a/src/mscorlib/src/System/Threading/EventResetMode.cs b/src/mscorlib/shared/System/Threading/EventResetMode.cs similarity index 88% rename from src/mscorlib/src/System/Threading/EventResetMode.cs rename to src/mscorlib/shared/System/Threading/EventResetMode.cs index 89bf7a7..7aac0f5 100644 --- a/src/mscorlib/src/System/Threading/EventResetMode.cs +++ b/src/mscorlib/shared/System/Threading/EventResetMode.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// /*============================================================================= ** ** Enum: EventResetMode @@ -13,12 +12,8 @@ ** =============================================================================*/ - -using System.Runtime.InteropServices; - namespace System.Threading { - [ComVisibleAttribute(false)] public enum EventResetMode { AutoReset = 0, diff --git a/src/mscorlib/src/System/Threading/ExecutionContext.cs b/src/mscorlib/shared/System/Threading/ExecutionContext.cs similarity index 96% rename from src/mscorlib/src/System/Threading/ExecutionContext.cs rename to src/mscorlib/shared/System/Threading/ExecutionContext.cs index ec125ad..67857e9 100644 --- a/src/mscorlib/src/System/Threading/ExecutionContext.cs +++ b/src/mscorlib/shared/System/Threading/ExecutionContext.cs @@ -1,29 +1,22 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. + /*============================================================ ** ** ** ** Purpose: Capture execution context for a thread ** -** +** ===========================================================*/ -using System; -using System.Security; -using System.Runtime.Remoting; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; -using System.Runtime.ExceptionServices; -using System.Runtime.Serialization; -using System.Runtime.InteropServices; -using System.Runtime.CompilerServices; -using System.Runtime.ConstrainedExecution; using System.Diagnostics; using System.Diagnostics.Contracts; -using System.Diagnostics.CodeAnalysis; +using System.Runtime.ExceptionServices; +using System.Runtime.Serialization; + +using Thread = Internal.Runtime.Augments.RuntimeThread; namespace System.Threading { @@ -147,7 +140,6 @@ namespace System.Threading return executionContext != null && executionContext.m_isFlowSuppressed; } - [HandleProcessCorruptedStateExceptions] public static void Run(ExecutionContext executionContext, ContextCallback callback, Object state) { if (executionContext == null) @@ -165,7 +157,7 @@ namespace System.Threading { // Note: we have a "catch" rather than a "finally" because we want // to stop the first pass of EH here. That way we can restore the previous - // context before any of our callers' EH filters run. That means we need to + // context before any of our callers' EH filters run. That means we need to // end the scope separately in the non-exceptional case below. ecsw.Undo(currentThread); throw; @@ -190,7 +182,7 @@ namespace System.Threading } } - static internal void EstablishCopyOnWriteScope(Thread currentThread, ref ExecutionContextSwitcher ecsw) + internal static void EstablishCopyOnWriteScope(Thread currentThread, ref ExecutionContextSwitcher ecsw) { Debug.Assert(currentThread == Thread.CurrentThread); @@ -198,7 +190,6 @@ namespace System.Threading ecsw.m_sc = currentThread.SynchronizationContext; } - [HandleProcessCorruptedStateExceptions] private static void OnContextChanged(ExecutionContext previous, ExecutionContext current) { Debug.Assert(previous != null); @@ -377,5 +368,3 @@ namespace System.Threading } } } - - diff --git a/src/mscorlib/shared/System/Threading/LazyThreadSafetyMode.cs b/src/mscorlib/shared/System/Threading/LazyThreadSafetyMode.cs new file mode 100644 index 0000000..2d13f23 --- /dev/null +++ b/src/mscorlib/shared/System/Threading/LazyThreadSafetyMode.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ +// +// a set of lightweight static helpers for lazy initialization. +// +// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- + +namespace System.Threading +{ + /// + /// Specifies how a instance should synchronize access among multiple threads. + /// + public enum LazyThreadSafetyMode + { + /// + /// This mode makes no guarantees around the thread-safety of the instance. If used from multiple threads, the behavior of the is undefined. + /// This mode should be used when a is guaranteed to never be initialized from more than one thread simultaneously and high performance is crucial. + /// If valueFactory throws an exception when the is initialized, the exception will be cached and returned on subsequent accesses to Value. Also, if valueFactory recursively + /// accesses Value on this instance, a will be thrown. + /// + None, + + /// + /// When multiple threads attempt to simultaneously initialize a instance, this mode allows each thread to execute the + /// valueFactory but only the first thread to complete initialization will be allowed to set the final value of the . + /// Once initialized successfully, any future calls to Value will return the cached result. If valueFactory throws an exception on any thread, that exception will be + /// propagated out of Value. If any thread executes valueFactory without throwing an exception and, therefore, successfully sets the value, that value will be returned on + /// subsequent accesses to Value from any thread. If no thread succeeds in setting the value, IsValueCreated will remain false and subsequent accesses to Value will result in + /// the valueFactory delegate re-executing. Also, if valueFactory recursively accesses Value on this instance, an exception will NOT be thrown. + /// + PublicationOnly, + + /// + /// This mode uses locks to ensure that only a single thread can initialize a instance in a thread-safe manner. In general, + /// taken if this mode is used in conjunction with a valueFactory delegate that uses locks internally, a deadlock can occur if not + /// handled carefully. If valueFactory throws an exception when the is initialized, the exception will be cached and returned on + /// subsequent accesses to Value. Also, if valueFactory recursively accesses Value on this instance, a will be thrown. + /// + ExecutionAndPublication + } +} diff --git a/src/mscorlib/src/System/Threading/LockRecursionException.cs b/src/mscorlib/shared/System/Threading/LockRecursionException.cs similarity index 52% rename from src/mscorlib/src/System/Threading/LockRecursionException.cs rename to src/mscorlib/shared/System/Threading/LockRecursionException.cs index 5624282..2f296cb 100644 --- a/src/mscorlib/src/System/Threading/LockRecursionException.cs +++ b/src/mscorlib/shared/System/Threading/LockRecursionException.cs @@ -2,28 +2,28 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -/*============================================================ -// -// -// -// Purpose: -// This exception represents a failed attempt to recursively -// acquire a lock, because the particular lock kind doesn't -// support it in its current state. -============================================================*/ - using System; using System.Runtime.Serialization; -using System.Runtime.CompilerServices; namespace System.Threading { [Serializable] public class LockRecursionException : System.Exception { - public LockRecursionException() { } - public LockRecursionException(string message) : base(message) { } + public LockRecursionException() + { + } + + public LockRecursionException(string message) + : base(message) + { + } + + public LockRecursionException(string message, Exception innerException) + : base(message, innerException) + { + } + protected LockRecursionException(SerializationInfo info, StreamingContext context) : base(info, context) { } - public LockRecursionException(string message, Exception innerException) : base(message, innerException) { } } } diff --git a/src/mscorlib/src/System/Threading/ManualResetEvent.cs b/src/mscorlib/shared/System/Threading/ManualResetEvent.cs similarity index 59% rename from src/mscorlib/src/System/Threading/ManualResetEvent.cs rename to src/mscorlib/shared/System/Threading/ManualResetEvent.cs index bb875c4..4b8d61f 100644 --- a/src/mscorlib/src/System/Threading/ManualResetEvent.cs +++ b/src/mscorlib/shared/System/Threading/ManualResetEvent.cs @@ -2,19 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// -/*============================================================================= -** -** -** -** Purpose: An example of a WaitHandle class -** -** -=============================================================================*/ - -using System; -using System.Runtime.InteropServices; - namespace System.Threading { public sealed class ManualResetEvent : EventWaitHandle diff --git a/src/mscorlib/src/System/Threading/ParameterizedThreadStart.cs b/src/mscorlib/shared/System/Threading/ParameterizedThreadStart.cs similarity index 85% rename from src/mscorlib/src/System/Threading/ParameterizedThreadStart.cs rename to src/mscorlib/shared/System/Threading/ParameterizedThreadStart.cs index 74f17a5..c0f29e8 100644 --- a/src/mscorlib/src/System/Threading/ParameterizedThreadStart.cs +++ b/src/mscorlib/shared/System/Threading/ParameterizedThreadStart.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// /*============================================================================= ** ** @@ -13,12 +12,7 @@ ** =============================================================================*/ - -using System.Threading; -using System.Runtime.InteropServices; - namespace System.Threading { - [ComVisibleAttribute(false)] public delegate void ParameterizedThreadStart(object obj); } diff --git a/src/mscorlib/src/System/Threading/SemaphoreFullException.cs b/src/mscorlib/shared/System/Threading/SemaphoreFullException.cs similarity index 92% rename from src/mscorlib/src/System/Threading/SemaphoreFullException.cs rename to src/mscorlib/shared/System/Threading/SemaphoreFullException.cs index bbcc226..19ac19d 100644 --- a/src/mscorlib/src/System/Threading/SemaphoreFullException.cs +++ b/src/mscorlib/shared/System/Threading/SemaphoreFullException.cs @@ -4,12 +4,10 @@ using System; using System.Runtime.Serialization; -using System.Runtime.InteropServices; namespace System.Threading { [Serializable] - [ComVisibleAttribute(false)] public class SemaphoreFullException : SystemException { public SemaphoreFullException() : base(SR.Threading_SemaphoreFullException) @@ -29,4 +27,3 @@ namespace System.Threading } } } - diff --git a/src/mscorlib/src/System/Threading/SendOrPostCallback.cs b/src/mscorlib/shared/System/Threading/SendOrPostCallback.cs similarity index 53% rename from src/mscorlib/src/System/Threading/SendOrPostCallback.cs rename to src/mscorlib/shared/System/Threading/SendOrPostCallback.cs index c08b1ab..6692d35 100644 --- a/src/mscorlib/src/System/Threading/SendOrPostCallback.cs +++ b/src/mscorlib/shared/System/Threading/SendOrPostCallback.cs @@ -1,14 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -/*============================================================ -** -** -** -** Purpose: Represents a method to be called when a message is to be dispatched to a synchronization context. -** -** -===========================================================*/ namespace System.Threading { diff --git a/src/mscorlib/src/System/Threading/SynchronizationLockException.cs b/src/mscorlib/shared/System/Threading/SynchronizationLockException.cs similarity index 98% rename from src/mscorlib/src/System/Threading/SynchronizationLockException.cs rename to src/mscorlib/shared/System/Threading/SynchronizationLockException.cs index 42892fe..120577f 100644 --- a/src/mscorlib/src/System/Threading/SynchronizationLockException.cs +++ b/src/mscorlib/shared/System/Threading/SynchronizationLockException.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// /*============================================================================= ** ** @@ -13,8 +12,6 @@ ** =============================================================================*/ - -using System; using System.Runtime.Serialization; namespace System.Threading @@ -45,5 +42,3 @@ namespace System.Threading } } } - - diff --git a/src/mscorlib/src/System/Threading/ThreadPriority.cs b/src/mscorlib/shared/System/Threading/ThreadPriority.cs similarity index 68% rename from src/mscorlib/src/System/Threading/ThreadPriority.cs rename to src/mscorlib/shared/System/Threading/ThreadPriority.cs index 64b77ea..3b34bd5 100644 --- a/src/mscorlib/src/System/Threading/ThreadPriority.cs +++ b/src/mscorlib/shared/System/Threading/ThreadPriority.cs @@ -2,21 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// -/*============================================================================= -** -** -** -** Purpose: Enums for the priorities of a Thread -** -** -=============================================================================*/ - -using System.Threading; - namespace System.Threading { - [Serializable] public enum ThreadPriority { /*========================================================================= diff --git a/src/mscorlib/src/System/Threading/ThreadStart.cs b/src/mscorlib/shared/System/Threading/ThreadStart.cs similarity index 76% rename from src/mscorlib/src/System/Threading/ThreadStart.cs rename to src/mscorlib/shared/System/Threading/ThreadStart.cs index c065fdd..5532539 100644 --- a/src/mscorlib/src/System/Threading/ThreadStart.cs +++ b/src/mscorlib/shared/System/Threading/ThreadStart.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// /*============================================================================= ** ** @@ -13,12 +12,7 @@ ** =============================================================================*/ -using System.Threading; - namespace System.Threading { - // Define the delegate - // NOTE: If you change the signature here, there is code in COMSynchronization - // that invokes this delegate in native. public delegate void ThreadStart(); } diff --git a/src/mscorlib/src/System/Threading/ThreadStartException.cs b/src/mscorlib/shared/System/Threading/ThreadStartException.cs similarity index 80% rename from src/mscorlib/src/System/Threading/ThreadStartException.cs rename to src/mscorlib/shared/System/Threading/ThreadStartException.cs index 54ec4ba..2ff77bc 100644 --- a/src/mscorlib/src/System/Threading/ThreadStartException.cs +++ b/src/mscorlib/shared/System/Threading/ThreadStartException.cs @@ -2,35 +2,28 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// - -using System; using System.Runtime.Serialization; -using System.Runtime.InteropServices; namespace System.Threading { [Serializable] public sealed class ThreadStartException : SystemException { - private ThreadStartException() + internal ThreadStartException() : base(SR.Arg_ThreadStartException) { HResult = __HResults.COR_E_THREADSTART; } - private ThreadStartException(Exception reason) + internal ThreadStartException(Exception reason) : base(SR.Arg_ThreadStartException, reason) { HResult = __HResults.COR_E_THREADSTART; } - //required for serialization internal ThreadStartException(SerializationInfo info, StreamingContext context) : base(info, context) { } } } - - diff --git a/src/mscorlib/src/System/Threading/ThreadState.cs b/src/mscorlib/shared/System/Threading/ThreadState.cs similarity index 74% rename from src/mscorlib/src/System/Threading/ThreadState.cs rename to src/mscorlib/shared/System/Threading/ThreadState.cs index c95772e..4bf3b51 100644 --- a/src/mscorlib/src/System/Threading/ThreadState.cs +++ b/src/mscorlib/shared/System/Threading/ThreadState.cs @@ -2,19 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// -/*============================================================================= -** -** -** -** Purpose: Enum to represent the different thread states -** -** -=============================================================================*/ - namespace System.Threading { - [Serializable] [Flags] public enum ThreadState { diff --git a/src/mscorlib/src/System/Threading/ThreadStateException.cs b/src/mscorlib/shared/System/Threading/ThreadStateException.cs similarity index 95% rename from src/mscorlib/src/System/Threading/ThreadStateException.cs rename to src/mscorlib/shared/System/Threading/ThreadStateException.cs index a2b8b15..33bc8ba 100644 --- a/src/mscorlib/src/System/Threading/ThreadStateException.cs +++ b/src/mscorlib/shared/System/Threading/ThreadStateException.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// /*============================================================================= ** ** @@ -13,7 +12,6 @@ ** =============================================================================*/ -using System; using System.Runtime.Serialization; namespace System.Threading @@ -39,7 +37,8 @@ namespace System.Threading HResult = __HResults.COR_E_THREADSTATE; } - protected ThreadStateException(SerializationInfo info, StreamingContext context) : base(info, context) + protected ThreadStateException(SerializationInfo info, StreamingContext context) + : base(info, context) { } } diff --git a/src/mscorlib/shared/System/Threading/TimeoutHelper.cs b/src/mscorlib/shared/System/Threading/TimeoutHelper.cs new file mode 100644 index 0000000..c66c9ad --- /dev/null +++ b/src/mscorlib/shared/System/Threading/TimeoutHelper.cs @@ -0,0 +1,54 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Diagnostics; + +namespace System.Threading +{ + /// + /// A helper class to capture a start time using Environment.TickCout as a time in milliseconds, also updates a given timeout bu subtracting the current time from + /// the start time + /// + internal static class TimeoutHelper + { + /// + /// Returns the Environment.TickCount as a start time in milliseconds as a uint, TickCount tools over from postive to negative every ~ 25 days + /// then ~25 days to back to positive again, uint is sued to ignore the sign and double the range to 50 days + /// + /// + public static uint GetTime() + { + return (uint)Environment.TickCount; + } + + /// + /// Helper function to measure and update the elapsed time + /// + /// The first time (in milliseconds) observed when the wait started + /// The orginal wait timeoutout in milliseconds + /// The new wait time in milliseconds, -1 if the time expired + public static int UpdateTimeOut(uint startTime, int originalWaitMillisecondsTimeout) + { + // The function must be called in case the time out is not infinite + Debug.Assert(originalWaitMillisecondsTimeout != Timeout.Infinite); + + uint elapsedMilliseconds = (GetTime() - startTime); + + // Check the elapsed milliseconds is greater than max int because this property is uint + if (elapsedMilliseconds > int.MaxValue) + { + return 0; + } + + // Subtract the elapsed time from the current wait time + int currentWaitTimeout = originalWaitMillisecondsTimeout - (int)elapsedMilliseconds; ; + if (currentWaitTimeout <= 0) + { + return 0; + } + + return currentWaitTimeout; + } + } +} diff --git a/src/mscorlib/src/System/Threading/WaitHandleCannotBeOpenedException.cs b/src/mscorlib/shared/System/Threading/WaitHandleCannotBeOpenedException.cs similarity index 92% rename from src/mscorlib/src/System/Threading/WaitHandleCannotBeOpenedException.cs rename to src/mscorlib/shared/System/Threading/WaitHandleCannotBeOpenedException.cs index a6f0267..e44946a 100644 --- a/src/mscorlib/src/System/Threading/WaitHandleCannotBeOpenedException.cs +++ b/src/mscorlib/shared/System/Threading/WaitHandleCannotBeOpenedException.cs @@ -2,17 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// - -using System; using System.Runtime.Serialization; -using System.Runtime.InteropServices; namespace System.Threading { [Serializable] - [ComVisibleAttribute(false)] - public class WaitHandleCannotBeOpenedException : ApplicationException { public WaitHandleCannotBeOpenedException() : base(SR.Threading_WaitHandleCannotBeOpenedException) @@ -35,4 +29,3 @@ namespace System.Threading } } } - diff --git a/src/mscorlib/src/System/Runtime/Serialization/IDeserializationCallback.cs b/src/mscorlib/src/System/Runtime/Serialization/IDeserializationCallback.cs deleted file mode 100644 index 2b07ce9..0000000 --- a/src/mscorlib/src/System/Runtime/Serialization/IDeserializationCallback.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -/*============================================================ -** -** Interface: IDeserializationEventListener -** -** -** Purpose: Implemented by any class that wants to indicate that -** it wishes to receive deserialization events. -** -** -===========================================================*/ - -using System; - -namespace System.Runtime.Serialization -{ - // Interface does not need to be marked with the serializable attribute - public interface IDeserializationCallback - { - void OnDeserialization(Object sender); - } -} diff --git a/src/mscorlib/src/System/Runtime/Serialization/SerializationAttributes.cs b/src/mscorlib/src/System/Runtime/Serialization/SerializationAttributes.cs deleted file mode 100644 index be9f4ae..0000000 --- a/src/mscorlib/src/System/Runtime/Serialization/SerializationAttributes.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -/*============================================================ -** -** -** -** Purpose: Various Attributes for Serialization -** -** -============================================================*/ - -using System; -using System.Diagnostics.Contracts; -using System.Reflection; - -namespace System.Runtime.Serialization -{ - [AttributeUsage(AttributeTargets.Field, Inherited = false)] - public sealed class OptionalFieldAttribute : Attribute - { - private int versionAdded = 1; - public OptionalFieldAttribute() { } - - public int VersionAdded - { - get - { - return versionAdded; - } - set - { - if (value < 1) - throw new ArgumentException(SR.Serialization_OptionalFieldVersionValue); - Contract.EndContractBlock(); - versionAdded = value; - } - } - } - - [AttributeUsage(AttributeTargets.Method, Inherited = false)] - public sealed class OnSerializingAttribute : Attribute - { - } - - [AttributeUsage(AttributeTargets.Method, Inherited = false)] - public sealed class OnSerializedAttribute : Attribute - { - } - - [AttributeUsage(AttributeTargets.Method, Inherited = false)] - public sealed class OnDeserializingAttribute : Attribute - { - } - - [AttributeUsage(AttributeTargets.Method, Inherited = false)] - public sealed class OnDeserializedAttribute : Attribute - { - } -} diff --git a/src/mscorlib/src/System/Runtime/Serialization/SerializationInfoEnumerator.cs b/src/mscorlib/src/System/Runtime/Serialization/SerializationInfoEnumerator.cs deleted file mode 100644 index 791f7a8..0000000 --- a/src/mscorlib/src/System/Runtime/Serialization/SerializationInfoEnumerator.cs +++ /dev/null @@ -1,176 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -/*============================================================ -** -** -** -** Purpose: A formatter-friendly mechanism for walking all of -** the data in a SerializationInfo. Follows the IEnumerator -** mechanism from Collections. -** -** -============================================================*/ - -using System; -using System.Diagnostics; -using System.Collections; -using System.Diagnostics.Contracts; - -namespace System.Runtime.Serialization -{ - // - // The tuple returned by SerializationInfoEnumerator.Current. - // - public struct SerializationEntry - { - private Type m_type; - private Object m_value; - private String m_name; - - public Object Value - { - get - { - return m_value; - } - } - - public String Name - { - get - { - return m_name; - } - } - - public Type ObjectType - { - get - { - return m_type; - } - } - - internal SerializationEntry(String entryName, Object entryValue, Type entryType) - { - m_value = entryValue; - m_name = entryName; - m_type = entryType; - } - } - - // - // A simple enumerator over the values stored in the SerializationInfo. - // This does not snapshot the values, it just keeps pointers to the - // member variables of the SerializationInfo that created it. - // - public sealed class SerializationInfoEnumerator : IEnumerator - { - private String[] m_members; - private Object[] m_data; - private Type[] m_types; - private int m_numItems; - private int m_currItem; - private bool m_current; - - internal SerializationInfoEnumerator(String[] members, Object[] info, Type[] types, int numItems) - { - Debug.Assert(members != null, "[SerializationInfoEnumerator.ctor]members!=null"); - Debug.Assert(info != null, "[SerializationInfoEnumerator.ctor]info!=null"); - Debug.Assert(types != null, "[SerializationInfoEnumerator.ctor]types!=null"); - Debug.Assert(numItems >= 0, "[SerializationInfoEnumerator.ctor]numItems>=0"); - Debug.Assert(members.Length >= numItems, "[SerializationInfoEnumerator.ctor]members.Length>=numItems"); - Debug.Assert(info.Length >= numItems, "[SerializationInfoEnumerator.ctor]info.Length>=numItems"); - Debug.Assert(types.Length >= numItems, "[SerializationInfoEnumerator.ctor]types.Length>=numItems"); - - m_members = members; - m_data = info; - m_types = types; - //The MoveNext semantic is much easier if we enforce that [0..m_numItems] are valid entries - //in the enumerator, hence we subtract 1. - m_numItems = numItems - 1; - m_currItem = -1; - m_current = false; - } - - public bool MoveNext() - { - if (m_currItem < m_numItems) - { - m_currItem++; - m_current = true; - } - else - { - m_current = false; - } - return m_current; - } - - Object IEnumerator.Current - { //Actually returns a SerializationEntry - get - { - if (m_current == false) - { - throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); - } - return (Object)(new SerializationEntry(m_members[m_currItem], m_data[m_currItem], m_types[m_currItem])); - } - } - - public SerializationEntry Current - { //Actually returns a SerializationEntry - get - { - if (m_current == false) - { - throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); - } - return (new SerializationEntry(m_members[m_currItem], m_data[m_currItem], m_types[m_currItem])); - } - } - - public void Reset() - { - m_currItem = -1; - m_current = false; - } - - public String Name - { - get - { - if (m_current == false) - { - throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); - } - return m_members[m_currItem]; - } - } - public Object Value - { - get - { - if (m_current == false) - { - throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); - } - return m_data[m_currItem]; - } - } - public Type ObjectType - { - get - { - if (m_current == false) - { - throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); - } - return m_types[m_currItem]; - } - } - } -} diff --git a/src/mscorlib/src/System/Runtime/Serialization/StreamingContext.cs b/src/mscorlib/src/System/Runtime/Serialization/StreamingContext.cs deleted file mode 100644 index 12a7631..0000000 --- a/src/mscorlib/src/System/Runtime/Serialization/StreamingContext.cs +++ /dev/null @@ -1,84 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -/*============================================================ -** -** ValueType: StreamingContext -** -** -** Purpose: A value type indicating the source or destination of our streaming. -** -** -===========================================================*/ - -using System.Runtime.Remoting; -using System; - -namespace System.Runtime.Serialization -{ - [Serializable] - public struct StreamingContext - { - internal Object m_additionalContext; - internal StreamingContextStates m_state; - - public StreamingContext(StreamingContextStates state) - : this(state, null) - { - } - - public StreamingContext(StreamingContextStates state, Object additional) - { - m_state = state; - m_additionalContext = additional; - } - - public Object Context - { - get { return m_additionalContext; } - } - - public override bool Equals(Object obj) - { - if (!(obj is StreamingContext)) - { - return false; - } - if (((StreamingContext)obj).m_additionalContext == m_additionalContext && - ((StreamingContext)obj).m_state == m_state) - { - return true; - } - return false; - } - - public override int GetHashCode() - { - return (int)m_state; - } - - public StreamingContextStates State - { - get { return m_state; } - } - } - - // ********************************************************** - // Keep these in sync with the version in vm\runtimehandles.h - // ********************************************************** - [Serializable] - [Flags] - public enum StreamingContextStates - { - CrossProcess = 0x01, - CrossMachine = 0x02, - File = 0x04, - Persistence = 0x08, - Remoting = 0x10, - Other = 0x20, - Clone = 0x40, - CrossAppDomain = 0x80, - All = 0xFF, - } -} diff --git a/src/mscorlib/src/System/Threading/LazyInitializer.cs b/src/mscorlib/src/System/Threading/LazyInitializer.cs index e264a8f..d585ba6 100644 --- a/src/mscorlib/src/System/Threading/LazyInitializer.cs +++ b/src/mscorlib/src/System/Threading/LazyInitializer.cs @@ -17,37 +17,6 @@ using System.Diagnostics.Contracts; namespace System.Threading { /// - /// Specifies how a instance should synchronize access among multiple threads. - /// - public enum LazyThreadSafetyMode - { - /// - /// This mode makes no guarantees around the thread-safety of the instance. If used from multiple threads, the behavior of the is undefined. - /// This mode should be used when a is guaranteed to never be initialized from more than one thread simultaneously and high performance is crucial. - /// If valueFactory throws an exception when the is initialized, the exception will be cached and returned on subsequent accesses to Value. Also, if valueFactory recursively - /// accesses Value on this instance, a will be thrown. - /// - None, - - /// - /// When multiple threads attempt to simultaneously initialize a instance, this mode allows each thread to execute the - /// valueFactory but only the first thread to complete initialization will be allowed to set the final value of the . - /// Once initialized successfully, any future calls to Value will return the cached result. If valueFactory throws an exception on any thread, that exception will be - /// propagated out of Value. If any thread executes valueFactory without throwing an exception and, therefore, successfully sets the value, that value will be returned on - /// subsequent accesses to Value from any thread. If no thread succeeds in setting the value, IsValueCreated will remain false and subsequent accesses to Value will result in - /// the valueFactory delegate re-executing. Also, if valueFactory recursively accesses Value on this instance, an exception will NOT be thrown. - /// - PublicationOnly, - - /// - /// This mode uses locks to ensure that only a single thread can initialize a instance in a thread-safe manner. In general, - /// taken if this mode is used in conjunction with a valueFactory delegate that uses locks internally, a deadlock can occur if not - /// handled carefully. If valueFactory throws an exception when the is initialized, the exception will be cached and returned on - /// subsequent accesses to Value. Also, if valueFactory recursively accesses Value on this instance, a will be thrown. - /// - ExecutionAndPublication - } - /// /// Provides lazy initialization routines. /// /// diff --git a/src/mscorlib/src/System/Threading/SpinWait.cs b/src/mscorlib/src/System/Threading/SpinWait.cs index ae490e8..30d7aa6 100644 --- a/src/mscorlib/src/System/Threading/SpinWait.cs +++ b/src/mscorlib/src/System/Threading/SpinWait.cs @@ -51,7 +51,7 @@ namespace System.Threading /// /// /// encapsulates common spinning logic. On single-processor machines, yields are - /// always used instead of busy waits, and on computers with Intel� processors employing Hyper-Threading� + /// always used instead of busy waits, and on computers with Intel processors employing Hyper-Threading /// technology, it helps to prevent hardware thread starvation. SpinWait encapsulates a good mixture of /// spinning and true yielding. /// @@ -312,50 +312,4 @@ namespace System.Threading get { return ProcessorCount == 1; } } } - - /// - /// A helper class to capture a start time using Environment.TickCout as a time in milliseconds, also updates a given timeout bu subtracting the current time from - /// the start time - /// - internal static class TimeoutHelper - { - /// - /// Returns the Environment.TickCount as a start time in milliseconds as a uint, TickCount tools over from postive to negative every ~ 25 days - /// then ~25 days to back to positive again, uint is sued to ignore the sign and double the range to 50 days - /// - /// - public static uint GetTime() - { - return (uint)Environment.TickCount; - } - - /// - /// Helper function to measure and update the elapsed time - /// - /// The first time (in milliseconds) observed when the wait started - /// The orginal wait timeoutout in milliseconds - /// The new wait time in milliseconds, -1 if the time expired - public static int UpdateTimeOut(uint startTime, int originalWaitMillisecondsTimeout) - { - // The function must be called in case the time out is not infinite - Debug.Assert(originalWaitMillisecondsTimeout != Timeout.Infinite); - - uint elapsedMilliseconds = (GetTime() - startTime); - - // Check the elapsed milliseconds is greater than max int because this property is uint - if (elapsedMilliseconds > int.MaxValue) - { - return 0; - } - - // Subtract the elapsed time from the current wait time - int currentWaitTimeout = originalWaitMillisecondsTimeout - (int)elapsedMilliseconds; ; - if (currentWaitTimeout <= 0) - { - return 0; - } - - return currentWaitTimeout; - } - } } -- 2.7.4