This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] remove darwin from libgomp's target.
Shantonu Sen wrote:
Here's what I have so far, with the new files as attachments. In
particular, I haven't verified that the cancellation point semantics are
preserved with respect to the POSIX semaphore version. I also dumped the
files in libgomp/config/darwin. A longer term fix would probably involve
more autoconf checks, and having this version alongside the POSIX
semaphore version in libgomp/config/posix, and using the appropriate
version, since they both use POSIX features.
I guess I should get a copyright assignment process going...
Shantonu,
I've taken your work and tried to integrate it into the current
infrastructure.
Patch attached. (autoheader, autoconf needed in libgomp)
I've ran a build on three platforms to make sure that it still works.
(darwin-ppc, linux-ppc, sparc-solaris8 multilib)
Darwin-ppc reports the same as your run, 122/5. (the others as well)
Great!!!
Regards,
Andreas
Index: configure.ac
===================================================================
--- configure.ac (revision 110365)
+++ 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 110365)
+++ 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).
@@ -46,6 +46,27 @@
# 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 +85,5 @@
{
sem_destroy (sem);
}
-
+#endif
#endif /* GOMP_SEM_H */
Index: config/posix/sem.c
===================================================================
--- config/posix/sem.c (revision 110365)
+++ 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).
@@ -35,7 +35,84 @@
#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 +121,4 @@
while (sem_wait (sem) != 0)
continue;
}
+#endif