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 def_gc.c,1.5,1.6 hb_gc.c,1.9,1.


From: Gopal.V <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/support def_gc.c,1.5,1.6 hb_gc.c,1.9,1.10 wait.c,1.3,1.4 wait_mutex.c,1.3,1.4
Date: Wed, 25 Jun 2003 23:39:27 -0400

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

Modified Files:
        def_gc.c hb_gc.c wait.c wait_mutex.c 
Log Message:
Threading support, Patch #1657


Index: def_gc.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/support/def_gc.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** def_gc.c    15 May 2003 01:59:13 -0000      1.5
--- def_gc.c    26 Jun 2003 03:39:25 -0000      1.6
***************
*** 112,115 ****
--- 112,119 ----
  }
  
+ void ILGCDeinit()
+ {
+ }
+ 
  void *ILGCAlloc(unsigned long size)
  {
***************
*** 199,202 ****
--- 203,211 ----
  
  void ILGCUnregisterWeak(void *ptr)
+ {
+       /* Nothing to do here because we don't do finalization */
+ }
+ 
+ void ILGCRegisterGeneralWeak(void *ptr, void *obj)
  {
        /* Nothing to do here because we don't do finalization */

Index: hb_gc.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/support/hb_gc.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** hb_gc.c     17 Sep 2002 00:03:29 -0000      1.9
--- hb_gc.c     26 Jun 2003 03:39:25 -0000      1.10
***************
*** 4,7 ****
--- 4,9 ----
   * Copyright (C) 2001  Southern Storm Software, Pty Ltd.
   *
+  * Contributions by Thong Nguyen <address@hidden>
+  *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
***************
*** 20,23 ****
--- 22,28 ----
  
  #include "il_gc.h"
+ #include "il_thread.h"
+ #include "thr_defs.h"
+ #include "stdio.h"
  
  #ifdef HAVE_LIBGC
***************
*** 34,47 ****
  static int volatile FinalizersDisabled = 0;
  
  /*
   * Notify the finalization thread that there is work to do.
   */
! static void GCNotifyFinalize(void)
  {
!       if(!FinalizersDisabled)
        {
-               /* TODO: do finalization in a separate thread */
                GC_invoke_finalizers();
        }
  }
  
--- 39,142 ----
  static int volatile FinalizersDisabled = 0;
  
+ static volatile int g_Deinit = 0;
+ static ILThread *g_FinalizerThread;
+ static ILWaitHandle *g_FinalizerSignal;
+ static ILWaitHandle *g_FinalizerResponse;
+ 
+ #ifdef GC_TRACE_ENABLE
+       #define GC_TRACE(a, b)          printf(a, b)
+ #else
+       #define GC_TRACE(a, b)
+ #endif
+ 
+ /*
+  *    Main entry point for the finalizer thread.
+  */
+ static void FinalizerThreadFunc(void *data)
+ {
+       GC_TRACE("GC:FinalizerThread: Finalizer thread started [thread:%d]\n", 
(int)ILThreadSelf());
+ 
+       for (;;)
+       {
+               ILWaitOne(g_FinalizerSignal, -1);
+ 
+               GC_TRACE("GC:FinalizerThread: Signal [thread:%d]\n", 
(int)ILThreadSelf());
+ 
+               if (GC_should_invoke_finalizers())
+               {
+                       GC_TRACE("GC:FinalizerThread: Finalizers running 
[thread:%d]\n", (int)ILThreadSelf());
+ 
+                       GC_invoke_finalizers();
+ 
+                       GC_TRACE("GC:FinalizerThread: Finalizers finished 
[thread:%d]\n", (int)ILThreadSelf());
+               }
+               
+               if (g_Deinit)
+               {
+                       /* Exit finalizer thread after having invoked 
finalizers one last time */
+ 
+                       GC_TRACE("GC:FinalizerThread: Finalizer thread finished 
[thread:%d]\n", (int)ILThreadSelf());
+ 
+                       ILWaitEventReset(g_FinalizerSignal);
+                       ILWaitEventSet(g_FinalizerResponse);
+                       
+                       return;
+               }
+ 
+               GC_TRACE("GC:FinalizerThread: Response [thread:%d]\n", 
(int)ILThreadSelf());
+ 
+               ILWaitEventReset(g_FinalizerSignal);
+               ILWaitEventSet(g_FinalizerResponse);
+       }
+ }
+ 
  /*
   * Notify the finalization thread that there is work to do.
   */
! static int PrivateGCNotifyFinalize(void)
  {
!       ILExecThread *thread;
! 
!       if (!ILHasThreads())
        {
                GC_invoke_finalizers();
+ 
+               return;
        }
+ 
+       if(!FinalizersDisabled)
+       {
+               /* Register the finalizer thread for managed code execution */
+ 
+               ILThreadAtomicStart();
+ 
+               if (ILThreadGetObject(g_FinalizerThread) == 0)
+               {                       
+                       /* Make sure the the finalizer thread is registered for 
managed execution. */
+ 
+                       /* This can't be done in ILGCInit cause the runtime 
isn't fully initialized in that function */
+ 
+                       thread = (ILExecThread 
*)ILThreadGetObject(ILThreadSelf());
+ 
+                       
ILThreadRegisterForManagedExecution(ILExecThreadGetProcess(thread), 
g_FinalizerThread, 0);
+               }
+ 
+               ILThreadAtomicEnd();
+ 
+               /* Signal the finalizer thread */
+ 
+               ILWaitEventSet(g_FinalizerSignal);
+ 
+               return 1;
+       }
+       else
+       {
+               return 0;
+       }
+ }
+ 
+ static void GCNotifyFinalize(void)
+ {
+       PrivateGCNotifyFinalize();
  }
  
***************
*** 51,55 ****
        GC_init();              /* For Cygwin and Win32 threads */
        GC_set_max_heap_size((size_t)maxSize);
! 
        /* Set up the finalization system the way we want it */
        GC_finalize_on_demand = 1;
--- 146,150 ----
        GC_init();              /* For Cygwin and Win32 threads */
        GC_set_max_heap_size((size_t)maxSize);
!       
        /* Set up the finalization system the way we want it */
        GC_finalize_on_demand = 1;
***************
*** 57,60 ****
--- 152,181 ----
        GC_finalizer_notifier = GCNotifyFinalize;
        FinalizersDisabled = 0;
+ 
+       /* Create the finalizer thread */
+       g_Deinit = 0;
+       g_FinalizerThread = ILThreadCreate(FinalizerThreadFunc, 0);
+       
+       if (g_FinalizerThread)
+       {
+               g_FinalizerSignal = ILWaitEventCreate(1, 0);
+               g_FinalizerResponse = ILWaitEventCreate(1, 0);
+ 
+               ILThreadStart(g_FinalizerThread);
+       }
+ }
+ 
+ void ILGCDeinit()
+ {
+       g_Deinit = 1;
+ 
+       if (g_FinalizerThread)
+       {
+               /* Notify the finalizer thread */
+               ILWaitEventSet(g_FinalizerSignal);
+ 
+               /* Wait 10(!?) seconds for the finalizers to finish */
+               ILWaitOne(g_FinalizerResponse, 10000);
+       }
  }
  
***************
*** 94,98 ****
        /* We use the Java-style finalization algorithm, which
           ignores cycles in the object structure */
!       GC_REGISTER_FINALIZER_NO_ORDER(block, func, data, 0, 0);
  }
  
--- 215,219 ----
        /* We use the Java-style finalization algorithm, which
           ignores cycles in the object structure */
!       GC_REGISTER_FINALIZER_NO_ORDER(block, func, data, 0, 0);        
  }
  
***************
*** 109,114 ****
  void ILGCInvokeFinalizers(void)
  {
!       GCNotifyFinalize();
!       /* TODO: wait for the finalizer thread to complete its work */
  }
  
--- 230,253 ----
  void ILGCInvokeFinalizers(void)
  {
!       if (!ILHasThreads())
!       {
!               PrivateGCNotifyFinalize();
! 
!               return;
!       }
! 
!       if(!FinalizersDisabled)
!       {
!               /* Signal the finalizers to run (returns 1 if successful) */
!               if (PrivateGCNotifyFinalize())
!               {
!                       GC_TRACE("ILGCInvokeFinalizers: Invoked finalizers and 
waiting [thread: %d]\n", (int)ILThreadSelf());
!                       
!                       /* Wait until finalizers have finished */
!                       ILWaitOne(g_FinalizerResponse, -1);
! 
!                       GC_TRACE("ILGCInvokeFinalizers: Finalizers 
finished[thread: %d]\n", (int)ILThreadSelf());
!               }
!       }
  }
  
***************
*** 136,139 ****
--- 275,283 ----
  {
        GC_unregister_disappearing_link(ptr);
+ }
+ 
+ void ILGCRegisterGeneralWeak(void *ptr, void *obj)
+ {
+       GC_general_register_disappearing_link(ptr, obj);
  }
  

Index: wait.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/support/wait.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** wait.c      7 Dec 2002 10:46:55 -0000       1.3
--- wait.c      26 Jun 2003 03:39:25 -0000      1.4
***************
*** 119,122 ****
--- 119,123 ----
        /* Register this thread with the handle */
        result = (*(handle->registerFunc))(handle, wakeup);
+ 
        if(result == IL_WAITREG_ACQUIRED)
        {
***************
*** 131,134 ****
--- 132,136 ----
                return LeaveWait(thread, IL_WAIT_FAILED);
        }
+ 
  
        /* Wait until we are signalled, timed out, or interrupted */

Index: wait_mutex.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/support/wait_mutex.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** wait_mutex.c        15 Feb 2003 10:11:43 -0000      1.3
--- wait_mutex.c        26 Jun 2003 03:39:25 -0000      1.4
***************
*** 342,346 ****
  }
  
! int ILWaitMutexRelease(ILWaitHandle *handle)
  {
        ILWaitMutex *mutex = (ILWaitMutex *)handle;
--- 342,346 ----
  }
  
! int PrivateILWaitMutexRelease(ILWaitHandle *handle, int mode)
  {
        ILWaitMutex *mutex = (ILWaitMutex *)handle;
***************
*** 361,368 ****
                result = 0;
        }
!       else if(--(mutex->count) == 0)
        {
-               /* The count has returned to zero, so find something
-                  else to give the ownership of the mutex to */
                mutex->owner = _ILWakeupQueueWake(&(mutex->queue));
                if(mutex->owner != 0)
--- 361,366 ----
                result = 0;
        }
!       else if (mutex->count == 0 && mode == 2)
        {
                mutex->owner = _ILWakeupQueueWake(&(mutex->queue));
                if(mutex->owner != 0)
***************
*** 372,375 ****
--- 370,396 ----
                result = 1;
        }
+       else if(--(mutex->count) == 0)
+       {
+               /* The count has returned to zero, so find something
+                  else to give the ownership of the mutex to */
+ 
+               if (mode == 0)
+               {
+                       mutex->owner = _ILWakeupQueueWake(&(mutex->queue));
+                       if(mutex->owner != 0)
+                       {
+                               mutex->count = 1;
+                       }
+                       result = 1;
+               }
+               else if (mode == 1)
+               {
+                       result = 1;
+               }
+               else
+               {
+                       result = 0;
+               }
+       }
        else
        {
***************
*** 383,386 ****
--- 404,412 ----
  }
  
+ int ILWaitMutexRelease(ILWaitHandle *handle)
+ {
+       return PrivateILWaitMutexRelease(handle, 0);
+ }
+ 
  /*
   * Close a monitor.
***************
*** 570,573 ****
--- 596,630 ----
        _ILMutexUnlock(&(monitor->parent.parent.lock));
        return result;
+ }
+ 
+ int ILWaitMonitorCanClose(ILWaitHandle *handle)
+ {
+       ILMonitor *monitor = (ILMonitor *)handle;
+ 
+       _ILMutexLock(&(monitor->parent.parent.lock));
+ 
+       if(monitor->parent.count == 0 &&
+               _ILWakeupQueueIsEmpty(&(monitor->parent.queue)))
+       {
+               _ILMutexUnlock(&(monitor->parent.parent.lock));
+ 
+               return 1;
+       }
+       else
+       {
+               _ILMutexUnlock(&(monitor->parent.parent.lock));
+ 
+               return 0;       
+       }
+ }
+ 
+ int ILWaitMonitorSpeculativeLeave(ILWaitHandle *handle)
+ {
+       return PrivateILWaitMutexRelease(handle, 1);
+ }
+ 
+ int ILWaitMonitorCompleteLeave(ILWaitHandle *handle)
+ {
+       return PrivateILWaitMutexRelease(handle, 2);
  }
  





reply via email to

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