[Libdispatch-changes] [10] trunk/src/semaphore.c

source_changes at macosforge.org source_changes at macosforge.org
Thu Sep 10 16:26:19 PDT 2009


Revision: 10
          http://trac.macosforge.org/projects/libdispatch/changeset/10
Author:   kvv at apple.com
Date:     2009-09-05 14:25:35 -0700 (Sat, 05 Sep 2009)
Log Message:
-----------
semaphore inline asm relies on gcc optimizer quirks

Modified Paths:
--------------
    trunk/src/semaphore.c

Modified: trunk/src/semaphore.c
===================================================================
--- trunk/src/semaphore.c	2009-09-05 21:24:16 UTC (rev 9)
+++ trunk/src/semaphore.c	2009-09-05 21:25:35 UTC (rev 10)
@@ -142,7 +142,7 @@
 again:
 	// Mach semaphores appear to sometimes spuriously wake up.  Therefore,
 	// we keep a parallel count of the number of times a Mach semaphore is
-	// signaled.
+	// signaled (6880961).
 	while ((orig = dsema->dsema_sent_ksignals)) {
 		if (dispatch_atomic_cmpxchg(&dsema->dsema_sent_ksignals, orig, orig - 1)) {
 			return 0;
@@ -198,7 +198,7 @@
 dispatch_group_enter(dispatch_group_t dg)
 {
 	dispatch_semaphore_t dsema = (dispatch_semaphore_t)dg;
-#if defined(__OPTIMIZE__) && defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
+#if defined(__OPTIMIZE__) && defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) && !defined(__llvm__)
 	// This assumes:
 	// 1) Way too much about the optimizer of GCC.
 	// 2) There will never be more than LONG_MAX threads.
@@ -210,7 +210,6 @@
 		"lock decl	%0\n\t"
 #endif
 		"js 	1f\n\t"
-		"xor	%%eax, %%eax\n\t"
 		"ret\n\t"
 		"1:"
 		: "+m" (dsema->dsema_value)
@@ -227,7 +226,7 @@
 long
 dispatch_semaphore_wait(dispatch_semaphore_t dsema, dispatch_time_t timeout)
 {
-#if defined(__OPTIMIZE__) && defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
+#if defined(__OPTIMIZE__) && defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) && !defined(__llvm__)
 	// This assumes:
 	// 1) Way too much about the optimizer of GCC.
 	// 2) There will never be more than LONG_MAX threads.
@@ -295,7 +294,7 @@
 long
 dispatch_semaphore_signal(dispatch_semaphore_t dsema)
 {
-#if defined(__OPTIMIZE__) && defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
+#if defined(__OPTIMIZE__) && defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) && !defined(__llvm__)
 	// overflow detection
 	// this assumes way too much about the optimizer of GCC
 	asm(
@@ -372,7 +371,7 @@
 	}
 	// Mach semaphores appear to sometimes spuriously wake up.  Therefore,
 	// we keep a parallel count of the number of times a Mach semaphore is
-	// signaled.
+	// signaled (6880961).
 	dispatch_atomic_inc(&dsema->dsema_group_waiters);
 	// check the values again in case we need to wake any threads
 	if (dsema->dsema_value == dsema->dsema_orig) {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/libdispatch-changes/attachments/20090910/4c2c43da/attachment-0001.html>


More information about the Libdispatch-changes mailing list