[Gc] a small patch for MSWIN

Jack Andrews effbiae at gmail.com
Fri Oct 24 09:49:39 PDT 2008


hi guys,

i've got gctest passing on windows (just single thread right now).
patch below.  lots more to come if you like this one !


ta, jack



Index: gc6.7/include/private/gcconfig.h
===================================================================
--- gc6.7.orig/include/private/gcconfig.h
+++ gc6.7/include/private/gcconfig.h
@@ -1229,6 +1229,13 @@
 #	define OS_TYPE "MSWINCE"
 #       define DATAEND  /* not needed */
 #   endif
+#   if defined(MSWIN32) || defined(MSWINCE)
+                /* lots of places use:                                  */
+                /*   #if defined(MSWIN32) || defined(MSWINCE)`          */
+                /* so simplify to `#ifdef MSWIN`                        */
+#       define MSWIN
+#       include "mswin.h"
+#   endif
 #   ifdef DJGPP
 #       define OS_TYPE "DJGPP"
 #       include "stubinfo.h"
Index: gc6.7/misc.c
===================================================================
--- gc6.7.orig/misc.c
+++ gc6.7/misc.c
@@ -32,6 +32,7 @@
 # define NOSERVICE
 # include <windows.h>
 # include <tchar.h>
+# include <private/mswin.h>
 #endif

 #ifdef NONSTOP
@@ -584,8 +585,8 @@ void GC_init_inner()
 #   ifdef PRINTSTATS
       GC_print_stats = 1;
 #   endif
-#   if defined(MSWIN32) || defined(MSWINCE)
-      InitializeCriticalSection(&GC_write_cs);
+#   if defined(MSWIN) && defined(THREADS)
+      INIT_CS(&GC_write_cs);
 #   endif
     if (0 != GETENV("GC_PRINT_STATS")) {
       GC_print_stats = 1;
@@ -851,7 +852,7 @@ out:
 }


-#if defined(MSWIN32) || defined(MSWINCE)
+#ifdef MSWIN
 # define LOG_FILE _T("gc.log")

   HANDLE GC_stdout = 0;
@@ -859,7 +860,7 @@ out:
   void GC_deinit()
   {
       if (GC_is_initialized) {
-  	DeleteCriticalSection(&GC_write_cs);
+  	DEL_CS(&GC_write_cs);
       }
   }

@@ -871,7 +872,7 @@ out:
       DWORD written;
       if (len == 0)
 	  return 0;
-      EnterCriticalSection(&GC_write_cs);
+      ENTER_CS(&GC_write_cs);
       if (GC_stdout == INVALID_HANDLE_VALUE) {
 	  return -1;
       } else if (GC_stdout == 0) {
@@ -884,7 +885,7 @@ out:
       tmp = WriteFile(GC_stdout, buf, len, &written, NULL);
       if (!tmp)
 	  DebugBreak();
-      LeaveCriticalSection(&GC_write_cs);
+      LEAVE_CS(&GC_write_cs);
       return tmp ? (int)written : -1;
   }

Index: gc6.7/tests/test.c
===================================================================
--- gc6.7.orig/tests/test.c
+++ gc6.7/tests/test.c
@@ -753,9 +753,7 @@ VOLATILE int dropped_something = 0;
     static pthread_mutex_t incr_lock = PTHREAD_MUTEX_INITIALIZER;
     pthread_mutex_lock(&incr_lock);
 # else
-#   ifdef GC_WIN32_THREADS
-      EnterCriticalSection(&incr_cs);
-#   endif
+    ENTER_CS(&incr_cs);
 # endif
   if ((int)(GC_word)client_data != t -> level) {
      (void)GC_printf0("Wrong finalization data - collector is broken\n");
@@ -772,9 +770,7 @@ VOLATILE int dropped_something = 0;
 # if defined(GC_PTHREADS)
     pthread_mutex_unlock(&incr_lock);
 # else
-#   ifdef GC_WIN32_THREADS
-      LeaveCriticalSection(&incr_cs);
-#   endif
+    LEAVE_CS(&incr_cs);
 # endif
 }

