Esempio n. 1
0
 public static unsafe bool JoinImpl(
     ProcessHandle handle,
     SchedulerTime stop,
     bool *started)
 {
     return(Join(handle, stop, out *started));
 }
Esempio n. 2
0
        public override void OnThreadBlocked(Thread thread, SchedulerTime stop)
        {
            // Assert preconditions
            VTable.Assert(thread == Thread.CurrentThread);

            if (stop != SchedulerTime.MaxValue)
            {
                // Enqueue timer so that if it expires we will notice it right a way
                EnqueueTimer(thread, stop);
            }

            // Thread is blocked now - indicate this to dispatcher. Dispatcher will make
            // make sure that thread's scheduler is aware of the blockage
            ProcessorDispatcher.SwitchContext(ThreadState.Blocked);

            // We just got unblocked and happilly running. We need to remove ourselves
            // from the timer queue if we are unblocked by signal rather than by timeout
            if (thread.UnblockedBy != WaitHandle.WaitTimeout)
            {
                // One of our buddies unblocked us - remove the time out. Before we can
                // actually assert that we were indeed unblocked by someone.
                VTable.Assert(thread.UnblockedBy != WaitHandle.UninitWait);

                // Remove a timer from the timer queue and happilly continue!
                RemoveTimer(thread);
            }
        }
        //| <include path='docs/doc[@for="WaitHandle.WaitOne1"]/*' />
        public override bool WaitOne(SchedulerTime stop)
        {
            bool b = SyncHandle.WaitOne(handle, stop);

            GC.KeepAlive(this);
            return(b);
        }
Esempio n. 4
0
 public bool Join(SchedulerTime timeout)
 {
     if (threadState == ThreadState.Unstarted)
     {
         throw new ThreadStateException();
     }
     return(joinEvent.WaitOne(timeout));
 }
Esempio n. 5
0
        public static bool Join(ThreadHandle handle, SchedulerTime stop)
        {
            Thread thread = HandleTable.GetHandle(handle.id) as Thread;

            bool ret = thread.Join(stop);

            Tracing.Log(Tracing.Debug, "ThreadHandle.Join(id={0:x8}, stop=)", handle.id);

            return(ret);
        }
Esempio n. 6
0
 public static bool Join(ProcessHandle handle,
                         SchedulerTime stop,
                         out bool started)
 {
     unsafe
     {
         fixed(bool *startedPtr = &started)
         {
             return(JoinImpl(handle, stop, startedPtr));
         }
     }
 }
Esempio n. 7
0
        public static bool WaitOne(SyncHandle handle,
                                   SchedulerTime stop)
        {
            //
            // Convert the handle to a waitHandle; wait on the waitHandle.
            //
            WaitHandle waitHandle = HandleTable.GetHandle(handle.id) as WaitHandle;
            bool       ret        = waitHandle.WaitOne(stop);

            Tracing.Log(Tracing.Debug, "SyncHandle.WaitOne(id={0:x8}, stop=)",
                        handle.id);

            return(ret);
        }
Esempio n. 8
0
        //| <include path='docs/doc[@for="WaitHandleHandle.WaitAny"]/*' />
        public static unsafe int WaitAny(WaitHandle[] waitHandles,
                                         SchedulerTime stop)
        {
            SyncHandle[] handles = Thread.CurrentThread.GetSyncHandles(waitHandles.Length);
            for (int i = 0; i < waitHandles.Length; i++)
            {
                handles[i] = waitHandles[i].Handle;
            }

            fixed(SyncHandle *array = &handles[0])
            {
                return(SyncHandle.WaitAny(array, waitHandles.Length, stop));
            }
        }
Esempio n. 9
0
        public static bool Join(ProcessHandle handle,
                                SchedulerTime stop,
                                out bool started)
        {
            Tracing.Log(Tracing.Debug, "ProcessHandle.Join(id={0:x8})",
                        handle.id);

            //
            // Convert the handle to a process; call Join method.
            //
            Process process = HandleTable.GetHandle(handle.id) as Process;
            bool    ret     = process.Join(stop, out started);

            return(ret);
        }
Esempio n. 10
0
        /// <summary>
        /// Try to enter the monitor, giving up if it cannot be
        /// entered after a timeout.
        /// </summary>
        internal bool TryEnter(SchedulerTime stop)
        {
            if (mutex.IsOwnedByCurrentThread())
            {
                depth++;
                return(true);
            }

            if (mutex.AcquireMutex(stop))
            {
                depth = 1;
                return(true);
            }
            return(false);
        }
