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.
- From: Andreas Tobler <toa at pop dot agri dot ch>
- To: Diego Novillo <dnovillo at redhat dot com>
- Cc: Shantonu Sen <ssen at opendarwin dot org>, Mike Stump <mrs at apple dot com>, Andrew Pinski <pinskia at physics dot uc dot edu>, Eric Christopher <echristo at apple dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Richard Henderson <rth at redhat dot com>
- Date: Thu, 02 Feb 2006 23:09:45 +0100
- Subject: Re: [patch] remove darwin from libgomp's target.
- References: <43DD4883.6060102@pop.agri.ch> <921696CB-572A-460F-9157-A2EE908B460A@apple.com> <43DD4C7D.1070606@pop.agri.ch> <6e728a7cbcb90d3ec60a260eb2645666@physics.uc.edu> <BE313972-CBE8-454A-AB55-6BEA0B0C03BB@opendarwin.org> <EC395CC0-2867-4E12-98FB-585F92A21129@apple.com> <CD670CB4-C533-453C-8385-B8EE9F3670EF@opendarwin.org> <43DE8DF5.8080103@pop.agri.ch> <43E27CC1.5090204@redhat.com>
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