Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
 private void EndMainThread()
 {
     // join child thread
     while (true)
     {
         manager.SyncVarAccess(taskid, MSyncVarOp.TASK_JOIN);
         if (childdone)
         {
             break; // done
         }
         manager.LocalBacktrack();
     }
     manager.CommitSyncVarAccess();
 }
Пример #4
0
        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);
        }