Simplify work item registration for internal work items
authorMarek Safar <marek.safar@gmail.com>
Wed, 9 Oct 2013 10:51:16 +0000 (12:51 +0200)
committerMarek Safar <marek.safar@gmail.com>
Wed, 9 Oct 2013 10:51:16 +0000 (12:51 +0200)
mcs/class/corlib/System.Threading.Tasks/TpScheduler.cs
mcs/class/corlib/System.Threading/ThreadPool.cs
mcs/class/corlib/System.Threading/Timer.cs

index c38a566e2cc3c64720e6e4cf6bd45a5829769b1f..e1c9a6842cae9abf024dd1dab3259146601b78bf 100644 (file)
@@ -50,7 +50,7 @@ namespace System.Threading.Tasks
                                return;
                        }
 
-                       ThreadPool.UnsafeQueueUserWorkItem (callback, task);
+                       ThreadPool.QueueWorkItem (callback, task);
                }
 
                static void TaskExecuterCallback (object obj)
index 05ba0fdfe514a30395f4a5e446fdd598250dd144..204386f9f70021579d9d200657030ef02dc4bd8f 100644 (file)
@@ -96,6 +96,12 @@ namespace System.Threading {
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                static extern void pool_queue (AsyncResult ares);
 
+               // TODO: It should be interface interface only to avoid extra allocation
+               internal static void QueueWorkItem (WaitCallback callBack, object state)
+               {
+                       pool_queue (new AsyncResult (callBack, state, false));
+               }
+
                public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
                                                                                WaitOrTimerCallback callBack,
                                                                                object state,
index 63358776056a619725b9684e8ad5935200d1efc2..dd32032436f9363d19827afc5e4df216edff9969 100644 (file)
@@ -337,7 +337,7 @@ namespace System.Threading
                                                        list.RemoveAt (i);
                                                        count--;
                                                        i--;
-                                                       ThreadPool.UnsafeQueueUserWorkItem (TimerCB, timer);
+                                                       ThreadPool.QueueWorkItem (TimerCB, timer);
                                                        long period = timer.period_ms;
                                                        long due_time = timer.due_time_ms;
                                                        bool no_more = (period == -1 || ((period == 0 || period == Timeout.Infinite) && due_time != Timeout.Infinite));