dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System LocalDataStoreSlot.cs,


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System LocalDataStoreSlot.cs, 1.1, 1.2
Date: Thu, 24 Jul 2003 02:30:39 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System
In directory subversions:/tmp/cvs-serv17640/runtime/System

Modified Files:
        LocalDataStoreSlot.cs 
Log Message:


Implement local data store slots for threads, based around
a "[ThreadStatic]" variable.


Index: LocalDataStoreSlot.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/LocalDataStoreSlot.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** LocalDataStoreSlot.cs       17 Apr 2003 10:36:07 -0000      1.1
--- LocalDataStoreSlot.cs       24 Jul 2003 06:30:36 -0000      1.2
***************
*** 27,42 ****
  public sealed class LocalDataStoreSlot
  {
        // Constructor.
!       [TODO]
!       internal LocalDataStoreSlot()
                        {
!                               // TODO
                        }
  
        // Destructor.
-       [TODO]
        ~LocalDataStoreSlot()
                        {
!                               // TODO
                        }
  
--- 27,147 ----
  public sealed class LocalDataStoreSlot
  {
+       // Internal state.
+       private LocalDataStoreSlot nextNamed;
+       private String name;
+       private int slotNum;
+       private bool free;
+       private bool isNamed;
+       private static int nextSlotNum;
+       private static LocalDataStoreSlot namedSlots;
+       [ThreadStatic] private static Object[] data;
+ 
        // Constructor.
!       internal LocalDataStoreSlot(bool isNamed, String name)
                        {
!                               this.isNamed = isNamed;
!                               this.name = name;
!                               lock(typeof(LocalDataStoreSlot))
!                               {
!                                       slotNum = nextSlotNum++;
!                               }
                        }
  
        // Destructor.
        ~LocalDataStoreSlot()
                        {
!                               // Not used in this implementation.
!                       }
! 
!       // Get a data store slot with a specific name.
!       internal static LocalDataStoreSlot GetNamed(String name)
!                       {
!                               lock(typeof(LocalDataStoreSlot))
!                               {
!                                       LocalDataStoreSlot slot = namedSlots;
!                                       while(slot != null)
!                                       {
!                                               if(slot.isNamed && slot.name == 
name)
!                                               {
!                                                       return slot;
!                                               }
!                                               slot = slot.nextNamed;
!                                       }
!                                       slot = new LocalDataStoreSlot(true, 
name);
!                                       slot.nextNamed = namedSlots;
!                                       namedSlots = slot;
!                                       return slot;
!                               }
!                       }
! 
!       // Free a data store slot with a specific name.
!       internal static void FreeNamed(String name)
!                       {
!                               lock(typeof(LocalDataStoreSlot))
!                               {
!                                       LocalDataStoreSlot slot = namedSlots;
!                                       LocalDataStoreSlot prev = null;
!                                       while(slot != null)
!                                       {
!                                               if(slot.isNamed && slot.name == 
name)
!                                               {
!                                                       if(prev != null)
!                                                       {
!                                                               prev.nextNamed 
= slot.nextNamed;
!                                                       }
!                                                       else
!                                                       {
!                                                               namedSlots = 
slot.nextNamed;
!                                                       }
!                                                       slot.free = true;
!                                                       return;
!                                               }
!                                               prev = slot;
!                                               slot = slot.nextNamed;
!                                       }
!                               }
!                       }
! 
!       // Get or set the data in this slot for the current thread.
!       internal Object Data
!                       {
!                               get
!                               {
!                                       if(free)
!                                       {
!                                               return null;
!                                       }
!                                       Object[] tempData = data;
!                                       if(tempData != null && slotNum < 
tempData.Length)
!                                       {
!                                               return tempData[slotNum];
!                                       }
!                                       else
!                                       {
!                                               return null;
!                                       }
!                               }
!                               set
!                               {
!                                       if(free)
!                                       {
!                                               return;
!                                       }
!                                       Object[] tempData = data;
!                                       if(tempData != null && slotNum < 
tempData.Length)
!                                       {
!                                               tempData[slotNum] = value;
!                                       }
!                                       else
!                                       {
!                                               Object[] tempData = new Object 
[(slotNum + 8) & ~7];
!                                               if(data != null)
!                                               {
!                                                       Array.Copy(data, 0, 
tempData, 0, data.Length);
!                                               }
!                                               data = tempData;
!                                               tempData[slotNum] = value;
!                                       }
!                               }
                        }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]