/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. using System.Threading;
  16. using Microsoft.Scripting.Runtime;
  17. using IronRuby.Runtime;
  18. namespace IronRuby.Builtins {
  19. [RubyClass("ThreadGroup", Inherits = typeof(object))]
  20. public class ThreadGroup {
  21. [RubyMethod("add")]
  22. public static ThreadGroup/*!*/ Add([NotNull]ThreadGroup/*!*/ self, [NotNull]Thread/*!*/ thread) {
  23. ThreadOps.RubyThreadInfo.FromThread(thread).Group = self;
  24. return self;
  25. }
  26. // enclose
  27. // enclosed?
  28. [RubyMethod("list")]
  29. public static RubyArray/*!*/ List([NotNull]ThreadGroup/*!*/ self) {
  30. ThreadOps.RubyThreadInfo[] threads = ThreadOps.RubyThreadInfo.Threads;
  31. RubyArray result = new RubyArray(threads.Length);
  32. foreach (ThreadOps.RubyThreadInfo threadInfo in threads) {
  33. Thread thread = threadInfo.Thread;
  34. if (thread != null && threadInfo.Group == self) {
  35. result.Add(thread);
  36. }
  37. }
  38. return result;
  39. }
  40. [RubyConstant]
  41. public readonly static ThreadGroup Default = new ThreadGroup();
  42. }
  43. }