public static unsafe bool JoinImpl( ProcessHandle handle, SchedulerTime stop, bool *started) { return(Join(handle, stop, out *started)); }
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); }
public bool Join(SchedulerTime timeout) { if (threadState == ThreadState.Unstarted) { throw new ThreadStateException(); } return(joinEvent.WaitOne(timeout)); }
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); }
public static bool Join(ProcessHandle handle, SchedulerTime stop, out bool started) { unsafe { fixed(bool *startedPtr = &started) { return(JoinImpl(handle, stop, startedPtr)); } } }
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); }
//| <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)); } }
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); }
/// <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); }
/// /// <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)); }
/// <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); }
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)); }
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); }
public abstract TimeSpan OnTimerInterrupt(int affinity, SchedulerTime now);
public static extern void Sleep(SchedulerTime stop);
public bool WaitOne(DateTime stop) { SchedulerTime st = SchedulerTime.MinValue + (stop - DateTime.BootTime); return(WaitOne(st)); }
public static extern unsafe int WaitAny(SyncHandle *handles, int handleCount, SchedulerTime stop);
public override bool WaitOne(SchedulerTime stop) { return(SyncHandle.WaitOne(Handle, stop)); }
/// /// <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)); }
/// /// <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); }
/// /// <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)); }
/// /// <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); }
//| <include path='docs/doc[@for="WaitHandle.WaitOne1"]/*' /> public abstract bool WaitOne(SchedulerTime stop);
public abstract Thread RunPolicy( int affinity, Thread currentThread, ThreadState schedulerAction, SchedulerTime currentTime);
public abstract void OnThreadBlocked(Thread thread, SchedulerTime stop);
public static extern bool WaitOne(SyncHandle handle, SchedulerTime stop);