Esempio n. 11
0
        ///
        /// <summary>
        ///     Acquire mutex with time out specified
        ///</summary>
        ///
        /// <param name="stop">Specified time out</param>
        ///
        public bool AcquireMutex(SchedulerTime stop)
        {
            bool   result        = true;;
            Thread currentThread = Thread.CurrentThread;

            // If we own the mutex we can by pass the wait - do wait only if we don't own
            if (this.owner != currentThread)
            {
                result = WaitOne(stop);
            }
            else
            {
                // Don't forget to update recursion counter
                this.acquired++;
            }


            return(result);
        }
        public override Thread RunPolicy(
            int schedulerAffinity,
            int runningThreadAffinity,
            Thread currentThread,
            ThreadState schedulerAction,
            SchedulerTime currentTime)
        {
            // Assert preconditions: current thread can be either NULL or its base scheduler
            // should be the same as specified by affinity
            VTable.Assert(currentThread == null ||
                          currentThread.Affinity == schedulerAffinity);

            // Use affinity to derive actual scheduler
            return(schedulers[schedulerAffinity].RunPolicy(
                       schedulerAffinity,
                       runningThreadAffinity,
                       currentThread,
                       schedulerAction,
                       currentTime));
        }
Esempio n. 13
0
        /// <summary>
        /// Wait within the monitor for a Pulse.
        /// </summary>
        internal bool Wait(SchedulerTime stop)
        {
            Thread currentThread = Thread.CurrentThread;

            if (!mutex.IsOwnedByCurrentThread())
            {
                DebugStub.Break();
                throw new SynchronizationLockException("Monitor not held on Wait");
            }

            int rememberedDepth = depth;

            depth = 0;

            // Add me onto the waiting list.
            Enqueue(currentThread);

            // Exit the monitor
            mutex.ReleaseMutex();

            // Wait
            currentThread.WaitForMonitor(stop);

            // Re-enter the monitor
            mutex.AcquireMutex();
            depth = rememberedDepth;

            bool success = !Remove(currentThread);

            if (!success && stop == SchedulerTime.MaxValue)
            {
                VTable.DebugBreak();
            }

            return(success);
        }
Esempio n. 14
0
        public static unsafe int WaitAny(SyncHandle *handles,
                                         int handleCount,
                                         SchedulerTime stop)
        {
            WaitHandle[] waits = Thread.CurrentThread.GetSyncHandles(handleCount);
            for (int i = 0; i < handleCount; i++)
            {
                waits[i] = HandleTable.GetHandle(handles[i].id) as WaitHandle;;
            }

            int ret = WaitHandle.WaitAny(waits, handleCount, stop);

            Tracing.Log(Tracing.Debug,
                        "SyncHandle.WaitAny(handles={0:x8}, count={1}, stop=) = {2}",
                        (UIntPtr)handles,
                        (UIntPtr) unchecked ((uint)handleCount),
                        (UIntPtr) unchecked ((uint)ret));

            for (int i = 0; i < handleCount; i++)
            {
                waits[i] = null;
            }
            return(ret);
        }
 public override TimeSpan OnTimerInterrupt(int affinity, SchedulerTime now)
 {
     return(schedulers[affinity].OnTimerInterrupt(affinity, now));
 }
Esempio n. 16
0
 public static extern bool Join(ThreadHandle thread,
                                SchedulerTime stop);
 ///
 /// <summary>
 ///     Block thread - put a thread on block queue and retrieve next thread to run
 /// </summary>
 ///
 /// <param name="thread">Thread that blocks </param>
 /// <param name="stop">Amount of time for the thread to be blocked</param>
 ///
 public override void OnThreadBlocked(Thread thread, SchedulerTime stop)
 {
     schedulers[thread.Affinity].OnThreadBlocked(thread, stop);
 }
Esempio n. 18
0
 public abstract TimeSpan OnTimerInterrupt(int affinity, SchedulerTime now);
Esempio n. 19
0
 public static extern void Sleep(SchedulerTime stop);
Esempio n. 20
0
        public bool WaitOne(DateTime stop)
        {
            SchedulerTime st = SchedulerTime.MinValue + (stop - DateTime.BootTime);

            return(WaitOne(st));
        }
Esempio n. 21
0
 public static extern unsafe int WaitAny(SyncHandle *handles,
                                         int handleCount,
                                         SchedulerTime stop);
Esempio n. 22
0
 public override bool WaitOne(SchedulerTime stop)
 {
     return(SyncHandle.WaitOne(Handle, stop));
 }
