This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] remove darwin from libgomp's target.


Diego Novillo wrote:
Andreas Tobler wrote:

+  ret = pthread_cond_destroy(&sem->cond);
+
One space before '('. Happens all over the patch.

Technically, the patch is immediately obvious and I'd approve it, but
libgomp still has no maintainer, so you'd have to ask a GWP maintainer
(rth is the original author, so I'm CCing him).


Ok, here is the updated patch with a hopefully appropriate CL. Shantonu, I hope it is ok for regarding the ChangeLog?

Andreas


2006-02-02 Shantonu Sen <ssen@opendarwin.org>


	* config/posix/sem.h: Define BROKEN_POSIX_SEMAPHORES functions.
	* config/posix/sem.c: Implement the above.

2006-02-02 Andreas Tobler <a.tobler@schweiz.ch>

	* configure.ac (HAVE_BROKEN_POSIX_SEMAPHORES): Check for darwin and
	define HAVE_BROKEN_POSIX_SEMAPHORES.
	* configure: Rebuilt.
	* config.h.in: Rebuilt.

Index: configure.ac
===================================================================
--- configure.ac	(revision 110520)
+++ configure.ac	(working copy)
@@ -165,6 +165,14 @@
 # Check for functions needed.
 AC_CHECK_FUNCS(getloadavg clock_gettime)
 
+# Check for broken semaphore implementation on darwin.
+case "$host" in
+  *-darwin*)
+    AC_DEFINE(HAVE_BROKEN_POSIX_SEMAPHORES, 1,
+	Define if the Posix semaphores do not work on your system)
+    ;;
+esac
+
 # At least for glibc, clock_gettime is in librt.  But don't pull that
 # in if it still doesn't give us the function we want.
 if test $ac_cv_func_clock_gettime = no; then
Index: config/posix/sem.h
===================================================================
--- config/posix/sem.h	(revision 110519)
+++ config/posix/sem.h	(working copy)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
    Contributed by Richard Henderson <rth@redhat.com>.
 
    This file is part of the GNU OpenMP Library (libgomp).
@@ -13,7 +13,7 @@
    FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
    more details.
 
-   You should have received a copy of the GNU Lesser General Public License 
+   You should have received a copy of the GNU Lesser General Public License
    along with libgomp; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    MA 02110-1301, USA.  */
@@ -46,6 +46,28 @@
 # pragma GCC visibility pop
 #endif
 
+#ifdef HAVE_BROKEN_POSIX_SEMAPHORES
+#include <pthread.h>
+
+struct gomp_sem
+{
+  pthread_mutex_t	mutex;
+  pthread_cond_t	cond;
+  int			value;
+};
+
+typedef struct gomp_sem gomp_sem_t;
+
+extern void gomp_sem_init (gomp_sem_t *sem, int value);
+
+extern void gomp_sem_wait (gomp_sem_t *sem);
+
+extern void gomp_sem_post (gomp_sem_t *sem);
+
+extern void gomp_sem_destroy (gomp_sem_t *sem);
+
+#else /* HAVE_BROKEN_POSIX_SEMAPHORES  */
+
 typedef sem_t gomp_sem_t;
 
 static inline void gomp_sem_init (gomp_sem_t *sem, int value)
@@ -64,5 +86,5 @@
 {
   sem_destroy (sem);
 }
-
-#endif /* GOMP_SEM_H */
+#endif /* doesn't HAVE_BROKEN_POSIX_SEMAPHORES  */
+#endif /* GOMP_SEM_H  */
Index: config/posix/sem.c
===================================================================
--- config/posix/sem.c	(revision 110519)
+++ config/posix/sem.c	(working copy)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
    Contributed by Richard Henderson <rth@redhat.com>.
 
    This file is part of the GNU OpenMP Library (libgomp).
@@ -13,7 +13,7 @@
    FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
    more details.
 
-   You should have received a copy of the GNU Lesser General Public License 
+   You should have received a copy of the GNU Lesser General Public License
    along with libgomp; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    MA 02110-1301, USA.  */
@@ -35,7 +35,86 @@
 
 #include "libgomp.h"
 
+#ifdef HAVE_BROKEN_POSIX_SEMAPHORES
+#include <stdlib.h>
 
+void gomp_sem_init (gomp_sem_t *sem, int value)
+{
+  int ret;
+
+  ret = pthread_mutex_init (&sem->mutex, NULL);
+  if (ret)
+    return;
+
+  ret = pthread_cond_init (&sem->cond, NULL);
+  if (ret)
+    return;
+
+  sem->value = value;
+}
+
+void gomp_sem_wait (gomp_sem_t *sem)
+{
+  int ret;
+
+  ret = pthread_mutex_lock (&sem->mutex);
+  if (ret)
+    return;
+
+  if (sem->value > 0)
+    {
+      sem->value--;
+      ret = pthread_mutex_unlock (&sem->mutex);
+      return;
+    }
+
+  while (sem->value <= 0)
+    {
+      ret = pthread_cond_wait (&sem->cond, &sem->mutex);
+      if (ret)
+	{
+	  pthread_mutex_unlock (&sem->mutex);
+	  return;
+	}
+    }
+
+  sem->value--;
+  ret = pthread_mutex_unlock (&sem->mutex);
+  return;
+}
+
+void gomp_sem_post (gomp_sem_t *sem)
+{
+  int ret;
+
+  ret = pthread_mutex_lock (&sem->mutex);
+  if (ret)
+    return;
+
+  sem->value++;
+
+  ret = pthread_mutex_unlock (&sem->mutex);
+  if (ret)
+    return;
+
+  ret = pthread_cond_signal (&sem->cond);
+
+  return;
+}
+
+void gomp_sem_destroy (gomp_sem_t *sem)
+{
+  int ret;
+
+  ret = pthread_mutex_destroy (&sem->mutex);
+  if (ret)
+    return;
+
+  ret = pthread_cond_destroy (&sem->cond);
+
+  return;
+}
+#else /* HAVE_BROKEN_POSIX_SEMAPHORES  */
 void
 gomp_sem_wait (gomp_sem_t *sem)
 {
@@ -44,3 +123,4 @@
   while (sem_wait (sem) != 0)
     continue;
 }
+#endif

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]