示例#1
0
文件: Thread.cs 项目: sidecut/xaeios
 internal Thread(ThreadStart threadStart, ThreadPriority priority, SIP sip, TaskHandle task)
 {
     Task = task;
     _threadStart = threadStart;
     _priority = priority;
     _sip = sip;
 }
示例#2
0
文件: Lock.cs 项目: sidecut/xaeios
 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());
 }
示例#3
0
文件: Lock.cs 项目: sidecut/xaeios
 public bool TryAcquire()
 {
     TaskHandle currentTask = SystemCalls.GetCurrentTask();
     if (_owner == null)
     {
         _owner = currentTask;
         return true;
     }
     else if (_owner == currentTask)
     {
         return true;
     }
     return false;
 }
示例#4
0
文件: Lock.cs 项目: sidecut/xaeios
 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");
     }
 }
示例#5
0
 public extern Thread this[TaskHandle task]
 {
     [XaeiOSMethodImpl(MethodImplOptions.Inline, Implementation = "{this}[{0}]")]
     get;
     [XaeiOSMethodImpl(MethodImplOptions.Inline, Implementation = "{this}[{0}] = {1}")]
     set;
 }
示例#6
0
 public static extern void InjectException(TaskHandle task, Exception exception);
示例#7
0
文件: Thread.cs 项目: sidecut/xaeios
        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);
                }
            }
        }
示例#8
0
文件: Thread.cs 项目: sidecut/xaeios
 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;
 }
示例#9
0
 public static void InjectException(TaskHandle task, Exception exception)
 {
     GetTask(task).InjectedException = (XaeiOSException)exception;
 }
示例#10
0
 public static extern void ScheduleTask(TaskHandle task);
示例#11
0
文件: Lock.cs 项目: sidecut/xaeios
 public Lock()
 {
     _owner = null;
     _waitingOwners = new NativeArray<TaskHandle>();
 }
示例#12
0
 public static void StartTask(TaskHandle task)
 {
     Scheduler.StartTask(GetTask(task));
 }
示例#13
0
 public static void ScheduleTask(TaskHandle task)
 {
     Scheduler.ScheduleTaskChecked(GetTask(task));
 }
示例#14
0
 public static void KillTask(TaskHandle task)
 {
     Scheduler.KillTask(GetTask(task));
 }
示例#15
0
文件: Monitor.cs 项目: sidecut/xaeios
 public MonitorLock()
 {
     _owner = null;
     _waitingOwners = new NativeArray<TaskHandle>();
     _count = 0;
 }
示例#16
0
文件: Monitor.cs 项目: sidecut/xaeios
 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;
 }
示例#17
0
 public static extern void StartTask(TaskHandle task);
示例#18
0
 public extern void Remove(TaskHandle task);
示例#19
0
 public WaitingTask(TaskHandle task, int resources)
 {
     Task = task;
     Resources = resources;
 }
示例#20
0
 public static extern void BlockTask(TaskHandle task);
示例#21
0
 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;
 }
示例#22
0
 public static extern void KillTask(TaskHandle task);
示例#23
0
 public static void BlockTask(TaskHandle task)
 {
     Scheduler.BlockTask(GetTask(task));
 }
示例#24
0
 public void Cancel()
 {
     Logging.Trace("Unblocker::Cancel()");
     Global.ClearTimeout(TimeoutId);
     TimeoutId = null;
     Task = null;
 }