Author: lupus
Date: 2006-03-20 09:31:59 -0500 (Mon, 20 Mar 2006)
New Revision: 58186
Modified:
branches/mono-1-1-13/mcs/class/corlib/System.Runtime.Remoting.Contexts/ChangeLog
branches/mono-1-1-13/mcs/class/corlib/System.Runtime.Remoting.Contexts/Context.cs
branches/mono-1-1-13/mcs/class/corlib/System.Threading/ChangeLog
branches/mono-1-1-13/mcs/class/corlib/System.Threading/Thread.cs
branches/mono-1-1-13/mcs/class/corlib/System/ChangeLog
branches/mono-1-1-13/mcs/class/corlib/System/LocalDataStoreSlot.cs
Log:
Backported LocalDataStoreSlot fix.
Modified: branches/mono-1-1-13/mcs/class/corlib/System/ChangeLog
===================================================================
--- branches/mono-1-1-13/mcs/class/corlib/System/ChangeLog 2006-03-20
14:18:25 UTC (rev 58185)
+++ branches/mono-1-1-13/mcs/class/corlib/System/ChangeLog 2006-03-20
14:31:59 UTC (rev 58186)
@@ -1,3 +1,9 @@
+
+Wed Mar 15 16:30:51 CET 2006 Paolo Molaro <[EMAIL PROTECTED]>
+ * LocalDataStoreSlot.cs: implement as index in an array.
+ Implemented finalizer and allow it to remove the data stored
+ in the slot.
+
2006-03-16 Atsushi Enomoto <[EMAIL PROTECTED]>
* Double.cs : (Parse) reject String.Empty.
Modified: branches/mono-1-1-13/mcs/class/corlib/System/LocalDataStoreSlot.cs
===================================================================
--- branches/mono-1-1-13/mcs/class/corlib/System/LocalDataStoreSlot.cs
2006-03-20 14:18:25 UTC (rev 58185)
+++ branches/mono-1-1-13/mcs/class/corlib/System/LocalDataStoreSlot.cs
2006-03-20 14:31:59 UTC (rev 58186)
@@ -37,13 +37,59 @@
{
public sealed class LocalDataStoreSlot
{
- internal LocalDataStoreSlot ()
+ internal int slot;
+ internal bool thread_local; // false for context-local
+
+ static object lock_obj = new object ();
+ static bool[] slot_bitmap_thread;
+ static bool[] slot_bitmap_context;
+
+ internal LocalDataStoreSlot (bool in_thread)
{
+ thread_local = in_thread;
+ lock (lock_obj) {
+ int i;
+ bool[] slot_bitmap;
+ if (in_thread)
+ slot_bitmap = slot_bitmap_thread;
+ else
+ slot_bitmap = slot_bitmap_context;
+ if (slot_bitmap != null) {
+ for (i = 0; i < slot_bitmap.Length;
++i) {
+ if (!slot_bitmap [i]) {
+ slot = i;
+ slot_bitmap [i] = true;
+ return;
+ }
+ }
+ bool[] new_bitmap = new bool [i + 2];
+ slot_bitmap.CopyTo (new_bitmap, 0);
+ slot_bitmap = new_bitmap;
+ } else {
+ slot_bitmap = new bool [2];
+ i = 0;
+ }
+ slot_bitmap [i] = true;
+ slot = i;
+ if (in_thread)
+ slot_bitmap_thread = slot_bitmap;
+ else
+ slot_bitmap_context = slot_bitmap;
+ }
}
- [MonoTODO("Spec: Finalize locks the data store manager before
marking the data slot as unoccupied")]
- ~LocalDataStoreSlot()
+ ~LocalDataStoreSlot ()
{
+ /* first remove all the values from the slots and
+ * then free the slot itself for reuse.
+ */
+ System.Threading.Thread.FreeLocalSlotValues (slot,
thread_local);
+ lock (lock_obj) {
+ if (thread_local)
+ slot_bitmap_thread [slot] = false;
+ else
+ slot_bitmap_context [slot] = false;
+ }
}
}
}
Modified:
branches/mono-1-1-13/mcs/class/corlib/System.Runtime.Remoting.Contexts/ChangeLog
===================================================================
---
branches/mono-1-1-13/mcs/class/corlib/System.Runtime.Remoting.Contexts/ChangeLog
2006-03-20 14:18:25 UTC (rev 58185)
+++
branches/mono-1-1-13/mcs/class/corlib/System.Runtime.Remoting.Contexts/ChangeLog
2006-03-20 14:31:59 UTC (rev 58186)
@@ -1,3 +1,8 @@
+
+Wed Mar 15 16:35:13 CET 2006 Paolo Molaro <[EMAIL PROTECTED]>
+
+ * Context.cs: update for LocalDataStoreSlot changes.
+
2005-12-08 Sebastien Pouliot <[EMAIL PROTECTED]>
* Context.cs: ContextProperties property is virtual.
Modified:
branches/mono-1-1-13/mcs/class/corlib/System.Runtime.Remoting.Contexts/Context.cs
===================================================================
---
branches/mono-1-1-13/mcs/class/corlib/System.Runtime.Remoting.Contexts/Context.cs
2006-03-20 14:18:25 UTC (rev 58185)
+++
branches/mono-1-1-13/mcs/class/corlib/System.Runtime.Remoting.Contexts/Context.cs
2006-03-20 14:31:59 UTC (rev 58186)
@@ -59,7 +59,7 @@
// The sink chain that has to be used by all calls exiting the
context
IMessageSink client_context_sink_chain = null;
- Hashtable datastore;
+ object[] datastore;
ArrayList context_properties;
bool frozen;
@@ -345,14 +345,14 @@
public static LocalDataStoreSlot AllocateDataSlot ()
{
- return new LocalDataStoreSlot ();
+ return new LocalDataStoreSlot (false);
}
public static LocalDataStoreSlot AllocateNamedDataSlot (string
name)
{
lock (namedSlots.SyncRoot)
{
- LocalDataStoreSlot slot = new
LocalDataStoreSlot ();
+ LocalDataStoreSlot slot = AllocateDataSlot ();
namedSlots.Add (name, slot);
return slot;
}
@@ -369,11 +369,12 @@
public static object GetData (LocalDataStoreSlot slot)
{
Context ctx = Thread.CurrentContext;
- if (ctx.datastore == null) return null;
-
- lock (ctx.datastore.SyncRoot)
+
+ lock (ctx)
{
- return ctx.datastore [slot];
+ if (ctx.datastore != null && slot.slot <
ctx.datastore.Length)
+ return ctx.datastore [slot.slot];
+ return null;
}
}
@@ -390,19 +391,17 @@
public static void SetData (LocalDataStoreSlot slot, object
data)
{
Context ctx = Thread.CurrentContext;
- if (ctx.datastore == null)
+ lock (ctx)
{
- lock (ctx)
- {
- if (ctx.datastore == null)
- ctx.datastore = new Hashtable
();
+ if (ctx.datastore == null) {
+ ctx.datastore = new object [slot.slot +
2];
+ } else if (slot.slot >= ctx.datastore.Length) {
+ object[] nslots = new object [slot.slot
+ 2];
+ ctx.datastore.CopyTo (nslots, 0);
+ ctx.datastore = nslots;
}
+ ctx.datastore [slot.slot] = data;
}
-
- lock (ctx.datastore.SyncRoot)
- {
- ctx.datastore [slot] = data;
- }
}
}
Modified: branches/mono-1-1-13/mcs/class/corlib/System.Threading/ChangeLog
===================================================================
--- branches/mono-1-1-13/mcs/class/corlib/System.Threading/ChangeLog
2006-03-20 14:18:25 UTC (rev 58185)
+++ branches/mono-1-1-13/mcs/class/corlib/System.Threading/ChangeLog
2006-03-20 14:31:59 UTC (rev 58186)
@@ -1,3 +1,10 @@
+
+Wed Mar 15 16:35:49 CET 2006 Paolo Molaro <[EMAIL PROTECTED]>
+
+ * Thread.cs: updates for LocalDataStoreSlot: we use an array as
+ storage for the slots now so that LocalDataStoreSlot objects an be
+ garbage collected if the user doesn't keep a reference to them.
+
2006-02-09 Miguel de Icaza <[EMAIL PROTECTED]>
* Monitor.cs: Patch from Thong Nguyen, Wait methods should allow a
Modified: branches/mono-1-1-13/mcs/class/corlib/System.Threading/Thread.cs
===================================================================
--- branches/mono-1-1-13/mcs/class/corlib/System.Threading/Thread.cs
2006-03-20 14:18:25 UTC (rev 58185)
+++ branches/mono-1-1-13/mcs/class/corlib/System.Threading/Thread.cs
2006-03-20 14:31:59 UTC (rev 58186)
@@ -105,8 +105,9 @@
private IntPtr unused7;
#endregion
+ // the name of local_slots is important as it's used by the
runtime.
[ThreadStatic]
- static Hashtable slothash;
+ static object[] local_slots;
// can be both a ThreadSart and a ParameterizedThreadStart
private MulticastDelegate threadstart;
@@ -171,58 +172,66 @@
}
}
- public static LocalDataStoreSlot AllocateNamedDataSlot(string
name) {
+ public static LocalDataStoreSlot AllocateNamedDataSlot (string
name) {
lock (datastore_lock) {
if (datastorehash == null)
InitDataStoreHash ();
- LocalDataStoreSlot slot =
(LocalDataStoreSlot)datastorehash[name];
- if(slot!=null) {
+ LocalDataStoreSlot slot =
(LocalDataStoreSlot)datastorehash [name];
+ if (slot != null) {
// This exception isnt documented (of
// course) but .net throws it
throw new ArgumentException("Named data
slot already added");
}
- slot = new LocalDataStoreSlot();
+ slot = AllocateDataSlot ();
- datastorehash.Add(name, slot);
+ datastorehash.Add (name, slot);
- return(slot);
+ return slot;
}
}
- public static void FreeNamedDataSlot(string name) {
+ public static void FreeNamedDataSlot (string name) {
lock (datastore_lock) {
if (datastorehash == null)
InitDataStoreHash ();
- LocalDataStoreSlot
slot=(LocalDataStoreSlot)datastorehash[name];
+ LocalDataStoreSlot slot =
(LocalDataStoreSlot)datastorehash [name];
- if(slot!=null) {
- datastorehash.Remove(slot);
+ if (slot != null) {
+ datastorehash.Remove (slot);
}
}
}
- private static Hashtable SlotHash {
- get {
- if (slothash == null)
- slothash = new Hashtable ();
- return slothash;
- }
+ public static LocalDataStoreSlot AllocateDataSlot () {
+ return new LocalDataStoreSlot (true);
}
- public static LocalDataStoreSlot AllocateDataSlot() {
- return new LocalDataStoreSlot();
+ public static object GetData (LocalDataStoreSlot slot) {
+ object[] slots = local_slots;
+ if (slot == null)
+ throw new ArgumentNullException ("slot");
+ if (slots != null && slot.slot < slots.Length)
+ return slots [slot.slot];
+ return null;
}
- public static object GetData(LocalDataStoreSlot slot) {
- return SlotHash [slot];
+ public static void SetData (LocalDataStoreSlot slot, object
data) {
+ object[] slots = local_slots;
+ if (slot == null)
+ throw new ArgumentNullException ("slot");
+ if (slots == null) {
+ slots = new object [slot.slot + 2];
+ local_slots = slots;
+ } else if (slot.slot >= slots.Length) {
+ object[] nslots = new object [slot.slot + 2];
+ slots.CopyTo (nslots, 0);
+ slots = nslots;
+ local_slots = slots;
+ }
+ slots [slot.slot] = data;
}
- public static void SetData(LocalDataStoreSlot slot,
- object data) {
- SlotHash [slot] = data;
- }
-
public static AppDomain GetDomain() {
return AppDomain.CurrentDomain;
}
@@ -230,6 +239,9 @@
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern static int GetDomainID();
+ [MethodImplAttribute (MethodImplOptions.InternalCall)]
+ internal extern static void FreeLocalSlotValues (int slot, bool
thread_local);
+
public static LocalDataStoreSlot GetNamedDataSlot(string name) {
lock (datastore_lock) {
if (datastorehash == null)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches