Imported Upstream version 4.8.0.309

Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-11-10 13:04:39 +00:00
parent ee1447783b
commit 94b2861243
4912 changed files with 390737 additions and 49310 deletions

View File

@@ -1,235 +0,0 @@
//
// System.Threading.EventWaitHandle.cs
//
// Author:
// Dick Porter (dick@ximian.com)
//
// (C) Ximian, Inc. (http://www.ximian.com)
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.IO;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
namespace System.Threading
{
[ComVisible (true)]
public class EventWaitHandle : WaitHandle
{
private EventWaitHandle (IntPtr handle)
{
Handle = handle;
}
static bool IsManualReset (EventResetMode mode)
{
if ((mode < EventResetMode.AutoReset) || (mode > EventResetMode.ManualReset))
throw new ArgumentException ("mode");
return (mode == EventResetMode.ManualReset);
}
public EventWaitHandle (bool initialState, EventResetMode mode)
{
bool created;
bool manual = IsManualReset (mode);
Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, null, out created);
}
#if !MOBILE
public EventWaitHandle (bool initialState, EventResetMode mode,
string name)
{
bool created;
bool manual = IsManualReset (mode);
Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, name, out created);
}
public EventWaitHandle (bool initialState, EventResetMode mode,
string name, out bool createdNew)
{
bool manual = IsManualReset (mode);
Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, name, out createdNew);
}
[MonoTODO ("Use access control in CreateEvent_internal")]
public EventWaitHandle (bool initialState, EventResetMode mode,
string name, out bool createdNew,
EventWaitHandleSecurity eventSecurity)
{
bool manual = IsManualReset (mode);
Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, name, out createdNew);
}
public EventWaitHandleSecurity GetAccessControl ()
{
return new EventWaitHandleSecurity (SafeWaitHandle,
AccessControlSections.Owner |
AccessControlSections.Group |
AccessControlSections.Access);
}
public static EventWaitHandle OpenExisting (string name)
{
return(OpenExisting (name, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify));
}
public static EventWaitHandle OpenExisting (string name, EventWaitHandleRights rights)
{
if (name == null) {
throw new ArgumentNullException ("name");
}
if ((name.Length == 0) ||
(name.Length > 260)) {
throw new ArgumentException ("name", Locale.GetText ("Invalid length [1-260]."));
}
MonoIOError error;
IntPtr handle = NativeEventCalls.OpenEvent_internal (name, rights, out error);
if (handle == (IntPtr)null) {
if (error == MonoIOError.ERROR_FILE_NOT_FOUND) {
throw new WaitHandleCannotBeOpenedException (Locale.GetText ("Named Event handle does not exist: ") + name);
} else if (error == MonoIOError.ERROR_ACCESS_DENIED) {
throw new UnauthorizedAccessException ();
} else {
throw new IOException (Locale.GetText ("Win32 IO error: ") + error.ToString ());
}
}
return(new EventWaitHandle (handle));
}
public static bool TryOpenExisting (string name, out EventWaitHandle result)
{
return TryOpenExisting (
name, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, out result);
}
public static bool TryOpenExisting (string name, EventWaitHandleRights rights,
out EventWaitHandle result)
{
if (name == null) {
throw new ArgumentNullException ("name");
}
if ((name.Length == 0) || (name.Length > 260)) {
throw new ArgumentException ("name", Locale.GetText ("Invalid length [1-260]."));
}
MonoIOError error;
IntPtr handle = NativeEventCalls.OpenEvent_internal (name, rights, out error);
if (handle == (IntPtr)null) {
result = null;
return false;
}
result = new EventWaitHandle (handle);
return true;
}
#else
public EventWaitHandle (bool initialState, EventResetMode mode, string name)
{
throw new NotSupportedException ();
}
public EventWaitHandle (bool initialState, EventResetMode mode,
string name, out bool createdNew)
{
throw new NotSupportedException ();
}
public EventWaitHandle (bool initialState, EventResetMode mode,
string name, out bool createdNew,
EventWaitHandleSecurity eventSecurity)
{
throw new NotSupportedException ();
}
public static EventWaitHandle OpenExisting (string name)
{
throw new NotSupportedException ();
}
public static EventWaitHandle OpenExisting (string name, EventWaitHandleRights rights)
{
throw new NotSupportedException ();
}
public static bool TryOpenExisting (string name, out EventWaitHandle result)
{
throw new NotSupportedException ();
}
public static bool TryOpenExisting (string name, EventWaitHandleRights rights,
out EventWaitHandle result)
{
throw new NotSupportedException ();
}
#endif
public bool Reset ()
{
/* This needs locking since another thread could dispose the handle */
lock (this) {
CheckDisposed ();
return NativeEventCalls.ResetEvent (SafeWaitHandle);
}
}
public bool Set ()
{
lock (this) {
CheckDisposed ();
return NativeEventCalls.SetEvent (SafeWaitHandle);
}
}
internal void CheckDisposed ()
{
if (disposed)
throw new ObjectDisposedException (GetType ().FullName);
}
bool disposed;
protected override void Dispose(bool explicitDisposing)
{
base.Dispose (explicitDisposing);
disposed = true;
}
#if !NET_2_1
public void SetAccessControl (EventWaitHandleSecurity eventSecurity)
{
if (null == eventSecurity)
throw new ArgumentNullException ("eventSecurity");
eventSecurity.PersistModifications (SafeWaitHandle);
}
#endif
}
}

