5 // Jérémie Laval <jeremie dot laval at xamarin dot com>
6 // Marek Safar <marek.safar@gmail.com>
8 // Copyright (c) 2011 Jérémie "Garuma" Laval
9 // Copyright 2012 Xamarin Inc (http://www.xamarin.com).
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
13 // of this software and associated documentation files (the "Software"), to deal
14 // in the Software without restriction, including without limitation the rights
15 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 // copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
19 // The above copyright notice and this permission notice shall be included in
20 // all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
34 using System.Collections.Generic;
36 namespace System.Threading.Tasks
38 sealed class TpScheduler: TaskScheduler
40 static readonly WaitCallback callback = TaskExecuterCallback;
42 protected internal override void QueueTask (Task task)
44 if ((task.CreationOptions & TaskCreationOptions.LongRunning) != 0) {
45 var thread = new Thread (l => ((Task)l).Execute ()) {
53 ThreadPool.UnsafeQueueUserWorkItem (callback, task);
56 static void TaskExecuterCallback (object obj)
58 Task task = (Task)obj;
62 protected override IEnumerable<Task> GetScheduledTasks ()
64 throw new NotImplementedException();
67 [MonoTODO ("Tasks cannot be dequeued")]
68 protected internal override bool TryDequeue (Task task)
73 protected override bool TryExecuteTaskInline (Task task, bool taskWasPreviouslyQueued)
75 if (taskWasPreviouslyQueued && !TryDequeue (task))
78 return TryExecuteTask(task);