internal Thread(ThreadStart threadStart, ThreadPriority priority, SIP sip, TaskHandle task) { Task = task; _threadStart = threadStart; _priority = priority; _sip = sip; }
public void Acquire() { TaskHandle currentTask = SystemCalls.GetCurrentTask(); //Logging.Trace("Task " + currentTask + " acquiring lock " + GetHashCode()); while (_owner != null && _owner != currentTask) { //Logging.Trace("Task " + currentTask + " failed to acquire lock " + GetHashCode()); _waitingOwners.Push(currentTask); SystemCalls.BlockTask(currentTask); SystemCalls.Yield(); } _owner = currentTask; //Logging.Trace("Task " + currentTask + " acquired lock " + GetHashCode()); }
public bool TryAcquire() { TaskHandle currentTask = SystemCalls.GetCurrentTask(); if (_owner == null) { _owner = currentTask; return true; } else if (_owner == currentTask) { return true; } return false; }
public void Release() { TaskHandle currentTask = SystemCalls.GetCurrentTask(); if (_owner == currentTask) { _owner = null; if (_waitingOwners.Length > 0) { // here we call ScheduleTask instead of Unblock because we Yielded the task SystemCalls.ScheduleTask(_owner = _waitingOwners.Shift()); } } else { throw new Exception("Cannot release lock. Current thread is not owner"); } }
public extern Thread this[TaskHandle task] { [XaeiOSMethodImpl(MethodImplOptions.Inline, Implementation = "{this}[{0}]")] get; [XaeiOSMethodImpl(MethodImplOptions.Inline, Implementation = "{this}[{0}] = {1}")] set; }
public static extern void InjectException(TaskHandle task, Exception exception);
private void InternalCallback(TaskHandle task, string taskName, var returnValue, TaskExitStatus exitStatus) { //Logging.Trace("Thread internal callback: " + this + ":" + this.Name); _running = false; //Logging.Trace("Unregistering thread: " + this + ":" + this.Name); ThreadManager.UnregisterThread(this); if (exitStatus == TaskExitStatus.UnhandledException) { _unhandledException = returnValue.Cast<Object>() as Exception; } else if (exitStatus == TaskExitStatus.CriticalError) { _unhandledException = new ExecutionEngineException(returnValue.NativeToString()); } if (Callback != null) { // TODO: Use the SIP thread pool to run this callback Callback(); } else { if (_unhandledException != null) { Console.WriteLine("An unhandled exception occurred in thread: " + this + ": " + _unhandledException + "\n" + _unhandledException.StackTrace); } } }
internal static Thread CreateSystemThread(ThreadPriority priority, SIP sip, TaskHandle kernelTask, string name) { Thread kernelThread = new Thread(); kernelThread.Task = kernelTask; kernelThread._priority = priority; kernelThread._sip = sip; kernelThread._name = name; return kernelThread; }
public static void InjectException(TaskHandle task, Exception exception) { GetTask(task).InjectedException = (XaeiOSException)exception; }
public static extern void ScheduleTask(TaskHandle task);
public Lock() { _owner = null; _waitingOwners = new NativeArray<TaskHandle>(); }
public static void StartTask(TaskHandle task) { Scheduler.StartTask(GetTask(task)); }
public static void ScheduleTask(TaskHandle task) { Scheduler.ScheduleTaskChecked(GetTask(task)); }
public static void KillTask(TaskHandle task) { Scheduler.KillTask(GetTask(task)); }
public MonitorLock() { _owner = null; _waitingOwners = new NativeArray<TaskHandle>(); _count = 0; }
public bool TryAcquire() { TaskHandle currentTask = SystemCalls.GetCurrentTask(); if (_owner == null) { _owner = currentTask; _count++; //Logging.Trace("Task " + currentTask + " acquired monitor lock " + GetHashCode() + " - count: " + _count); return true; } else if (_owner == currentTask) { _count++; //Logging.Trace("Task " + currentTask + " acquired monitor lock " + GetHashCode() + " - count: " + _count); return true; } return false; }
public static extern void StartTask(TaskHandle task);
public extern void Remove(TaskHandle task);
public WaitingTask(TaskHandle task, int resources) { Task = task; Resources = resources; }
public static extern void BlockTask(TaskHandle task);
private static Task GetTask(TaskHandle task) { Task t = Task.GetTaskById(var.Cast<TaskHandle, int>(task)); if (t == null) { throw new Exception("Task with " + task + " does not exist."); } return t; }
public static extern void KillTask(TaskHandle task);
public static void BlockTask(TaskHandle task) { Scheduler.BlockTask(GetTask(task)); }
public void Cancel() { Logging.Trace("Unblocker::Cancel()"); Global.ClearTimeout(TimeoutId); TimeoutId = null; Task = null; }