Thu Jan 13 18:16:35 CET 2005 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Thu, 13 Jan 2005 17:08:32 +0000 (17:08 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Thu, 13 Jan 2005 17:08:32 +0000 (17:08 -0000)
* object-internal.h, threads.c: implement stacksize and
parameterized thread start functionality (requires
matching corlib). Marked broken code for later removal.

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

mono/metadata/ChangeLog
mono/metadata/object-internals.h
mono/metadata/threads.c

index d1140ee343047a0ccc98a0c756ef35234ba7cd86..42669c2cc4481b2af1aa6deb980a2eb7c8da2c6c 100644 (file)
@@ -1,3 +1,10 @@
+
+Thu Jan 13 18:16:35 CET 2005 Paolo Molaro <lupus@ximian.com>
+
+       * object-internal.h, threads.c: implement stacksize and 
+       parameterized thread start functionality (requires
+       matching corlib). Marked broken code for later removal.
+
 2005-01-12  Martin Baulig  <martin@ximian.com>
 
        * class-internals.h (MonoGenericClass): Moved the `initialized'
index 64223f89fa09f5cab4d874c67cea122189777f9a..10bd1835e8e5bf87f31e3fc0a826f4dd1d83a7bb 100644 (file)
@@ -213,6 +213,7 @@ typedef struct {
 
 struct _MonoThread {
        MonoObject  obj;
+       int         lock_thread_id; /* to be used as the pre-shifted thread id in thin locks */
        HANDLE      handle;
        MonoObject **culture_info;
        MonoObject **ui_culture_info;
@@ -228,6 +229,10 @@ struct _MonoThread {
        gpointer *static_data;
        gpointer jit_data;
        gpointer lock_data;
+       gpointer unused1;
+       gpointer unused2;
+       int stack_size;
+       MonoObject *start_obj;
        GSList *appdomain_refs;
        MonoBoolean interruption_requested;
        gpointer suspend_event;
index 8f542c608592d7350e3e24ef0f29a5d934047685..75c819c0a1a7ce45c058710890e37f16a15aa92f 100644 (file)
@@ -41,7 +41,8 @@ struct StartInfo
 {
        guint32 (*func)(void *);
        MonoThread *obj;
-       void *this;
+       MonoObject *delegate;
+       void *start_arg;
        MonoDomain *domain;
 };
 
@@ -113,6 +114,7 @@ static guint32 slothash_key = -1;
 
 /* The default stack size for each thread */
 static guint32 default_stacksize = 0;
+#define default_stacksize_for_thread(thread) ((thread)->stack_size? (thread)->stack_size: default_stacksize)
 
 static void thread_adjust_static_data (MonoThread *thread);
 static void mono_init_static_data_info (StaticDataInfo *static_data);
@@ -218,9 +220,11 @@ static guint32 start_wrapper(void *data)
 {
        struct StartInfo *start_info=(struct StartInfo *)data;
        guint32 (*start_func)(void *);
-       void *this;
+       void *start_arg;
        guint32 tid;
        MonoThread *thread=start_info->obj;
+       MonoObject *start_delegate = start_info->delegate;
+       MonoObject *start_obj = start_info->start_arg;
        
 #ifdef THREAD_DEBUG
        g_message(G_GNUC_PRETTY_FUNCTION ": (%d) Start wrapper",
@@ -244,7 +248,7 @@ static guint32 start_wrapper(void *data)
        }
 
        start_func = start_info->func;
-       this = start_info->this;
+       start_arg = start_info->start_arg;
 
        /* This MUST be called before any managed code can be
         * executed, as it calls the callback function that (for the
@@ -284,7 +288,16 @@ static guint32 start_wrapper(void *data)
        g_message (G_GNUC_PRETTY_FUNCTION "start_wrapper for %d\n", thread->tid);
 #endif
 
-       start_func (this);
+       /* start_func is set only for unamanged start functions */
+       if (start_func) {
+               start_func (start_arg);
+       } else {
+               void *args [1];
+               g_assert (start_delegate != NULL);
+               args [0] = start_arg;
+               /* we may want to handle the exception here. See comment below on unhandled exceptions */
+               mono_runtime_delegate_invoke (start_delegate, args, NULL);
+       }
 #ifdef PLATFORM_WIN32
        /* If the thread calls ExitThread at all, this remaining code
         * will not be executed, but the main thread will eventually
@@ -346,16 +359,16 @@ void mono_thread_create (MonoDomain *domain, gpointer func, gpointer arg)
        start_info->func = func;
        start_info->obj = thread;
        start_info->domain = domain;
-       start_info->this = arg;
+       start_info->start_arg = arg;
        
        /* Create suspended, so we can do some housekeeping before the thread
         * starts
         */
 #if defined(PLATFORM_WIN32) && defined(HAVE_BOEHM_GC)
-       thread_handle = GC_CreateThread(NULL, default_stacksize, start_wrapper, start_info,
+       thread_handle = GC_CreateThread(NULL, default_stacksize_for_thread (thread), start_wrapper, start_info,
                                     CREATE_SUSPENDED, &tid);
 #else
-       thread_handle = CreateThread(NULL, default_stacksize, start_wrapper, start_info,
+       thread_handle = CreateThread(NULL, default_stacksize_for_thread (thread), start_wrapper, start_info,
                                     CREATE_SUSPENDED, &tid);
 #endif
 #ifdef THREAD_DEBUG
@@ -476,7 +489,12 @@ HANDLE ves_icall_System_Threading_Thread_Thread_internal(MonoThread *this,
                  ": Trying to start a new thread: this (%p) start (%p)",
                  this, start);
 #endif
-       
+
+/* FIXME: remove the code inside BROKEN_THREAD_START once martin gets rid of the
+ * thread_start_compile_func stuff.
+ */
+#define BROKEN_THREAD_START
+#ifdef BROKEN_THREAD_START
        im = mono_get_delegate_invoke (start->vtable->klass);
        im = mono_marshal_get_delegate_invoke (im);
        if (mono_thread_callbacks)
@@ -489,10 +507,19 @@ HANDLE ves_icall_System_Threading_Thread_Thread_internal(MonoThread *this,
                          ": Can't locate start method!");
                return(NULL);
        } else {
+#else
+       start_func = NULL;
+       {
+#endif
                /* This is freed in start_wrapper */
                start_info = g_new0 (struct StartInfo, 1);
                start_info->func = start_func;
-               start_info->this = delegate;
+#ifdef BROKEN_THREAD_START
+               start_info->start_arg = start;
+#else
+               start_info->start_arg = this->start_obj;
+#endif
+               start_info->delegate = start;
                start_info->obj = this;
                start_info->domain = mono_domain_get ();
 
@@ -503,10 +530,10 @@ HANDLE ves_icall_System_Threading_Thread_Thread_internal(MonoThread *this,
                }
 
 #if defined(PLATFORM_WIN32) && defined(HAVE_BOEHM_GC)
-               thread=GC_CreateThread(NULL, default_stacksize, start_wrapper, start_info,
+               thread=GC_CreateThread(NULL, default_stacksize_for_thread (this), start_wrapper, start_info,
                                    CREATE_SUSPENDED, &tid);
 #else
-               thread=CreateThread(NULL, default_stacksize, start_wrapper, start_info,
+               thread=CreateThread(NULL, default_stacksize_for_thread (this), start_wrapper, start_info,
                                    CREATE_SUSPENDED, &tid);
 #endif
                if(thread==NULL) {