Esempio n. 23
0
 ///
 /// <summary>
 /// Wait on a set of handles until one of them becomes signaled with a specified time out.
 /// </summary>
 ///
 /// <param name="waitHandles">Wait handles to wait on </param>
 /// <param name="stop">Time out </param>
 ///
 public static int WaitAny(WaitHandle[] waitHandles, SchedulerTime stop)
 {
     return(WaitAny(waitHandles, waitHandles.Length, stop));
 }
Esempio n. 24
0
        ///
        /// <summary>
        /// Wait on a set of handles until one of them becomes signaled with a specified time out.
        /// </summary>
        ///
        /// <param name="waitHandles">Wait handles to wait on </param>
        /// <param name="waitHandlesCount">A number of wait handles to wait on </param>
        /// <param name="stop">Time out </param>
        ///
        public static int WaitAny(
            WaitHandle[]        waitHandles,
            int waitHandlesCount,
            SchedulerTime stop)
        {
            // Retrieve current thread information
            Thread currentThread = Thread.CurrentThread;
            Thread target        = null;
            int    unblockedBy;

            ThreadEntry[] entries = currentThread.GetWaitEntries(
                waitHandlesCount);

            // Before we attempting to enqueue ourselves into the wait queues make sure
            // we disable abort
            currentThread.DelayStop(true);

            // Perepare for a wait - enqueue ourselves into every wait handle
            unblockedBy = PreWaitAnyInternal(currentThread,
                                             waitHandles,
                                             entries,
                                             waitHandlesCount);

            // If we are in the process of blocking: Block
            if (UninitWait == unblockedBy)
            {
                // Allow thread to be aborted at this point
                currentThread.DelayStop(false);

                // Update thread WaitFor information: Indicate every one that we waiting -
                // scheduler ones wakes us up is responsible for cleaning up wait information
                // by using ResetWaitInfo call
                //currentThread.UpdateWaitInfo (waitHandles,
                //                        waitHandlesCount,
                //                        entries,
                //                        stop);

                // Write out log record
                Monitoring.Log(Monitoring.Provider.Thread,
                               (ushort)ThreadEvent.WaitAny, 0,
                               (uint)stop.Ticks, (uint)(stop.Ticks >> 32),
                               (uint)currentThread.threadIndex, 0, 0);


                // Let scheduler know that we are blocking
                Kernel.TheScheduler.OnThreadBlocked(currentThread, stop);

                // Our thread is about to run so we can disassociate it from wait handles
                PostWaitAnyInternal(currentThread,
                                    waitHandles,
                                    entries,
                                    waitHandlesCount);

                // Thread has the unblocked information
                unblockedBy = currentThread.UnblockedBy;
            }

            // Assert post condition: unblocked by can't be uninitialized
            VTable.Assert(unblockedBy != WaitHandle.UninitWait);

            // If there are wait handles and we were unblocked by not the timeout
            if (waitHandles != null && unblockedBy >= 0 &&
                unblockedBy < waitHandlesCount)
            {
                // Complete wait
                waitHandles[unblockedBy].CompleteWait(currentThread);

                // When we were signalged delay abort has been set - now we can turn it off
                // For mutex complete wait will add delay abort. It will remain on until
                // mutex is released
                currentThread.DelayStop(false);
            }

            // Make sure that we pay attention to abort
            currentThread.ProcessAbortIfRequired();

            return(unblockedBy);
        }
Esempio n. 25
0
        ///
        /// <summary>
        /// Wait on a set of handles until one of them becomes signaled with a specified time out.
        /// </summary>
        ///
        /// <param name="waitHandles">Wait handles to wait on </param>
        /// <param name="timeout">Time out </param>
        ///
        public static int WaitAny(WaitHandle[] waitHandles, TimeSpan timeout)
        {
            SchedulerTime stop = SchedulerTime.Now + timeout;

            return(WaitAny(waitHandles, waitHandles.Length, stop));
        }
Esempio n. 26
0
 ///
 /// <summary>
 /// Wait on a handle with a specified time out.
 /// </summary>
 ///
 /// <param name="stop">Time out </param>
 ///
 internal bool WaitOne(SchedulerTime stop)
 {
     return(WaitAny(singleHandle, 1, stop) != WaitTimeout);
 }
Esempio n. 27
0
 //| <include path='docs/doc[@for="WaitHandle.WaitOne1"]/*' />
 public abstract bool WaitOne(SchedulerTime stop);
Esempio n. 28
0
 public abstract Thread RunPolicy(
     int affinity,
     Thread currentThread,
     ThreadState schedulerAction,
     SchedulerTime currentTime);
Esempio n. 29
0
 public abstract void OnThreadBlocked(Thread thread, SchedulerTime stop);
Esempio n. 30
0
 public static extern bool WaitOne(SyncHandle handle,
                                   SchedulerTime stop);