[Gc] Removal of Win32 CriticalSection for non-threaded case

Ivan Maidanski ivmai at mail.ru
Sun Oct 26 04:48:37 PST 2008


Hi!

Inspired by "Jack Andrews" <effbiae at gmail.com>!

This patch (for Win32 single-threaded) removes unnecessary GC_write_cs global var, Initialize/DeleteCriticalSection() imported calls (and
Enter/LeaveCriticalSection() for the case when compiled without optimizations).

Bye.

-------------- next part --------------
diff -ru bdwgc/misc.c updated/bdwgc/misc.c
--- bdwgc/misc.c	2008-10-25 17:00:42.000000000 +0400
+++ updated/bdwgc/misc.c	2008-10-26 13:57:56.000000000 +0300
@@ -412,7 +412,7 @@
     /* UNLOCK(); */
 }
 
-#if defined(MSWIN32) || defined(MSWINCE)
+#if (defined(MSWIN32) || defined(MSWINCE)) && defined(GC_THREADS)
     CRITICAL_SECTION GC_write_cs;
 #endif
 
@@ -495,7 +495,7 @@
   	  InitializeCriticalSection (&GC_allocate_ml);
       }
 #endif /* MSWIN32 */
-#   if defined(MSWIN32) || defined(MSWINCE)
+#   if (defined(MSWIN32) || defined(MSWINCE)) && defined(GC_THREADS)
       InitializeCriticalSection(&GC_write_cs);
 #   endif
 #   if (!defined(SMALL_CONFIG))
@@ -829,23 +829,26 @@
 
   void GC_deinit(void)
   {
+#   ifdef GC_THREADS
       if (GC_is_initialized) {
   	DeleteCriticalSection(&GC_write_cs);
       }
+#   endif
   }
 
-# ifndef THREADS
-#   define GC_need_to_lock 0  /* Not defined without threads */
-# endif
   int GC_write(const char *buf, size_t len)
   {
       BOOL tmp;
       DWORD written;
       if (len == 0)
 	  return 0;
-      if (GC_need_to_lock) EnterCriticalSection(&GC_write_cs);
+#     ifdef GC_THREADS
+	  if (GC_need_to_lock) EnterCriticalSection(&GC_write_cs);
+#     endif
       if (GC_stdout == INVALID_HANDLE_VALUE) {
-          if (GC_need_to_lock) LeaveCriticalSection(&GC_write_cs);
+#	  ifdef GC_THREADS
+	      if (GC_need_to_lock) LeaveCriticalSection(&GC_write_cs);
+#	  endif
 	  return -1;
       } else if (GC_stdout == 0) {
 	char * file_name = GETENV("GC_LOG_FILE");
@@ -873,10 +876,11 @@
 #     if defined(_MSC_VER) && defined(_DEBUG)
 	  _CrtDbgReport(_CRT_WARN, NULL, 0, NULL, "%.*s", len, buf);
 #     endif
-      if (GC_need_to_lock) LeaveCriticalSection(&GC_write_cs);
+#     ifdef GC_THREADS
+	  if (GC_need_to_lock) LeaveCriticalSection(&GC_write_cs);
+#     endif
       return tmp ? (int)written : -1;
   }
-# undef GC_need_to_lock
 
 #endif
 


More information about the Gc mailing list