1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
using System;
using System.Collections;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
using Mono.Debugger.Backend;
namespace Mono.Debugger
{
// <summary>
// This is used to share information about breakpoints and signal handlers
// between different invocations of the same target.
// </summary>
public sealed class ThreadGroup : DebuggerMarshalByRefObject
{
string name;
Hashtable threads;
static ThreadGroup global = new ThreadGroup ("global");
static ThreadGroup system = new ThreadGroup ("system");
protected ThreadGroup (string name)
{
this.name = name;
this.threads = Hashtable.Synchronized (new Hashtable ());
}
internal static ThreadGroup CreateThreadGroup (string name)
{
if ((name == "global") || (name == "system"))
throw new InvalidOperationException ();
return new ThreadGroup (name);
}
public void AddThread (int id)
{
if (IsSystem)
throw new InvalidOperationException ();
if (!threads.Contains (id))
threads.Add (id, true);
}
public void RemoveThread (int id)
{
if (IsSystem)
throw new InvalidOperationException ();
threads.Remove (id);
}
public int[] Threads {
get {
lock (this) {
int[] retval = new int [threads.Keys.Count];
threads.Keys.CopyTo (retval, 0);
return retval;
}
}
}
public string Name {
get { return name; }
}
public static ThreadGroup Global {
get { return global; }
}
public static ThreadGroup System {
get { return system; }
}
public bool IsGlobal {
get { return this == global; }
}
public bool IsSystem {
get { return this == global || this == system; }
}
public override string ToString ()
{
return String.Format ("{0} ({1})", GetType (), name);
}
}
}
|