This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
/
thread-manager.c
114 lines (87 loc) · 2.47 KB
/
thread-manager.c
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <mono-debugger-jit-wrapper.h>
#include <mono/io-layer/io-layer.h>
#include <mono/metadata/threads.h>
#define IN_MONO_DEBUGGER
#include <mono/private/libgc-mono-debugger.h>
#include <unistd.h>
#include <string.h>
static GPtrArray *thread_array = NULL;
static void (*notification_function) (int tid, gpointer data, gpointer data2);
extern void GC_push_all_stack (gpointer b, gpointer t);
static void
debugger_gc_stop_world (void)
{
mono_debugger_thread_manager_acquire_global_thread_lock ();
}
static void
debugger_gc_start_world (void)
{
mono_debugger_thread_manager_release_global_thread_lock ();
}
static void
debugger_gc_push_all_stacks (void)
{
int i, tid;
tid = IO_LAYER (GetCurrentThreadId) ();
if (!thread_array)
return;
for (i = 0; i < thread_array->len; i++) {
MonoDebuggerThread *thread = g_ptr_array_index (thread_array, i);
gpointer end_stack = (thread->tid == tid) ? &i : thread->end_stack;
GC_push_all_stack (end_stack, thread->start_stack);
}
}
GCThreadFunctions mono_debugger_thread_vtable = {
NULL,
debugger_gc_stop_world,
debugger_gc_push_all_stacks,
debugger_gc_start_world
};
void
mono_debugger_thread_manager_init (void)
{
if (!thread_array)
thread_array = g_ptr_array_new ();
gc_thread_vtable = &mono_debugger_thread_vtable;
notification_function = mono_debugger_create_notification_function (
(gpointer) &MONO_DEBUGGER__manager.thread_manager_notification);
}
void
mono_debugger_thread_manager_add_thread (guint32 tid, gpointer start_stack, gpointer func)
{
MonoDebuggerThread *thread = g_new0 (MonoDebuggerThread, 1);
thread->tid = tid;
thread->func = func;
thread->start_stack = start_stack;
notification_function (tid, func, &thread->end_stack);
mono_debugger_thread_manager_thread_created (thread);
}
void
mono_debugger_thread_manager_thread_created (MonoDebuggerThread *thread)
{
if (!thread_array)
thread_array = g_ptr_array_new ();
g_ptr_array_add (thread_array, thread);
}
void
mono_debugger_thread_manager_start_resume (guint32 tid)
{
}
void
mono_debugger_thread_manager_end_resume (guint32 tid)
{
}
void
mono_debugger_thread_manager_acquire_global_thread_lock (void)
{
int tid = IO_LAYER (GetCurrentThreadId) ();
mono_debugger_notification_function (
NOTIFICATION_ACQUIRE_GLOBAL_THREAD_LOCK, NULL, tid);
}
void
mono_debugger_thread_manager_release_global_thread_lock (void)
{
int tid = IO_LAYER (GetCurrentThreadId) ();
mono_debugger_notification_function (
NOTIFICATION_RELEASE_GLOBAL_THREAD_LOCK, NULL, tid);
}