Commit d349482e by Andreas Tobler

[multiple changes]

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

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

2006-02-25  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.

From-SVN: r111441
parent 332cf1b3
2006-02-25 Shantonu Sen <ssen@opendarwin.org>
* config/posix/sem.h: Define BROKEN_POSIX_SEMAPHORES functions.
* config/posix/sem.c: Implement the above.
2006-02-25 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.
2006-02-17 Francois-Xavier Coudert <coudert@clipper.ens.fr> 2006-02-17 Francois-Xavier Coudert <coudert@clipper.ens.fr>
PR bootstrap/26161 PR bootstrap/26161
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
/* Define to 1 if the target supports __attribute__((visibility(...))). */ /* Define to 1 if the target supports __attribute__((visibility(...))). */
#undef HAVE_ATTRIBUTE_VISIBILITY #undef HAVE_ATTRIBUTE_VISIBILITY
/* Define if the POSIX Semaphores do not work on your system. */
#undef HAVE_BROKEN_POSIX_SEMAPHORES
/* Define to 1 if you have the `clock_gettime' function. */ /* Define to 1 if you have the `clock_gettime' function. */
#undef HAVE_CLOCK_GETTIME #undef HAVE_CLOCK_GETTIME
......
/* Copyright (C) 2005 Free Software Foundation, Inc. /* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>. Contributed by Richard Henderson <rth@redhat.com>.
This file is part of the GNU OpenMP Library (libgomp). This file is part of the GNU OpenMP Library (libgomp).
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
more details. 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 along with libgomp; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */ MA 02110-1301, USA. */
...@@ -35,7 +35,86 @@ ...@@ -35,7 +35,86 @@
#include "libgomp.h" #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 void
gomp_sem_wait (gomp_sem_t *sem) gomp_sem_wait (gomp_sem_t *sem)
{ {
...@@ -44,3 +123,4 @@ gomp_sem_wait (gomp_sem_t *sem) ...@@ -44,3 +123,4 @@ gomp_sem_wait (gomp_sem_t *sem)
while (sem_wait (sem) != 0) while (sem_wait (sem) != 0)
continue; continue;
} }
#endif
/* Copyright (C) 2005 Free Software Foundation, Inc. /* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>. Contributed by Richard Henderson <rth@redhat.com>.
This file is part of the GNU OpenMP Library (libgomp). This file is part of the GNU OpenMP Library (libgomp).
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
more details. 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 along with libgomp; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */ MA 02110-1301, USA. */
...@@ -46,6 +46,28 @@ ...@@ -46,6 +46,28 @@
# pragma GCC visibility pop # pragma GCC visibility pop
#endif #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; typedef sem_t gomp_sem_t;
static inline void gomp_sem_init (gomp_sem_t *sem, int value) static inline void gomp_sem_init (gomp_sem_t *sem, int value)
...@@ -64,5 +86,5 @@ static inline void gomp_sem_destroy (gomp_sem_t *sem) ...@@ -64,5 +86,5 @@ static inline void gomp_sem_destroy (gomp_sem_t *sem)
{ {
sem_destroy (sem); sem_destroy (sem);
} }
#endif /* doesn't HAVE_BROKEN_POSIX_SEMAPHORES */
#endif /* GOMP_SEM_H */ #endif /* GOMP_SEM_H */
...@@ -164,6 +164,15 @@ AC_LINK_IFELSE( ...@@ -164,6 +164,15 @@ AC_LINK_IFELSE(
# Check for functions needed. # Check for functions needed.
AC_CHECK_FUNCS(getloadavg clock_gettime) AC_CHECK_FUNCS(getloadavg clock_gettime)
# Check for broken semaphore implementation on darwin.
# sem_init returns: sem_init error: Function not implemented.
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 # 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. # in if it still doesn't give us the function we want.
if test $ac_cv_func_clock_gettime = no; then if test $ac_cv_func_clock_gettime = no; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment