Author: lupus
Date: 2006-03-20 08:55:11 -0500 (Mon, 20 Mar 2006)
New Revision: 58182

Modified:
   branches/mono-1-1-13/mono/mono/metadata/ChangeLog
   branches/mono-1-1-13/mono/mono/metadata/icall.c
   branches/mono-1-1-13/mono/mono/metadata/threads-types.h
   branches/mono-1-1-13/mono/mono/metadata/threads.c
Log:


Wed Mar 15 16:31:38 CET 2006 Paolo Molaro <[EMAIL PROTECTED]>

        * icall.c, threads-types.h, threads.c: implemented finalizer for
        LocalDataStoreSlot.



Modified: branches/mono-1-1-13/mono/mono/metadata/ChangeLog
===================================================================
--- branches/mono-1-1-13/mono/mono/metadata/ChangeLog   2006-03-20 13:51:09 UTC 
(rev 58181)
+++ branches/mono-1-1-13/mono/mono/metadata/ChangeLog   2006-03-20 13:55:11 UTC 
(rev 58182)
@@ -1,3 +1,9 @@
+
+Wed Mar 15 16:31:38 CET 2006 Paolo Molaro <[EMAIL PROTECTED]>
+
+       * icall.c, threads-types.h, threads.c: implemented finalizer for
+       LocalDataStoreSlot.
+
 2006-03-14  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * icall.c (ves_icall_System_Reflection_Assembly_GetTypes): Avoid

Modified: branches/mono-1-1-13/mono/mono/metadata/icall.c
===================================================================
--- branches/mono-1-1-13/mono/mono/metadata/icall.c     2006-03-20 13:51:09 UTC 
(rev 58181)
+++ branches/mono-1-1-13/mono/mono/metadata/icall.c     2006-03-20 13:55:11 UTC 
(rev 58182)
@@ -7035,6 +7035,7 @@
        {"Abort_internal(object)", ves_icall_System_Threading_Thread_Abort},
        {"ClrState", ves_icall_System_Threading_Thread_ClrState},
        {"CurrentThread_internal", mono_thread_current},
+       {"FreeLocalSlotValues", mono_thread_free_local_slot_values},
        {"GetCachedCurrentCulture", 
ves_icall_System_Threading_Thread_GetCachedCurrentCulture},
        {"GetCachedCurrentUICulture", 
ves_icall_System_Threading_Thread_GetCachedCurrentUICulture},
        {"GetDomainID", ves_icall_System_Threading_Thread_GetDomainID},

Modified: branches/mono-1-1-13/mono/mono/metadata/threads-types.h
===================================================================
--- branches/mono-1-1-13/mono/mono/metadata/threads-types.h     2006-03-20 
13:51:09 UTC (rev 58181)
+++ branches/mono-1-1-13/mono/mono/metadata/threads-types.h     2006-03-20 
13:55:11 UTC (rev 58182)
@@ -115,4 +115,6 @@
 
 void ves_icall_System_Threading_Thread_MemoryBarrier (void);
 
+void mono_thread_free_local_slot_values (int slot, MonoBoolean thread_local);
+
 #endif /* _MONO_METADATA_THREADS_TYPES_H_ */

Modified: branches/mono-1-1-13/mono/mono/metadata/threads.c
===================================================================
--- branches/mono-1-1-13/mono/mono/metadata/threads.c   2006-03-20 13:51:09 UTC 
(rev 58181)
+++ branches/mono-1-1-13/mono/mono/metadata/threads.c   2006-03-20 13:55:11 UTC 
(rev 58182)
@@ -2595,6 +2595,70 @@
        }
 }
 
+static MonoClassField *local_slots = NULL;
+
+typedef struct {
+       /* local tls data to get locals_slot from a thread */
+       guint32 offset;
+       int idx;
+       /* index in the locals_slot array */
+       int slot;
+} LocalSlotID;
+
+static void
+clear_local_slot (gpointer key, gpointer value, gpointer user_data)
+{
+       LocalSlotID *sid = user_data;
+       MonoThread *thread = (MonoThread*)value;
+       MonoArray *slots_array;
+       /*
+        * the static field is stored at: ((char*) thread->static_data [idx]) + 
(offset & 0xffffff);
+        * it is for the right domain, so we need to check if it is allocated 
an initialized
+        * for the current thread.
+        */
+       /*g_print ("handling thread %p\n", thread);*/
+       if (!thread->static_data || !thread->static_data [sid->idx])
+               return;
+       slots_array = *(MonoArray **)(((char*) thread->static_data [sid->idx]) 
+ (sid->offset & 0xffffff));
+       if (!slots_array || sid->slot >= mono_array_length (slots_array))
+               return;
+       mono_array_set (slots_array, MonoObject*, sid->slot, NULL);
+}
+
+void
+mono_thread_free_local_slot_values (int slot, MonoBoolean thread_local)
+{
+       MonoDomain *domain;
+       LocalSlotID sid;
+       sid.slot = slot;
+       if (thread_local) {
+               void *addr = NULL;
+               if (!local_slots) {
+                       local_slots = mono_class_get_field_from_name 
(mono_defaults.thread_class, "local_slots");
+                       if (!local_slots) {
+                               g_warning ("local_slots field not found in 
Thread class");
+                               return;
+                       }
+               }
+               domain = mono_domain_get ();
+               mono_domain_lock (domain);
+               if (domain->special_static_fields)
+                       addr = g_hash_table_lookup 
(domain->special_static_fields, local_slots);
+               mono_domain_unlock (domain);
+               if (!addr)
+                       return;
+               /*g_print ("freeing slot %d at %p\n", slot, addr);*/
+               sid.offset = GPOINTER_TO_UINT (addr);
+               sid.offset &= 0x7fffffff;
+               sid.idx = (sid.offset >> 24) - 1;
+               mono_threads_lock ();
+               mono_g_hash_table_foreach (threads, clear_local_slot, &sid);
+               mono_threads_unlock ();
+       } else {
+               /* FIXME: clear the slot for MonoAppContexts, too */
+       }
+}
+
 static void gc_stop_world (gpointer key, gpointer value, gpointer user)
 {
        MonoThread *thread=(MonoThread *)value;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to