Пример #1
0
        public static bool Unregister(Original.RegisteredWaitHandle handle, Original.WaitHandle waitObject)
        {
            return(Helper.SimpleWrap <bool>(
                       delegate(ClrSyncManager manager)
            {
                Original.WaitHandle cancelObject = null;
                Helper.WaitOrTimerCallbackRoutineArg p = manager.rwhToInfo[handle];
                manager.SetMethodInfo("RegisteredWaitHandle.Unregister");
                manager.SyncVarAccess(p, MSyncVarOp.RWVAR_READWRITE);
                if (!p.canceled)
                {
                    p.canceled = true;
                    p.onCancellation = waitObject;
                    if (p.finished)
                    {
                        cancelObject = waitObject;
                    }
                }
                manager.CommitSyncVarAccess();

                global::Microsoft.ManagedChess.MChessChess.LeaveChess();
                if (cancelObject != null)
                {
                    __Substitutions.System.Threading.EventWaitHandle.Set((Original.EventWaitHandle)cancelObject);
                }
                global::Microsoft.ManagedChess.MChessChess.EnterChess();

                return handle.Unregister(null);
            },
                       delegate()
            {
                return handle.Unregister(waitObject);
            }
                       ));
        }
Пример #2
0
 public static Original.RegisteredWaitHandle UnsafeRegisterWaitForSingleObject(
     Original.WaitHandle waitObject,
     Original.WaitOrTimerCallback callBack,
     object state,
     TimeSpan ts,
     bool executeOnlyOnce)
 {
     return(RegisterWaitForSingleObjectHelper(waitObject, callBack, state, (long)ts.TotalMilliseconds, executeOnlyOnce, false));
 }
Пример #3
0
 public static Original.RegisteredWaitHandle UnsafeRegisterWaitForSingleObject(
     Original.WaitHandle waitObject,
     Original.WaitOrTimerCallback callBack,
     object state,
     uint millisecondsTimeOutInterval,
     bool executeOnlyOnce)
 {
     return(RegisterWaitForSingleObjectHelper(waitObject, callBack, state, millisecondsTimeOutInterval, executeOnlyOnce, false));
 }
Пример #4
0
 static Original.RegisteredWaitHandle RegisterWaitForSingleObjectHelper(
     Original.WaitHandle waitObject,
     Original.WaitOrTimerCallback callBack,
     object state,
     long millisecondsTimeOutInterval,
     bool executeOnlyOnce,
     bool isSafe)
 {
     return(Helper.SimpleWrap <Original.RegisteredWaitHandle>(
                delegate(ClrSyncManager manager)
     {
         Helper.WaitOrTimerCallbackRoutineArg p = new Helper.WaitOrTimerCallbackRoutineArg();
         p.s = new Original::Semaphore(0, 1);
         p.a = new AutoResetEvent(false);
         p.waitObject = waitObject;
         p.callback = callBack;
         p.state = state;
         p.millisecondsTimeOutInterval = millisecondsTimeOutInterval;
         p.executeOnlyOnce = executeOnlyOnce;
         p.canceled = false;
         p.onCancellation = null;
         p.finished = false;
         Original.RegisteredWaitHandle returnValue =
             isSafe ? Original.ThreadPool.RegisterWaitForSingleObject(new AutoResetEvent(true),
                                                                      RegisterWaitHelper.RegisterWaitForSingleObjectWrapper(manager), p, Timeout.Infinite, true)
                        : Original.ThreadPool.UnsafeRegisterWaitForSingleObject(new AutoResetEvent(true), RegisterWaitHelper.RegisterWaitForSingleObjectWrapper(manager), p, Timeout.Infinite, true);
         if (returnValue != null)
         {
             p.a.WaitOne();
             manager.rwhToInfo[returnValue] = p;
             ChessTask child = manager.TaskFork();
             manager.RegisterTaskSemaphore(child, p.s, false);
             manager.TaskResume(child);
         }
         return returnValue;
     },
                delegate()
     {
         return isSafe ? Original.ThreadPool.RegisterWaitForSingleObject(waitObject, callBack, state, millisecondsTimeOutInterval, executeOnlyOnce)
                           : Original.ThreadPool.UnsafeRegisterWaitForSingleObject(waitObject, callBack, state, millisecondsTimeOutInterval, executeOnlyOnce);
     }
                ));
 }