View File

@@ -206,7 +206,7 @@ namespace System.Threading
}
}
#if !NET_2_1
#if !MOBILE
public void SetAccessControl (MutexSecurity mutexSecurity)
{
if (null == mutexSecurity)

View File

@@ -45,7 +45,7 @@ namespace System.Threading
internal static class NativeEventCalls
{
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern IntPtr CreateEvent_internal(bool manual,bool initial,string name, out bool created);
public static extern IntPtr CreateEvent_internal (bool manual, bool initial, string name, out int errorCode);
public static bool SetEvent (SafeWaitHandle handle)
{
@@ -82,7 +82,7 @@ namespace System.Threading
#if !MOBILE
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern IntPtr OpenEvent_internal (string name, EventWaitHandleRights rights, out MonoIOError error);
public static extern IntPtr OpenEvent_internal (string name, EventWaitHandleRights rights, out int errorCode);
#endif
}
}

View File

@@ -65,7 +65,6 @@ namespace System.Threading {
/* start_notify is used by the runtime to signal that Start()
* is ok to return
*/
private IntPtr start_notify;
private IntPtr stack_ptr;
private UIntPtr static_data; /* GC-tracked */
private IntPtr runtime_thread_info;
@@ -90,12 +89,19 @@ namespace System.Threading {
private IntPtr interrupt_on_stop;
private IntPtr flags;
private IntPtr thread_pinning_ref;
private IntPtr abort_protected_block_count;
/*
* These fields are used to avoid having to increment corlib versions
* when a new field is added to the unmanaged MonoThread structure.
*/
private IntPtr unused1;
private IntPtr unused2;
/* This is used only to check that we are in sync between the representation
* of MonoInternalThread in native and InternalThread in managed
*
* DO NOT RENAME! DO NOT ADD FIELDS AFTER! */
private IntPtr last;
#endregion
#pragma warning restore 169, 414, 649
@@ -116,15 +122,12 @@ namespace System.Threading {
private InternalThread internal_thread;
object m_ThreadStartArg;
object pending_exception;
int priority = (int) ThreadPriority.Normal;
#endregion
#pragma warning restore 414
IPrincipal principal;
int principal_version;
bool current_culture_set;
bool current_ui_culture_set;
CultureInfo current_culture;
CultureInfo current_ui_culture;
// the name of current_thread is
// important because they are used by the runtime.
@@ -132,9 +135,6 @@ namespace System.Threading {
[ThreadStatic]
static Thread current_thread;
static internal CultureInfo default_culture;
static internal CultureInfo default_ui_culture;
// can be both a ThreadStart and a ParameterizedThreadStart
private MulticastDelegate m_Delegate;
@@ -339,54 +339,6 @@ namespace System.Threading {
}
}
//[MethodImplAttribute (MethodImplOptions.InternalCall)]
//private static extern int current_lcid ();
public CultureInfo CurrentCulture {
get {
CultureInfo culture = current_culture;
if (current_culture_set && culture != null)
return culture;
if (default_culture != null)
return default_culture;
current_culture = culture = CultureInfo.ConstructCurrentCulture ();
return culture;
}
[SecurityPermission (SecurityAction.Demand, ControlThread=true)]
set {
if (value == null)
throw new ArgumentNullException ("value");
value.CheckNeutral ();
current_culture = value;
current_culture_set = true;
}
}
public CultureInfo CurrentUICulture {
get {
CultureInfo culture = current_ui_culture;
if (current_ui_culture_set && culture != null)
return culture;
if (default_ui_culture != null)
return default_ui_culture;
current_ui_culture = culture = CultureInfo.ConstructCurrentUICulture ();
return culture;
}
set {
if (value == null)
throw new ArgumentNullException ("value");
current_ui_culture = value;
current_ui_culture_set = true;
}
}
public bool IsThreadPoolThread {
get {
return IsThreadPoolThreadInternal;
@@ -507,6 +459,12 @@ namespace System.Threading {
{
throw new PlatformNotSupportedException ("Thread.ResetAbort is not supported on the current platform.");
}
internal object AbortReason {
get {
throw new PlatformNotSupportedException ("Thread.ResetAbort is not supported on the current platform.");
}
}
#endif // MONO_FEATURE_THREAD_ABORT
[MethodImplAttribute (MethodImplOptions.InternalCall)]
@@ -722,11 +680,6 @@ namespace System.Threading {
return ManagedThreadId;
}
internal CultureInfo GetCurrentUICultureNoAppX ()
{
return CultureInfo.CurrentUICulture;
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern void GetStackTraces (out Thread[] threads, out object[] stack_frames);
@@ -756,5 +709,10 @@ namespace System.Threading {
throw new PlatformNotSupportedException ("Thread.Resume is not supported on the current platform.");
}
#endif
public void DisableComObjectEagerCleanup ()
{
throw new PlatformNotSupportedException ();
}
}
}