[Gc] Atomicityfor LOCK_STATS

Ivan Maidanski ivmai at mail.ru
Wed Nov 12 07:33:56 PST 2008


Hi!

This patch replaces "++" with AO_fetch_and_add1() for locking statistics counters in "pthread_support.c" and "win32_threads.c" files (as suggested by Boehm).

Bye.

-------------- next part --------------
diff -ru bdwgc/pthread_support.c updated/bdwgc/pthread_support.c
--- bdwgc/pthread_support.c	2008-10-28 18:07:32.000000000 +0300
+++ updated/bdwgc/pthread_support.c	2008-11-12 16:36:34.000000000 +0300
@@ -1264,9 +1264,9 @@
 
 /* #define LOCK_STATS */
 #ifdef LOCK_STATS
-  unsigned long GC_spin_count = 0;
-  unsigned long GC_block_count = 0;
-  unsigned long GC_unlocked_count = 0;
+  AO_t GC_spin_count = 0;
+  AO_t GC_block_count = 0;
+  AO_t GC_unlocked_count = 0;
 #endif
 
 STATIC void GC_generic_lock(pthread_mutex_t * lock)
@@ -1277,7 +1277,7 @@
     
     if (0 == pthread_mutex_trylock(lock)) {
 #       ifdef LOCK_STATS
-	    ++GC_unlocked_count;
+	    (void)AO_fetch_and_add1_full(&GC_unlocked_count);
 #       endif
 	return;
     }
@@ -1288,7 +1288,7 @@
         switch(pthread_mutex_trylock(lock)) {
 	    case 0:
 #		ifdef LOCK_STATS
-		    ++GC_spin_count;
+		    (void)AO_fetch_and_add1_full(&GC_spin_count);
 #		endif
 		return;
 	    case EBUSY:
@@ -1299,7 +1299,7 @@
     }
 #endif /* !NO_PTHREAD_TRYLOCK */
 #   ifdef LOCK_STATS
-	++GC_block_count;
+	(void)AO_fetch_and_add1_full(&GC_block_count);
 #   endif
     pthread_mutex_lock(lock);
 }
diff -ru bdwgc/win32_threads.c updated/bdwgc/win32_threads.c
--- bdwgc/win32_threads.c	2008-11-01 20:26:40.000000000 +0300
+++ updated/bdwgc/win32_threads.c	2008-11-12 16:36:58.000000000 +0300
@@ -1190,7 +1190,7 @@
 /* as in pthread_support.c except that GC_generic_lock() is not used.	*/
 
 #ifdef LOCK_STATS
-  unsigned long GC_block_count = 0;
+  AO_t GC_block_count = 0;
 #endif
 
 void GC_acquire_mark_lock(void)
@@ -1199,7 +1199,7 @@
 	ABORT("pthread_mutex_lock failed");
     }
 #   ifdef LOCK_STATS
-	++GC_block_count;
+	(void)AO_fetch_and_add1_full(&GC_block_count);
 #   endif
     /* GC_generic_lock(&mark_mutex); */
 #   ifdef GC_ASSERTIONS
@@ -1309,22 +1309,22 @@
 
 /* #define LOCK_STATS */
 #ifdef LOCK_STATS
-  unsigned long GC_block_count = 0;
-  unsigned long GC_unlocked_count = 0;
+  AO_t GC_block_count = 0;
+  AO_t GC_unlocked_count = 0;
 #endif
 
 void GC_acquire_mark_lock(void)
 {
     if (AO_fetch_and_add1_full(&GC_mark_mutex_waitcnt) != 0) {
 #	ifdef LOCK_STATS
-          ++GC_block_count;
+          (void)AO_fetch_and_add1_full(&GC_block_count);
 #	endif
         if (WaitForSingleObject(mark_mutex_event, INFINITE) == WAIT_FAILED)
           ABORT("WaitForSingleObject() failed");
     }
 #   ifdef LOCK_STATS
         else {
-	  ++GC_unlocked_count;
+	  (void)AO_fetch_and_add1_full(&GC_unlocked_count);
 	}
 #   endif
   


More information about the Gc mailing list