[corlib] Allow SynchronizationContext.Current to work on MfA
authorJonathan Pryor <jonpryor@vt.edu>
Fri, 1 Jun 2012 16:48:53 +0000 (12:48 -0400)
committerJonathan Pryor <jonpryor@vt.edu>
Fri, 1 Jun 2012 16:48:53 +0000 (12:48 -0400)
For the main (UI) thread, make SynchronizationContext.Current return
the Android.App.Application.SynchronizationContext property.

mcs/class/corlib/System.Threading/SynchronizationContext.cs
mcs/class/corlib/System/AndroidPlatform.cs [new file with mode: 0644]
mcs/class/corlib/corlib.dll.sources

index cb7369fb0ff1aa3179c45b56c47beb95d5e30154..3bbb7569ff35b7321013edd7bad4646b6fcef246 100644 (file)
@@ -50,7 +50,10 @@ namespace System.Threading
                public static SynchronizationContext Current
                {
                        get {
-#if NET_2_1
+#if MONODROID
+                               if (currentContext == null)
+                                       currentContext = AndroidPlatform.GetDefaultSyncContext ();
+#elif NET_2_1
                                if (currentContext == null)
                                        currentContext = new SynchronizationContext ();
 #endif
diff --git a/mcs/class/corlib/System/AndroidPlatform.cs b/mcs/class/corlib/System/AndroidPlatform.cs
new file mode 100644 (file)
index 0000000..d9e818b
--- /dev/null
@@ -0,0 +1,53 @@
+// 
+// System.AndroidPlatform.cs
+//
+// Author:
+//   Jonathan Pryor (jonp@xamarin.com)
+//
+// Copyright (C) 2012 Xamarin Inc (http://xamarin.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.
+//
+
+#if MONODROID
+using System.Threading;
+
+namespace System {
+
+       internal class AndroidPlatform {
+
+               static readonly Func<SynchronizationContext> getDefaultSyncContext;
+
+               static AndroidPlatform ()
+               {
+                       getDefaultSyncContext = (Func<SynchronizationContext>)
+                               Delegate.CreateDelegate (typeof(Func<SynchronizationContext>), 
+                                               Type.GetType ("Android.Runtime.AndroidEnvironment, Mono.Android", true)
+                                               .GetMethod ("GetDefaultSyncContext", 
+                                                       System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic));
+               }
+
+               internal static SynchronizationContext GetDefaultSyncContext ()
+               {
+                       return getDefaultSyncContext ();
+               }
+       }
+}
+#endif
index 88fa8759de379db5bd13d51a55c055891e277835..212fd2bb4af23b762dfd7958573730dedd0dc13e 100644 (file)
@@ -79,6 +79,7 @@ Mono.Xml/SecurityParser.cs
 System/AccessViolationException.cs
 System/ActivationContext.cs
 System/Activator.cs
+System/AndroidPlatform.cs
 System/AppDomain.cs
 System/AppDomainInitializer.cs
 System/AppDomainManager.cs