2003-01-22 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Wed, 22 Jan 2003 12:11:00 +0000 (12:11 -0000)
committerMartin Baulig <martin@novell.com>
Wed, 22 Jan 2003 12:11:00 +0000 (12:11 -0000)
* appdomain.h (MonoThreadStartCB): Added `MonoThread *thread' and
`gpointer func' arguments.
(MonoThreadAttachCB): New typedef; like the old MonoThreadStartCB,
but added `MonoThread *thread' argument.
(mono_runtime_init): The last argument is now a MonoThreadAttachCB.

* threads.c (mono_new_thread_init): Added `gpointer func' argument
and pass it to the mono_thread_start_cb callback.
(mono_install_thread_callbacks): New public function to install a
set of callbacks which are set by the debugger.
(mono_thread_init): The last argument is now a MonoThreadAttachCB.

svn path=/trunk/mono/; revision=10806

mono/metadata/ChangeLog
mono/metadata/appdomain.c
mono/metadata/appdomain.h
mono/metadata/gc.c
mono/metadata/threads.c
mono/metadata/threads.h

index bbb07733f7e0acd3494668115df724596bfcc95e..0f2e85b9110d7a1b2c1b45e4c29467ed5054ccab 100644 (file)
@@ -1,3 +1,17 @@
+2003-01-22  Martin Baulig  <martin@ximian.com>
+
+       * appdomain.h (MonoThreadStartCB): Added `MonoThread *thread' and
+       `gpointer func' arguments.      
+       (MonoThreadAttachCB): New typedef; like the old MonoThreadStartCB,
+       but added `MonoThread *thread' argument.
+       (mono_runtime_init): The last argument is now a MonoThreadAttachCB.
+
+       * threads.c (mono_new_thread_init): Added `gpointer func' argument
+       and pass it to the mono_thread_start_cb callback.
+       (mono_install_thread_callbacks): New public function to install a
+       set of callbacks which are set by the debugger.
+       (mono_thread_init): The last argument is now a MonoThreadAttachCB.
+
 2003-01-22  Martin Baulig  <martin@ximian.com>
 
        * Makefile.am: Install debug-mono-symfile.h.