@@ -847,9 +843,7 @@ int n;
             static pthread_mutex_t incr_lock = PTHREAD_MUTEX_INITIALIZER;
             pthread_mutex_lock(&incr_lock);
 #         else
-#           ifdef GC_WIN32_THREADS
-              EnterCriticalSection(&incr_cs);
-#           endif
+            ENTER_CS(&incr_cs);
 #         endif
 		/* Losing a count here causes erroneous report of failure. */
           finalizable_count++;
@@ -863,9 +857,7 @@ int n;
 #	  if defined(GC_PTHREADS)
 	    pthread_mutex_unlock(&incr_lock);
 #	  else
-#           ifdef GC_WIN32_THREADS
-              LeaveCriticalSection(&incr_cs);
-#           endif
+            LEAVE_CS(&incr_cs);
 #         endif
 	}

@@ -1648,7 +1640,7 @@ int APIENTRY WinMain(HINSTANCE instance,
     GC_enable_incremental();
 # endif
   GC_init();
-  InitializeCriticalSection(&incr_cs);
+  INIT_CS(&incr_cs);
   (void) GC_set_warn_proc(warn_proc);
 # ifdef MSWINCE
     win_created_h = CreateEvent(NULL, FALSE, FALSE, NULL);
Index: gc6.7/win32_threads.c
===================================================================
--- gc6.7.orig/win32_threads.c
+++ gc6.7/win32_threads.c
@@ -244,9 +244,7 @@ void GC_stop_world()
   if (!GC_thr_initialized) ABORT("GC_stop_world() called before
GC_thr_init()");

   GC_please_stop = TRUE;
-# ifndef CYGWIN32
-    EnterCriticalSection(&GC_write_cs);
-# endif /* !CYGWIN32 */
+  ENTER_CS(&GC_write_cs);
   for (i = 0; i <= GC_get_max_thread_index(); i++)
     if (thread_table[i].stack_base != 0
 	&& thread_table[i].id != thread_id) {
@@ -277,9 +275,7 @@ void GC_stop_world()
 #     endif
       thread_table[i].suspended = TRUE;
     }
-# ifndef CYGWIN32
-    LeaveCriticalSection(&GC_write_cs);
-# endif /* !CYGWIN32 */
+    LEAVE_CS(&GC_write_cs);
 }

 void GC_start_world()
@@ -559,7 +555,7 @@ int WINAPI WinMain(HINSTANCE hInstance,
     }

     GC_deinit();
-    DeleteCriticalSection(&GC_allocate_ml);
+    DEL_CS(&GC_allocate_ml);

     return (int) exit_code;
 }
@@ -790,7 +786,7 @@ BOOL WINAPI DllMain(HINSTANCE inst, ULON
       UNLOCK();

       GC_deinit();
-      DeleteCriticalSection(&GC_allocate_ml);
+      DEL_CS(&GC_allocate_ml);
     }
     break;

Index: gc6.7/include/private/mswin.h
===================================================================
--- /dev/null
+++ gc6.7/include/private/mswin.h
@@ -0,0 +1,22 @@
+#ifndef _MSWIN_H
+
+# define _MSWIN_H
+
+#  ifndef MSWIN
+#    error only for use on native windows
+#  endif
+
+#  if defined(GC_WIN32_THREADS)
+#    define INIT_CS(x)  InitializeCriticalSection(x)
+#    define ENTER_CS(x) EnterCriticalSection(x)
+#    define LEAVE_CS(x) LeaveCriticalSection(x)
+#    define DEL_CS(x)   DeleteCriticalSection(x)
+#  else
+#    define INIT_CS(x)
+#    define ENTER_CS(x)
+#    define LEAVE_CS(x)
+#    define DEL_CS(x)
+#  endif
+
+
+#endif //_MSWIN_H


More information about the Gc mailing list