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

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

[Dotgnu-pnet-commits] CVS: pnet/engine engine.h,1.76,1.77 lib_defs.h,1.


From: Thong Nguyen <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/engine engine.h,1.76,1.77 lib_defs.h,1.23,1.24 lib_thread.c,1.13,1.14 thread.c,1.16,1.17
Date: Sat, 05 Jul 2003 04:30:59 -0400

Update of /cvsroot/dotgnu-pnet/pnet/engine
In directory subversions:/tmp/cvs-serv4126/engine

Modified Files:
        engine.h lib_defs.h lib_thread.c thread.c 
Log Message:
Various threading updates.


Index: engine.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/engine.h,v
retrieving revision 1.76
retrieving revision 1.77
diff -C2 -r1.76 -r1.77
*** engine.h    28 Jun 2003 00:45:49 -0000      1.76
--- engine.h    5 Jul 2003 08:30:56 -0000       1.77
***************
*** 202,207 ****
        ILExecThread   *prevThread;
  
!       /* Operating system thread object */
!       ILThread       *osThread;
  
        /* Extent of the execution stack */
--- 202,207 ----
        ILExecThread   *prevThread;
  
!       /* Support thread object */
!       ILThread       *supportThread;
  
        /* Extent of the execution stack */
***************
*** 223,227 ****
  
        /* System.Threading.Thread object */
!       ILObject        *clrThread;
  
        /* Free monitors list */
--- 223,227 ----
  
        /* System.Threading.Thread object */
!       ILObject *clrThread;
  
        /* Free monitors list */