index 6641d4bfc7e16ec967a3556389dc5664d434c6ab..68038da50eb94ee2693a8b43df0c6ff744405e60 100644 (file)
@@ -50,7 +50,7 @@ mono_domain_fire_assembly_load (MonoAssembly *assembly, gpointer user_data);
  */
 void
 mono_runtime_init (MonoDomain *domain, MonoThreadStartCB start_cb,
-                  MonoThreadStartCB attach_cb)
+                  MonoThreadAttachCB attach_cb)
 {
        MonoAppDomainSetup *setup;
        MonoAppDomain *ad;
index a3f01ccf5823383312a06a99edc9df23200d61e0..d27e31566d80d5b8c5bdef2bd9645a5b8dd353e6 100644 (file)
@@ -18,7 +18,8 @@
 #include <mono/utils/mono-hash.h>
 #include <mono/io-layer/io-layer.h>
 
-typedef void (*MonoThreadStartCB) (gpointer stack_start);
+typedef void (*MonoThreadStartCB) (MonoThread *thread, gpointer stack_start, gpointer func);
+typedef void (*MonoThreadAttachCB) (MonoThread *thread, gpointer stack_start);
 
 /* This is a copy of System.AppDomainSetup */
 typedef struct {
@@ -105,7 +106,7 @@ mono_init                  (const char *filename);
 
 void
 mono_runtime_init          (MonoDomain *domain, MonoThreadStartCB start_cb,
-                           MonoThreadStartCB attach_cb);
+                           MonoThreadAttachCB attach_cb);
 
 void
 mono_runtime_cleanup       (MonoDomain *domain);
index d7affd57798d24e0b0de9759b45c8e274b2fc348..f63ddba2f7ab5ed5e0bfcea605781808db52196c 100644 (file)
@@ -415,7 +415,7 @@ static guint32 finalizer_thread (gpointer unused)
 {
        guint32 stack_start;
        
-       mono_new_thread_init (NULL, &stack_start);
+       mono_new_thread_init (NULL, &stack_start, NULL);
        
        while(!finished) {
                /* Wait to be notified that there's at least one
index cb1cdb76a3c0c57283760d32c2f234dcef96406e..79fc53c6826d2b215200683237074bcaef53a88d 100644 (file)
@@ -67,7 +67,10 @@ static guint32 current_object_key;
 static MonoThreadStartCB mono_thread_start_cb = NULL;
 
 /* function called at thread attach */
-static MonoThreadStartCB mono_thread_attach_cb = NULL;
+static MonoThreadAttachCB mono_thread_attach_cb = NULL;
+
+/* function called when a new thread has been created */
+static MonoThreadCallbacks *mono_thread_callbacks = NULL;
 
 /* The TLS key that holds the LocalDataStoreSlot hash in each thread */
 static guint32 slothash_key;
@@ -168,7 +171,7 @@ static guint32 start_wrapper(void *data)
 
        mono_profiler_thread_start (tid);
 
-       mono_new_thread_init (start_info->obj, &tid);
+       mono_new_thread_init (start_info->obj, &tid, start_func);
 
        g_free (start_info);
 
@@ -188,7 +191,7 @@ static guint32 start_wrapper(void *data)
        return(0);
 }
 
-void mono_new_thread_init (MonoThread *thread_object, gpointer stack_start)
+void mono_new_thread_init (MonoThread *thread_object, gpointer stack_start, gpointer func)
 {
        /* FIXME: GC problem here with recorded object
         * pointer!
@@ -199,7 +202,7 @@ void mono_new_thread_init (MonoThread *thread_object, gpointer stack_start)
        TlsSetValue (current_object_key, thread_object);
 
        if (mono_thread_start_cb) {
-               mono_thread_start_cb (stack_start);
+               mono_thread_start_cb (thread_object, stack_start, func);
        }
 }
 
@@ -245,7 +248,7 @@ mono_thread_attach (MonoDomain *domain)
        if ((thread = mono_thread_current ())) {
                g_warning ("mono_thread_attach called for an already attached thread");
                if (mono_thread_attach_cb) {
-                       mono_thread_attach_cb (&tid);
+                       mono_thread_attach_cb (thread, &tid);
                }
                return thread;
        }
@@ -272,7 +275,7 @@ mono_thread_attach (MonoDomain *domain)
        mono_domain_set (domain);
 
        if (mono_thread_attach_cb) {
-               mono_thread_attach_cb (&tid);
+               mono_thread_attach_cb (thread, &tid);
        }
 
        return(thread);
@@ -297,7 +300,10 @@ HANDLE ves_icall_System_Threading_Thread_Thread_internal(MonoThread *this,
 #endif
        
        im = mono_get_delegate_invoke (start->vtable->klass);
-       start_func = mono_compile_method (im);
+       if (mono_thread_callbacks)
+               start_func = (* mono_thread_callbacks->thread_start_compile_func) (im);
+       else
+               start_func = mono_compile_method (im);
 
        if(start_func==NULL) {
                g_warning(G_GNUC_PRETTY_FUNCTION
@@ -332,7 +338,7 @@ HANDLE ves_icall_System_Threading_Thread_Thread_internal(MonoThread *this,
                g_message(G_GNUC_PRETTY_FUNCTION
                          ": Started thread ID %d (handle %p)", tid, thread);
 #endif
-               
+
                return(thread);
        }
 }
@@ -365,7 +371,13 @@ void ves_icall_System_Threading_Thread_Start_internal(MonoThread *this,
         */
        handle_store(this);
 
+       if (mono_thread_callbacks)
+               (* mono_thread_callbacks->start_resume) (this);
+
        ResumeThread(thread);
+
+       if (mono_thread_callbacks)
+               (* mono_thread_callbacks->end_resume) (this);
 }
 
 void ves_icall_System_Threading_Thread_Sleep_internal(gint32 ms)
@@ -1181,8 +1193,7 @@ ves_icall_System_Threading_Thread_ResetAbort (void)
        }
 }
 
-void mono_thread_init (MonoDomain *domain, MonoThreadStartCB start_cb,
-                      MonoThreadStartCB attach_cb)
+void mono_thread_init (MonoDomain *domain, MonoThreadStartCB start_cb, MonoThreadAttachCB attach_cb)
 {
        /* Build a System.Threading.Thread object instance to return
         * for the main line's Thread.CurrentThread property.
@@ -1230,6 +1241,11 @@ void mono_thread_init (MonoDomain *domain, MonoThreadStartCB start_cb,
        GetCurrentProcess ();
 }
 
+void mono_install_thread_callbacks (MonoThreadCallbacks *callbacks)
+{
+       mono_thread_callbacks = callbacks;
+}
+
 #ifdef THREAD_DEBUG
 static void print_tids (gpointer key, gpointer value, gpointer user)
 {
index 2caa8ebb8e495da7a49a85ed997839a3e812baae..26d5b07302c4582f475c2c7159e9f83f7237b151 100644 (file)
 extern int  mono_thread_get_abort_signal (void);
 
 extern void mono_thread_init (MonoDomain *domain, MonoThreadStartCB start_cb,
-                             MonoThreadStartCB attach_cb);
+                             MonoThreadAttachCB attach_cb);
 extern void mono_thread_cleanup(void);
 extern MonoThread *mono_thread_current (void);
 
+typedef struct {
+       gpointer (* thread_start_compile_func) (MonoMethod *delegate);
+       void (* start_resume) (MonoThread *thread);
+       void (* end_resume) (MonoThread *thread);
+} MonoThreadCallbacks;
+
+extern void mono_install_thread_callbacks (MonoThreadCallbacks *callbacks);
+
 extern void mono_new_thread_init (MonoThread *thread_object,
-                                 gpointer stack_start);
+                                 gpointer stack_start,
+                                 gpointer func);
 extern MonoThread *mono_thread_create (MonoDomain *domain, gpointer func,
                                       gpointer arg);
 extern MonoThread *mono_thread_attach (MonoDomain *domain);