public void CancelThreads() { while (this.WaitingThreads.Count > 0) { KThread thread = this.WaitingThreads.Dequeue(); thread.Wake(unchecked ((int)0x800201b5)); // SCE_KERNEL_ERROR_WAIT_DELETE } }
public void Exit(int code) { State = KThreadState.Dead; this.RemoveFromSchedule(); ExitCode = code; while (ExitWaiters.Count > 0) { KThread thread = ExitWaiters.Dequeue(); thread.Wake(0); } }
public void AddMessage(int message) { if (this.WaitingThreads.Count > 0 && this.Messages.Count == 0) { KThread thread = this.WaitingThreads.Dequeue(); unsafe { *(int *)Kernel.MemorySystem.Translate(thread.WaitAddress) = message; } thread.Wake(); return; } this.Messages.Enqueue(message); }
public void Unlock() { // Try to wake threads if (WaitingThreads.Count > 0) { KThread thread = WaitingThreads.Dequeue(); thread.Wake(0); // Remain locked, as that thread now holds the lock Kernel.Schedule(); } else { Locked = false; } }
public bool Signal() { bool needsSwitch = false; LinkedListEntry <KThread> e = WaitingThreads.HeadEntry; while (e != null) { LinkedListEntry <KThread> next = e.Next; KThread thread = e.Value; Debug.Assert(thread != null); Debug.Assert(thread.WaitingOn == KThreadWait.Event); Debug.Assert(thread.WaitHandle == this); bool matches = this.Matches(thread.WaitArgument, thread.WaitEventMode); if (matches == true) { // Finish wait if (thread.WaitAddress != 0x0) { unsafe { uint *poutBits = ( uint * )Kernel.MemorySystem.Translate(thread.WaitAddress); * poutBits = this.Value; } } this.Clear(thread.WaitArgument, thread.WaitEventMode); WaitingThreads.Remove(e); // Wake thread thread.Wake(0); needsSwitch = true; } e = next; } return(needsSwitch); }
private bool WakeWaiter() { KThread waiter = WaitingThreads.Dequeue(); if (waiter == null) { return(false); } // Allocate a new block for the waiter KMemoryBlock block = this.Allocate(); Debug.Assert(waiter.WaitAddress != 0); unsafe { uint *pdata = ( uint * )Kernel.MemorySystem.Translate(waiter.WaitAddress); * pdata = block.Address; } waiter.Wake(0); return(true); }