public static bool IsStopped(Thread self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); RubyThreadStatus status = GetStatus(self); return(status == RubyThreadStatus.Sleeping || status == RubyThreadStatus.Completed || status == RubyThreadStatus.Aborted); }
public static MutableString /*!*/ Inspect(RubyContext /*!*/ context, Thread /*!*/ self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); MutableString result = MutableString.CreateMutable(); result.Append("#<"); result.Append(RubyUtils.GetClassName(context, self)); result.Append(':'); RubyUtils.AppendFormatHexObjectId(result, RubyUtils.GetObjectId(context, self)); result.Append(' '); if ((self.ThreadState & ThreadState.WaitSleepJoin) != 0) { result.Append("sleep"); } else if ((self.ThreadState & (ThreadState.Stopped | ThreadState.Aborted | ThreadState.AbortRequested)) != 0) { result.Append("dead"); } else { result.Append("run"); } result.Append('>'); return(result); }
public static object Status(Thread /*!*/ self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); switch (GetStatus(self)) { case RubyThreadStatus.Unstarted: return(MutableString.CreateAscii("unstarted")); case RubyThreadStatus.Running: return(MutableString.CreateAscii("run")); case RubyThreadStatus.Sleeping: return(MutableString.CreateAscii("sleep")); case RubyThreadStatus.Aborting: return(MutableString.CreateAscii("aborting")); case RubyThreadStatus.Completed: return(false); case RubyThreadStatus.Aborted: return(null); default: throw new ArgumentException("unknown thread status"); } }
public static Thread Priority(Thread /*!*/ self, int priority) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); if (priority <= -2) { self.Priority = ThreadPriority.Lowest; } else if (priority == -1) { self.Priority = ThreadPriority.BelowNormal; } else if (priority == 0) { self.Priority = ThreadPriority.Normal; } else if (priority == 1) { self.Priority = ThreadPriority.AboveNormal; } else { self.Priority = ThreadPriority.Highest; } return(self); }
public static Thread Run(Thread /*!*/ self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); RubyThreadInfo info = RubyThreadInfo.FromThread(self); info.Run(); return(self); }
internal static void DoSleep() { RubyThreadInfo.RegisterThread(Thread.CurrentThread); // TODO: MRI throws an exception if you try to stop the main thread RubyThreadInfo info = RubyThreadInfo.FromThread(Thread.CurrentThread); info.Sleep(); }
public static Thread /*!*/ Join(Thread /*!*/ self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); self.Join(); Exception threadException = RubyThreadInfo.FromThread(self).Exception; if (threadException != null) { throw threadException; } return(self); }
public static Thread Kill(Thread /*!*/ self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); RubyThreadInfo info = RubyThreadInfo.FromThread(self); if (GetStatus(self) == RubyThreadStatus.Sleeping && info.ExitRequested) { // Thread must be sleeping in an ensure clause. Wake up the thread and allow ensure clause to complete info.Run(); return(self); } info.ExitRequested = true; RubyUtils.ExitThread(self); return(self); }
public static Thread /*!*/ Join(Thread /*!*/ self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); if (!(self.ThreadState == ThreadState.AbortRequested || self.ThreadState == ThreadState.Aborted)) { self.Join(); } Exception threadException = RubyThreadInfo.FromThread(self).Exception; if (threadException != null) { throw threadException; } return(self); }
public static RubyArray /*!*/ List(object self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); RubyThreadInfo[] threads = RubyThreadInfo.Threads; RubyArray result = new RubyArray(threads.Length); foreach (RubyThreadInfo threadInfo in threads) { Thread thread = threadInfo.Thread; if (thread != null) { result.Add(thread); } } return(result); }
public static MutableString /*!*/ Inspect(RubyContext /*!*/ context, Thread /*!*/ self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); MutableString result = MutableString.CreateMutable(context.GetIdentifierEncoding()); result.Append("#<"); result.Append(context.GetClassDisplayName(self)); result.Append(':'); RubyUtils.AppendFormatHexObjectId(result, RubyUtils.GetObjectId(context, self)); result.Append(' '); RubyThreadStatus status = GetStatus(self); switch (status) { case RubyThreadStatus.Unstarted: result.Append("unstarted"); break; case RubyThreadStatus.Running: result.Append("run"); break; case RubyThreadStatus.Sleeping: result.Append("sleep"); break; case RubyThreadStatus.Aborting: result.Append("aborting"); break; case RubyThreadStatus.Completed: case RubyThreadStatus.Aborted: result.Append("dead"); break; } result.Append('>'); return(result); }
public static Thread /*!*/ Join(Thread /*!*/ self, double seconds) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); if (!(self.ThreadState == ThreadState.AbortRequested || self.ThreadState == ThreadState.Aborted)) { double ms = seconds * 1000; int timeout = (ms <Int32.MinValue || ms> Int32.MaxValue) ? Timeout.Infinite : (int)ms; if (!self.Join(timeout)) { return(null); } } Exception threadException = RubyThreadInfo.FromThread(self).Exception; if (threadException != null) { throw threadException; } return(self); }
public static object Status(Thread /*!*/ self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); switch (self.ThreadState) { case ThreadState.WaitSleepJoin: return(MutableString.Create("sleep")); case ThreadState.Running: return(MutableString.Create("run")); case ThreadState.Aborted: case ThreadState.AbortRequested: return(null); case ThreadState.Stopped: case ThreadState.StopRequested: return(false); default: throw new ArgumentException("unknown thread status: " + self.ThreadState.ToString()); } }
public static object Priority(Thread /*!*/ self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); switch (self.Priority) { case ThreadPriority.Lowest: return(-2); case ThreadPriority.BelowNormal: return(-1); case ThreadPriority.Normal: return(0); case ThreadPriority.AboveNormal: return(1); case ThreadPriority.Highest: return(2); default: return(0); } }
public static bool Critical(object self, bool value) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); return(false); }
public static Thread Kill(Thread /*!*/ self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); self.Abort(); return(self); }
public static void Stop(object self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); // TODO: MRI throws an exception if you try to stop the main thread Thread.Sleep(Timeout.Infinite); }
public static void Yield(object self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); Thread.Sleep(0); }
public static Thread /*!*/ Current(object self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); return(Thread.CurrentThread); }
public static void Critical(RubyContext /*!*/ context, object self, bool value) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); SetCritical(context, value); }
[RubyMethod("critical", RubyMethodAttributes.PublicSingleton)] // Compatibility <= RubyCompatibility.Ruby18 public static bool Critical(RubyContext /*!*/ context, object self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); return(context.CriticalThread != null); }
public static bool IsAlive(Thread /*!*/ self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); return(self.IsAlive); }
public static void Run(Thread /*!*/ self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); self.Interrupt(); }