private static int WaitAnyRawHelper(ClrSyncManager manager, Original::Task[] tasks, int millisecondsTimeout, CancellationToken cancellationToken) { int ret; while (true) { manager.SetMethodInfo("Task.WaitAny"); manager.AggregateSyncVarAccess(tasks, MSyncVarOp.WAIT_ANY); try { ret = Original::Task.WaitAny(tasks, 0, cancellationToken); } catch (Exception e) { manager.CommitSyncVarAccess(); throw e; } if (ret != -1) { break; // operation succeeded } if (millisecondsTimeout >= 0) { manager.MarkTimeout(); manager.CommitSyncVarAccess(); manager.TaskYield(); return(ret); } manager.LocalBacktrack(); } manager.CommitSyncVarAccess(); return(ret); }
public static int WaitGeneralRaw( ClrSyncManager manager, Original::WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext, string op) { if (waitHandles == null) { throw new ArgumentNullException(); } foreach (var h in waitHandles) { if (h == null) { throw new ArgumentNullException(); } } if (millisecondsTimeout < Timeout.Infinite) { throw new ArgumentOutOfRangeException(); } int ret; while (true) { manager.SetMethodInfo("WaitHandle." + op); manager.AggregateSyncVarAccess( waitHandles, (op == "WaitAll") ? MSyncVarOp.WAIT_ALL : MSyncVarOp.WAIT_ANY); try { ret = (op == "WaitAll" ? (Original::WaitHandle.WaitAll(waitHandles, 0, false) ? 0 : Original.WaitHandle.WaitTimeout) : (Original::WaitHandle.WaitAny(waitHandles, 0, false))); } catch (Exception e) { manager.CommitSyncVarAccess(); throw e; } if (ret != Original::WaitHandle.WaitTimeout) { break; // operation succeeded } if (millisecondsTimeout >= 0) { manager.MarkTimeout(); manager.CommitSyncVarAccess(); manager.TaskYield(); return(ret); } manager.LocalBacktrack(); } manager.CommitSyncVarAccess(); return(ret); }
public SimplePartitioner(ClrSyncManager manager, long start, long end, long split, Func <long, T> get, bool keysNormalized) : base(false, false, keysNormalized) { this.manager = manager; this.min = start; this.max = end - 1; this.split = split; this.get = get; this.forwardpos = min; this.backwardpos = max; barrier = new OThreading.Barrier(2); semaphore = new OThreading.Semaphore(0, 1); mainthread = OThreading.Thread.CurrentThread; //global::System.Console.WriteLine("SimplePartitioner constructed by " + OThreading.Thread.CurrentThread.ManagedThreadId); }
private static bool JoinRaw(Original::Thread t, ClrSyncManager manager, int millisecondsTimeout) { if (millisecondsTimeout < Timeout.Infinite) { throw new ArgumentOutOfRangeException(); } bool ret; while (true) { manager.SetMethodInfo("Thread.Join(" + millisecondsTimeout + ")"); manager.SyncVarAccess(t, MSyncVarOp.TASK_JOIN); try { ret = t.Join(0); } catch (Exception e) { manager.CommitSyncVarAccess(); throw e; } if (ret) { break; // join succeeded } if (millisecondsTimeout >= 0) { manager.MarkTimeout(); manager.CommitSyncVarAccess(); manager.TaskYield(); return(ret); } manager.LocalBacktrack(); } manager.CommitSyncVarAccess(); return(ret); }