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

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

[Dotgnu-pnet-commits] CVS: pnet/support hb_gc.c,1.15,1.16 thread.c,1.7,1


From: Thong Nguyen <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/support hb_gc.c,1.15,1.16 thread.c,1.7,1.8
Date: Sat, 05 Jul 2003 18:51:35 -0400

Update of /cvsroot/dotgnu-pnet/pnet/support
In directory subversions:/tmp/cvs-serv12446/support

Modified Files:
        hb_gc.c thread.c 
Log Message:
Threading improvements.  Better background thread management.


Index: hb_gc.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/support/hb_gc.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** hb_gc.c     2 Jul 2003 23:42:53 -0000       1.15
--- hb_gc.c     5 Jul 2003 22:51:32 -0000       1.16
***************
*** 128,132 ****
                if (thread != 0)
                {
!                       
ILThreadRegisterForManagedExecution(ILExecThreadGetProcess(thread), 
g_FinalizerThread, 0);
                }
                else
--- 128,132 ----
                if (thread != 0)
                {
!                       
ILThreadRegisterForManagedExecution(ILExecThreadGetProcess(thread), 
g_FinalizerThread);
                }
                else
***************
*** 180,183 ****
--- 180,184 ----
  
                ILThreadStart(g_FinalizerThread);
+               ILThreadSetBackground(g_FinalizerThread, 1);
        }
  }

Index: thread.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/support/thread.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** thread.c    5 Jul 2003 08:24:49 -0000       1.7
--- thread.c    5 Jul 2003 22:51:32 -0000       1.8
***************
*** 39,42 ****
--- 39,43 ----
  static long volatile numThreads;
  static long volatile numBackgroundThreads;
+ static ILWaitHandle *foregroundThreadsFinished;
  
  /*
***************
*** 81,84 ****
--- 82,87 ----
        _ILWakeupQueueCreate(&(mainThread.joinQueue));
  
+       foregroundThreadsFinished = ILWaitEventCreate(1, 1);
+ 
        /* Set the thread object for the "main" thread */
        _ILThreadSetSelf(&mainThread);
***************
*** 89,92 ****
--- 92,103 ----
  }
  
+ void ThreadDeinit(void)
+ {
+       if (foregroundThreadsFinished != 0)
+       {
+               ILWaitHandleClose(foregroundThreadsFinished);
+       }
+ }
+ 
  void ILThreadInit(void)
  {
***************
*** 94,97 ****
--- 105,113 ----
  }
  
+ void ILThreadDeinit(void)
+ {
+       _ILCallOnce(ThreadDeinit);
+ }
+ 
  void _ILThreadRun(ILThread *thread)
  {
***************
*** 120,123 ****
--- 136,146 ----
                numBackgroundThreads -= 1;
        }
+ 
+       /* If there are no more foreground threads (except the main one) then 
set
+               the event that signals that state */
+       if(numThreads - numBackgroundThreads == 1)
+       {
+               ILWaitEventSet(foregroundThreadsFinished);
+       }
        _ILMutexUnlock(&threadLockAll);
  }
***************
*** 154,158 ****
        /* Lock out the thread system */
        _ILMutexLock(&threadLockAll);
! 
        /* We have one extra thread in the system at present */
        ++numThreads;
--- 177,181 ----
        /* Lock out the thread system */
        _ILMutexLock(&threadLockAll);
!       
        /* We have one extra thread in the system at present */
        ++numThreads;
***************
*** 182,185 ****
--- 205,220 ----
                        /* Set the thread state to running (0) */
                        thread->state &= ~IL_TS_UNSTARTED;
+                       
+                       /* If this thread isn't a background thread then unset 
the
+                               foregroundThreadsFinished event.
+                               This occurs here rather than in ILThreadCreate 
so that unstarted
+                               threads won't unset the 
foregroundThreadsFinished event without ever 
+                               setting it again (which normally happens at the 
end of _ILThreadRun) */
+ 
+                       if (!ILThreadGetBackground(thread))
+                       {
+                               ILWaitEventReset(foregroundThreadsFinished);
+                       }
+ 
                        result = 1;
                }
***************
*** 240,243 ****
--- 275,286 ----
                --numBackgroundThreads;
        }
+ 
+       /* If there are no more foreground threads (except the main one) then 
set
+               the event that signals that state */
+       if (numThreads - numBackgroundThreads == 1)
+       {
+               ILWaitEventSet(foregroundThreadsFinished);
+       }
+ 
        _ILMutexUnlock(&threadLockAll);
  }
***************
*** 638,641 ****
--- 681,692 ----
        _ILMutexLock(&threadLockAll);
        numBackgroundThreads += change;
+ 
+       /* If there are no more foreground threads (except the main one) then 
set
+               the event that signals that state */
+       if (numThreads - numBackgroundThreads == 1)
+       {
+               ILWaitEventSet(foregroundThreadsFinished);
+       }
+ 
        _ILMutexUnlock(&threadLockAll);
  }
***************
*** 753,756 ****
--- 804,816 ----
        _ILMutexUnlock(&(thread->lock));
        return result;
+ }
+ 
+ void ILThreadWaitForForegroundThreads(int timeout)
+ {
+ #ifdef IL_NO_THREADS
+       /* Nothing to do */
+ #else 
+       ILWaitOne(foregroundThreadsFinished, timeout);
+ #endif
  }
  





reply via email to

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