示例#1
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
        public static bool IsStopped(Thread self)
        {
            RubyThreadInfo.RegisterThread(Thread.CurrentThread);
            RubyThreadStatus status = GetStatus(self);

            return(status == RubyThreadStatus.Sleeping || status == RubyThreadStatus.Completed || status == RubyThreadStatus.Aborted);
        }
示例#2
0
        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);
        }
示例#3
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
        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");
            }
        }
示例#4
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
        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);
        }
示例#5
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
        public static Thread Run(Thread /*!*/ self)
        {
            RubyThreadInfo.RegisterThread(Thread.CurrentThread);
            RubyThreadInfo info = RubyThreadInfo.FromThread(self);

            info.Run();
            return(self);
        }
示例#6
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
        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();
        }
示例#7
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
        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);
        }
示例#8
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
        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);
        }
示例#9
0
        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);
        }
示例#10
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
        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);
        }
示例#11
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
        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);
        }
示例#12
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
        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);
        }
示例#13
0
        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());
            }
        }
示例#14
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
        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);
            }
        }
示例#15
0
 public static bool Critical(object self, bool value)
 {
     RubyThreadInfo.RegisterThread(Thread.CurrentThread);
     return(false);
 }
示例#16
0
 public static Thread Kill(Thread /*!*/ self)
 {
     RubyThreadInfo.RegisterThread(Thread.CurrentThread);
     self.Abort();
     return(self);
 }
示例#17
0
 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);
 }
示例#18
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
 public static void Yield(object self)
 {
     RubyThreadInfo.RegisterThread(Thread.CurrentThread);
     Thread.Sleep(0);
 }
示例#19
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
 public static Thread /*!*/ Current(object self)
 {
     RubyThreadInfo.RegisterThread(Thread.CurrentThread);
     return(Thread.CurrentThread);
 }
示例#20
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
 public static void Critical(RubyContext /*!*/ context, object self, bool value)
 {
     RubyThreadInfo.RegisterThread(Thread.CurrentThread);
     SetCritical(context, value);
 }
示例#21
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
 [RubyMethod("critical", RubyMethodAttributes.PublicSingleton)] // Compatibility <= RubyCompatibility.Ruby18
 public static bool Critical(RubyContext /*!*/ context, object self)
 {
     RubyThreadInfo.RegisterThread(Thread.CurrentThread);
     return(context.CriticalThread != null);
 }
示例#22
0
文件: ThreadOps.cs 项目: ltwlf/IronSP
 public static bool IsAlive(Thread /*!*/ self)
 {
     RubyThreadInfo.RegisterThread(Thread.CurrentThread);
     return(self.IsAlive);
 }
示例#23
0
 public static void Run(Thread /*!*/ self)
 {
     RubyThreadInfo.RegisterThread(Thread.CurrentThread);
     self.Interrupt();
 }