Index: lib_defs.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/lib_defs.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -r1.23 -r1.24
*** lib_defs.h  26 Jun 2003 09:31:47 -0000      1.23
--- lib_defs.h  5 Jul 2003 08:30:56 -0000       1.24
***************
*** 298,302 ****
  typedef struct
  {
!       void       *privateData;
        ILObject   *stateInfo;
        ILObject   *start;
--- 298,302 ----
  typedef struct
  {
!       ILThread   *privateData;
        ILObject   *stateInfo;
        ILObject   *start;

Index: lib_thread.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/lib_thread.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** lib_thread.c        29 Jun 2003 21:38:12 -0000      1.13
--- lib_thread.c        5 Jul 2003 08:30:56 -0000       1.14
***************
*** 29,32 ****
--- 29,40 ----
  
  /*
+  *    Comments on terminology:
+  *
+  * Support Thread:    Refers to an ILThread instance.
+  * Engine Thread:             Refers to an ILExecThread instance.
+  * CLR Thread:                Refers to a System.Threading.Thread instance. 
+  */
+ 
+ /*
   *    Timeout value the managed WaitHandle uses.
   */
***************
*** 824,828 ****
  
        /* Invoke the ThreadStart delegate */
!       ILExecThreadCall(thread, method, &result, *((ILObject 
**)thread->clrThread + 2));
  
        /* Print out any uncaught exceptions */
--- 832,836 ----
  
        /* Invoke the ThreadStart delegate */
!       ILExecThreadCall(thread, method, &result, ((System_Thread 
*)thread->clrThread)->start);
  
        /* Print out any uncaught exceptions */
***************
*** 840,847 ****
  void _IL_Thread_InitializeThread(ILExecThread *thread, ILObject *_this)
  {
!       ILThread *osThread;
!       ILExecThread *newThread;
  
!       if (*((ILThread **)_this) != NULL)
        {
                /* InitializeThread can't be called more than once */
--- 848,854 ----
  void _IL_Thread_InitializeThread(ILExecThread *thread, ILObject *_this)
  {
!       ILThread *supportThread;
  
!       if (((System_Thread *)_this)->privateData != NULL)
        {
                /* InitializeThread can't be called more than once */
***************
*** 851,858 ****
                return;
        }
! 
!       /* Create a new OS-level thread */
! 
!       if ((osThread = ILThreadCreate(__PrivateThreadStart, 0)) == 0)
        {
                /* Threading isn't supported */
--- 858,863 ----
                return;
        }
!       
!       if (!ILHasThreads())
        {
                /* Threading isn't supported */
***************
*** 864,888 ****
        }
  
!       /* Register the OS-level thread for managed code execution */
  
!       if (ILThreadRegisterForManagedExecution(thread->process, osThread, 1) 
== 0)
        {
!               /* Runtime isn't fully initialized.  This should never happen */
! 
!               ILExecThreadThrowSystem(thread, 
"System.ExecutionEngineException",
!                       "Exception_UnexpectedEngineState");
! 
                return;
        }
  
!       /* Get the ILExecThread from the OS-level thread */
!       /* The ILExecThread should already be associated with the OS-level 
thread */
!       newThread = (ILExecThread *)ILThreadGetObject(osThread);
!       
!       /* Associate the CLR-level thread with the engine-level thread */
!       newThread->clrThread = _this;
! 
!       /* Associate the OS-level thread with the CLR-level thread */
!       *((ILThread **)_this) = osThread;
  }
  
--- 869,886 ----
        }
  
!       /* Create a new support thread */
  
!       if ((supportThread = ILThreadCreate(__PrivateThreadStart, 0)) == 0)
        {
!               /* Threading is supported but creation failed.
!                       ThrowOutOfMemoryException */
!                       
!               ILExecThreadThrowOutOfMemory(thread);
!               
                return;
        }
  
!       /* Associate the support thread with the CLR thread */
!       ((System_Thread *)_this)->privateData = supportThread;
  }
  
***************
*** 892,907 ****
  void _IL_Thread_FinalizeThread(ILExecThread *thread, ILObject *_this)
  {
!       /*
!        * TODO:
!        *
!        * Some parts of ILThreadDestroy should probably be performed 
immediately
!        * after the thread has finished executing (to free up OS handles 
early).
!        */
! 
!       /* This will be null if threads aren't supported and someone creates a 
Thread */
! 
!       if (*((ILThread **)_this))
        {
!               ILThreadDestroy(*((ILThread **)_this));
        }
  }
--- 890,900 ----
  void _IL_Thread_FinalizeThread(ILExecThread *thread, ILObject *_this)
  {
!       ILThread *supportThread;
!       
!       supportThread = ((System_Thread *)_this)->privateData;
!       
!       if (supportThread)
        {
!               ILThreadDestroy(supportThread);
        }
  }
***************
*** 912,916 ****
  void _IL_Thread_Abort(ILExecThread *thread, ILObject *_this)
  {     
!       ILThreadAbort(*((ILThread **)_this));
  }
  
--- 905,941 ----
  void _IL_Thread_Abort(ILExecThread *thread, ILObject *_this)
  {     
!       ILThreadAbort(((System_Thread *)_this)->privateData);
! }
! 
! /*
!  * public void Interrupt();
!  */
! void _IL_Thread_Interrupt(ILExecThread *thread, ILObject *_this)
! {     
!       ILThreadInterrupt(((System_Thread *)_this)->privateData);
! }
! 
! /*
!  * public void Suspend();
!  */
! void _IL_Thread_Suspend(ILExecThread *thread, ILObject *_this)
! {     
!       if (ILThreadSuspend(((System_Thread *)_this)->privateData) == 0)
!       {
!               ILExecThreadThrowSystem
!                       (
!                               thread,
!                               "System.Threading.ThreadStateException",
!                               (const char *)0
!                       );
!       }
! }
! 
! /*
!  * public void Resume();
!  */
! void _IL_Thread_Resume(ILExecThread *thread, ILObject *_this)
! {     
!       ILThreadResume(((System_Thread *)_this)->privateData);
  }
  
***************
*** 921,925 ****
                                                           ILInt32 timeout)
  {     
!       switch (ILThreadJoin((*((ILThread **)_this)), timeout))
        {       
        case IL_JOIN_OK:
--- 946,954 ----
                                                           ILInt32 timeout)
  {     
!       ILThread *supportThread;
! 
!       supportThread = ((System_Thread *)_this)->privateData;
!       
!       switch (ILThreadJoin(supportThread, timeout))
        {       
        case IL_JOIN_OK:
***************
*** 979,987 ****
  void _IL_Thread_ResetAbort(ILExecThread *thread)
  {
!       if ((ILThreadGetState(thread->osThread) & IL_TS_ABORT_REQUESTED) != 0)
        {
                /* No abort has been requested */
  
!               ILExecThreadThrowSystem(thread, 
"System.Threading.ThreadStateException", (const char *)0);
  
                return;
--- 1008,1017 ----
  void _IL_Thread_ResetAbort(ILExecThread *thread)
  {
!       if ((ILThreadGetState(thread->supportThread) & IL_TS_ABORT_REQUESTED) 
!= 0)
        {
                /* No abort has been requested */
  
!               ILExecThreadThrowSystem(thread,
!                       "System.Threading.ThreadStateException", (const char 
*)0);
  
                return;
***************
*** 1004,1018 ****
  void _IL_Thread_Start(ILExecThread *thread, ILObject *_this)
  {
!       if ((ILThreadGetState(*((ILThread **)_this)) & IL_TS_UNSTARTED) == 0)
        {
                /* Thread has already been started or has ended. */
  
                ILExecThreadThrowSystem(thread, 
"System.Threading.ThreadStateException", 
                        "Exception_ThreadAlreadyStarted");
  
                return;
        }
  
!       ILThreadStart(*((ILThread **)_this));
  }
  
--- 1034,1102 ----
  void _IL_Thread_Start(ILExecThread *thread, ILObject *_this)
  {
!       ILThread *supportThread;
!       ILExecThread *execThread;
! 
!       _IL_Monitor_Enter(thread, _this);
! 
!       /* Get the support thread stored inside the first field of the 
!       CLR thread by _IL_Thread_InitializeThread */
! 
!       supportThread = ((System_Thread *)_this)->privateData;
!       
!       if (supportThread == 0
!               || (ILThreadGetState(supportThread) & IL_TS_UNSTARTED) == 0)
        {
                /* Thread has already been started or has ended. */
  
+               _IL_Monitor_Exit(thread, _this);
+ 
                ILExecThreadThrowSystem(thread, 
"System.Threading.ThreadStateException", 
                        "Exception_ThreadAlreadyStarted");
+               
+               return;
+       }
+ 
+       /* Register the support thread for managed code execution */
+ 
+       if ((execThread = ILThreadRegisterForManagedExecution(thread->process, 
supportThread, 1)) == 0)
+       {
+               /* Runtime isn't fully initialized.  This should never happen */
+ 
+               _IL_Monitor_Exit(thread, _this);
  
+               ILExecThreadThrowSystem(thread, 
"System.ExecutionEngineException",
+                       "Exception_UnexpectedEngineState");
+               
                return;
        }
+       
+       /* Associate the CLR thread with the engine thread */
+ 
+       execThread->clrThread = _this;
+ 
+       /* Start the support thread */
+ 
+       if (ILThreadStart(supportThread) == 0)
+       {
+               /* Start unsuccessul.  Do a GC then try again */
+ 
+               ILGCCollect();
+               ILGCInvokeFinalizers();
+       
+               if (ILThreadStart(supportThread) == 0)
+               {
+                       /* Start unsuccessful.  Destroy the support & engine 
threads */
+ 
+                       ((System_Thread *)_this)->privateData = 0;              
+                       ILThreadDestroy(supportThread);
+                       ILExecThreadDestroy(execThread);
+ 
+                       /* Throw an OutOfMemoryException */
  
!                       ILExecThreadThrowOutOfMemory(thread);
!               }
!       }
!       
!       _IL_Monitor_Exit(thread, _this);
  }
  
***************
*** 1031,1035 ****
                                                                          
ILObject *_this, ILBool value)
  {
!       ILThreadSetBackground(*((ILThread **)_this), value);
  }
  
--- 1115,1119 ----
                                                                          
ILObject *_this, ILBool value)
  {
!       ILThreadSetBackground(((System_Thread *)_this)->privateData, value);
  }
  
***************
*** 1039,1043 ****
  ILInt32 _IL_Thread_InternalGetPriority(ILExecThread *thread, ILObject *_this)
  {
!       if ((ILThreadGetState(*((ILThread **)_this)) 
                        & (IL_TS_ABORTED | IL_TS_ABORT_REQUESTED | 
IL_TS_STOPPED)) != 0)
        {
--- 1123,1131 ----
  ILInt32 _IL_Thread_InternalGetPriority(ILExecThread *thread, ILObject *_this)
  {
!       ILThread *supportThread;
! 
!       supportThread = ((System_Thread *)_this)->privateData;
! 
!       if ((ILThreadGetState(supportThread) 
                        & (IL_TS_ABORTED | IL_TS_ABORT_REQUESTED | 
IL_TS_STOPPED)) != 0)
        {
***************
*** 1058,1062 ****
                                                                        ILInt32 
priority)
  {
!       if ((ILThreadGetState(*((ILThread **)_this))
                        & (IL_TS_ABORTED | IL_TS_ABORT_REQUESTED | 
IL_TS_STOPPED)) != 0)
        {
--- 1146,1154 ----
                                                                        ILInt32 
priority)
  {
!       ILThread *supportThread;
!       
!       supportThread = ((System_Thread *)_this)->privateData;
! 
!       if ((ILThreadGetState(supportThread)
                        & (IL_TS_ABORTED | IL_TS_ABORT_REQUESTED | 
IL_TS_STOPPED)) != 0)
        {
***************
*** 1072,1076 ****
  ILInt32 _IL_Thread_InternalGetState(ILExecThread *thread, ILObject *_this)
  {
!       return ILThreadGetState(*((ILThread **)_this));
  }
  
--- 1164,1168 ----
  ILInt32 _IL_Thread_InternalGetState(ILExecThread *thread, ILObject *_this)
  {
!       return ILThreadGetState(((System_Thread *)_this)->privateData);
  }
  

Index: thread.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/thread.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -r1.16 -r1.17
*** thread.c    26 Jun 2003 03:39:25 -0000      1.16
--- thread.c    5 Jul 2003 08:30:56 -0000       1.17
***************
*** 54,58 ****
                clrThread = _ILEngineAllocObject(thread, classInfo);
  
!               /* Assocaite the CLR thread object with the OS thread */
  
                *((ILThread **)clrThread) = ILThreadSelf();
--- 54,58 ----
                clrThread = _ILEngineAllocObject(thread, classInfo);
  
!               /* Associate the CLR thread object with the OS thread */
  
                *((ILThread **)clrThread) = ILThreadSelf();
***************
*** 83,87 ****
  
        /* Associate the OS-level thread with the new engine-level thread */
!       execThread->osThread = thread;
  
        return execThread;
--- 83,87 ----
  
        /* Associate the OS-level thread with the new engine-level thread */
!       execThread->supportThread = thread;
  
        return execThread;
***************
*** 121,125 ****
  
        /* Initialize the thread state */
!       thread->osThread = 0;
        thread->clrThread = 0;  
        thread->freeMonitor = 0;
--- 121,125 ----
  
        /* Initialize the thread state */
!       thread->supportThread = 0;
        thread->clrThread = 0;  
        thread->freeMonitor = 0;





reply via email to

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