<Compile Include="$(BclSourcesRoot)\System\Globalization\GlobalizationAssembly.cs" />
</ItemGroup>
<ItemGroup>
- <Compile Include="$(BclSourcesRoot)\System\Threading\AbandonedMutexException.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\AsyncLocal.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\AutoResetEvent.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\SendOrPostCallback.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\SynchronizationContext.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\EventResetMode.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\EventWaitHandle.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\ExecutionContext.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Interlocked.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\LockRecursionException.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\ManualResetEvent.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Monitor.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Mutex.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Overlapped.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\ParameterizedThreadStart.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Semaphore.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\SemaphoreFullException.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\SynchronizationLockException.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Thread.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\ThreadInterruptedException.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\ThreadPool.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\ThreadPriority.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\ThreadStart.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\ThreadState.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\ThreadStateException.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\ThreadStartException.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Timer.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Volatile.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\WaitHandle.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\WaitHandleCannotBeOpenedException.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Threading\ApartmentState.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\SpinLock.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\SpinWait.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\LazyInitializer.cs" />
<ItemGroup>
<Compile Include="$(BclSourcesRoot)\System\Runtime\Serialization\FormatterConverter.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\Serialization\FormatterServices.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Runtime\Serialization\IDeserializationCallback.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Runtime\Serialization\SerializationAttributes.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Runtime\Serialization\SerializationException.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\Serialization\SerializationInfo.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Runtime\Serialization\SerializationInfoEnumerator.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Runtime\Serialization\StreamingContext.cs" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="$(BclSourcesRoot)\System\Runtime\Versioning\NonVersionableAttribute.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(BclSourcesRoot)\System\Runtime\Remoting\ObjectHandle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnmanagedFunctionPointerAttribute.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnmanagedType.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\VarEnum.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\IDeserializationCallback.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\IFormatterConverter.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\IObjectReference.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\ISafeSerializationData.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\ISerializable.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\OnDeserializedAttribute.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\OnDeserializingAttribute.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\OnSerializedAttribute.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\OnSerializingAttribute.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\OptionalFieldAttribute.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\SafeSerializationEventArgs.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\SerializationException.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\SerializationInfoEnumerator.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Serialization\StreamingContext.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Versioning\NonVersionableAttribute.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Versioning\TargetFrameworkAttribute.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Security\AllowPartiallyTrustedCallersAttribute.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Security\CryptographicException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Text\UTF8Encoding.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Text\UnicodeEncoding.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\ThreadAttributes.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\AbandonedMutexException.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ApartmentState.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\AsyncLocal.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\AutoResetEvent.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\DeferredDisposableLifetime.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\EventResetMode.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ExecutionContext.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\LazyThreadSafetyMode.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\LockRecursionException.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ManualResetEvent.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ParameterizedThreadStart.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\SemaphoreFullException.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\SendOrPostCallback.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\SynchronizationLockException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskCanceledException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskExtensions.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Tasks\TaskSchedulerException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadAbortException.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadPriority.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadStart.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadStartException.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadState.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadStateException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Timeout.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\TimeoutHelper.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Threading\WaitHandleCannotBeOpenedException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\ThreadStaticAttribute.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\TimeoutException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZone.cs"/>
--- /dev/null
+// 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);
+ }
+}
--- /dev/null
+// 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
+ {
+ }
+}
--- /dev/null
+// 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
+ {
+ }
+}
--- /dev/null
+// 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
+ {
+ }
+}
--- /dev/null
+// 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
+ {
+ }
+}
--- /dev/null
+// 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;
+ }
+ }
+ }
+}
// 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
[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;
}
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)
{
}
}
--- /dev/null
+// 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];
+ }
+ }
+ }
+}
--- /dev/null
+// 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,
+ }
+}
// 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)
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;
}
}
-
// 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
{
/*=========================================================================
// 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
{
// 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
// 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
**
=============================================================================*/
-
-using System.Runtime.InteropServices;
-
namespace System.Threading
{
- [ComVisibleAttribute(false)]
public enum EventResetMode
{
AutoReset = 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: 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
{
return executionContext != null && executionContext.m_isFlowSuppressed;
}
- [HandleProcessCorruptedStateExceptions]
public static void Run(ExecutionContext executionContext, ContextCallback callback, Object state)
{
if (executionContext == null)
{
// 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;
}
}
- static internal void EstablishCopyOnWriteScope(Thread currentThread, ref ExecutionContextSwitcher ecsw)
+ internal static void EstablishCopyOnWriteScope(Thread currentThread, ref ExecutionContextSwitcher ecsw)
{
Debug.Assert(currentThread == Thread.CurrentThread);
ecsw.m_sc = currentThread.SynchronizationContext;
}
- [HandleProcessCorruptedStateExceptions]
private static void OnContextChanged(ExecutionContext previous, ExecutionContext current)
{
Debug.Assert(previous != null);
}
}
}
-
-
--- /dev/null
+// 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
+{
+ /// <summary>
+ /// Specifies how a <see cref="T:System.Threading.Lazy{T}"/> instance should synchronize access among multiple threads.
+ /// </summary>
+ public enum LazyThreadSafetyMode
+ {
+ /// <summary>
+ /// This mode makes no guarantees around the thread-safety of the <see cref="T:System.Threading.Lazy{T}"/> instance. If used from multiple threads, the behavior of the <see cref="T:System.Threading.Lazy{T}"/> is undefined.
+ /// This mode should be used when a <see cref="T:System.Threading.Lazy{T}"/> is guaranteed to never be initialized from more than one thread simultaneously and high performance is crucial.
+ /// If valueFactory throws an exception when the <see cref="T:System.Threading.Lazy{T}"/> is initialized, the exception will be cached and returned on subsequent accesses to Value. Also, if valueFactory recursively
+ /// accesses Value on this <see cref="T:System.Threading.Lazy{T}"/> instance, a <see cref="T:System.InvalidOperationException"/> will be thrown.
+ /// </summary>
+ None,
+
+ /// <summary>
+ /// When multiple threads attempt to simultaneously initialize a <see cref="T:System.Threading.Lazy{T}"/> 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 <see cref="T:System.Threading.Lazy{T}"/>.
+ /// 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 <see cref="T:System.Threading.Lazy{T}"/> instance, an exception will NOT be thrown.
+ /// </summary>
+ PublicationOnly,
+
+ /// <summary>
+ /// This mode uses locks to ensure that only a single thread can initialize a <see cref="T:System.Threading.Lazy{T}"/> instance in a thread-safe manner. In general,
+ /// taken if this mode is used in conjunction with a <see cref="T:System.Threading.Lazy{T}"/> valueFactory delegate that uses locks internally, a deadlock can occur if not
+ /// handled carefully. If valueFactory throws an exception when the<see cref="T:System.Threading.Lazy{T}"/> is initialized, the exception will be cached and returned on
+ /// subsequent accesses to Value. Also, if valueFactory recursively accesses Value on this <see cref="T:System.Threading.Lazy{T}"/> instance, a <see cref="T:System.InvalidOperationException"/> will be thrown.
+ /// </summary>
+ ExecutionAndPublication
+ }
+}
// 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) { }
}
}
// 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
// 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.Threading;
-using System.Runtime.InteropServices;
-
namespace System.Threading
{
- [ComVisibleAttribute(false)]
public delegate void ParameterizedThreadStart(object obj);
}
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)
}
}
}
-
// 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
{
// 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;
namespace System.Threading
}
}
}
-
-
// 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
{
/*=========================================================================
// 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.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();
}
// 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)
{
}
}
}
-
-
// 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
{
// 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;
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)
{
}
}
--- /dev/null
+// 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
+{
+ /// <summary>
+ /// 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
+ /// </summary>
+ internal static class TimeoutHelper
+ {
+ /// <summary>
+ /// 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
+ /// </summary>
+ /// <returns></returns>
+ public static uint GetTime()
+ {
+ return (uint)Environment.TickCount;
+ }
+
+ /// <summary>
+ /// Helper function to measure and update the elapsed time
+ /// </summary>
+ /// <param name="startTime"> The first time (in milliseconds) observed when the wait started</param>
+ /// <param name="originalWaitMillisecondsTimeout">The orginal wait timeoutout in milliseconds</param>
+ /// <returns>The new wait time in milliseconds, -1 if the time expired</returns>
+ 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;
+ }
+ }
+}
// 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)
}
}
}
-
+++ /dev/null
-// 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);
- }
-}
+++ /dev/null
-// 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
- {
- }
-}
+++ /dev/null
-// 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];
- }
- }
- }
-}
+++ /dev/null
-// 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,
- }
-}
namespace System.Threading
{
/// <summary>
- /// Specifies how a <see cref="T:System.Threading.Lazy{T}"/> instance should synchronize access among multiple threads.
- /// </summary>
- public enum LazyThreadSafetyMode
- {
- /// <summary>
- /// This mode makes no guarantees around the thread-safety of the <see cref="T:System.Threading.Lazy{T}"/> instance. If used from multiple threads, the behavior of the <see cref="T:System.Threading.Lazy{T}"/> is undefined.
- /// This mode should be used when a <see cref="T:System.Threading.Lazy{T}"/> is guaranteed to never be initialized from more than one thread simultaneously and high performance is crucial.
- /// If valueFactory throws an exception when the <see cref="T:System.Threading.Lazy{T}"/> is initialized, the exception will be cached and returned on subsequent accesses to Value. Also, if valueFactory recursively
- /// accesses Value on this <see cref="T:System.Threading.Lazy{T}"/> instance, a <see cref="T:System.InvalidOperationException"/> will be thrown.
- /// </summary>
- None,
-
- /// <summary>
- /// When multiple threads attempt to simultaneously initialize a <see cref="T:System.Threading.Lazy{T}"/> 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 <see cref="T:System.Threading.Lazy{T}"/>.
- /// 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 <see cref="T:System.Threading.Lazy{T}"/> instance, an exception will NOT be thrown.
- /// </summary>
- PublicationOnly,
-
- /// <summary>
- /// This mode uses locks to ensure that only a single thread can initialize a <see cref="T:System.Threading.Lazy{T}"/> instance in a thread-safe manner. In general,
- /// taken if this mode is used in conjunction with a <see cref="T:System.Threading.Lazy{T}"/> valueFactory delegate that uses locks internally, a deadlock can occur if not
- /// handled carefully. If valueFactory throws an exception when the<see cref="T:System.Threading.Lazy{T}"/> is initialized, the exception will be cached and returned on
- /// subsequent accesses to Value. Also, if valueFactory recursively accesses Value on this <see cref="T:System.Threading.Lazy{T}"/> instance, a <see cref="T:System.InvalidOperationException"/> will be thrown.
- /// </summary>
- ExecutionAndPublication
- }
- /// <summary>
/// Provides lazy initialization routines.
/// </summary>
/// <remarks>
/// <remarks>
/// <para>
/// <see cref="SpinWait"/> 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.
/// </para>
get { return ProcessorCount == 1; }
}
}
-
- /// <summary>
- /// 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
- /// </summary>
- internal static class TimeoutHelper
- {
- /// <summary>
- /// 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
- /// </summary>
- /// <returns></returns>
- public static uint GetTime()
- {
- return (uint)Environment.TickCount;
- }
-
- /// <summary>
- /// Helper function to measure and update the elapsed time
- /// </summary>
- /// <param name="startTime"> The first time (in milliseconds) observed when the wait started</param>
- /// <param name="originalWaitMillisecondsTimeout">The orginal wait timeoutout in milliseconds</param>
- /// <returns>The new wait time in milliseconds, -1 if the time expired</returns>
- 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;
- }
- }
}