PageRenderTime 21ms CodeModel.GetById 10ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/IronPython_Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ThreadGroup.cs

#
C# | 49 lines | 27 code | 6 blank | 16 comment | 4 complexity | e7c8bed7e91811bd75a05c5f333dbd63 MD5 | raw file
 1/* ****************************************************************************
 2 *
 3 * Copyright (c) Microsoft Corporation. 
 4 *
 5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
 6 * copy of the license can be found in the License.html file at the root of this distribution. If 
 7 * you cannot locate the  Apache License, Version 2.0, please send an email to 
 8 * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 9 * by the terms of the Apache License, Version 2.0.
10 *
11 * You must not remove this notice, or any other, from this software.
12 *
13 *
14 * ***************************************************************************/
15
16using System.Threading;
17using Microsoft.Scripting.Runtime;
18using IronRuby.Runtime;
19
20namespace IronRuby.Builtins {
21    [RubyClass("ThreadGroup", Inherits = typeof(object))]
22    public class ThreadGroup {
23        [RubyMethod("add")]
24        public static ThreadGroup/*!*/ Add([NotNull]ThreadGroup/*!*/ self, [NotNull]Thread/*!*/ thread) {
25            ThreadOps.RubyThreadInfo.FromThread(thread).Group = self;
26            return self;
27        }
28
29        // enclose
30        // enclosed?
31
32        [RubyMethod("list")]
33        public static RubyArray/*!*/ List([NotNull]ThreadGroup/*!*/ self) {
34            ThreadOps.RubyThreadInfo[] threads = ThreadOps.RubyThreadInfo.Threads;
35            RubyArray result = new RubyArray(threads.Length);
36            foreach (ThreadOps.RubyThreadInfo threadInfo in threads) {
37                Thread thread = threadInfo.Thread;
38                if (thread != null && threadInfo.Group == self) {
39                    result.Add(thread);
40                }
41            }
42
43            return result;
44        }
45
46        [RubyConstant]
47        public readonly static ThreadGroup Default = new ThreadGroup();
48    }
49}