summaryrefslogtreecommitdiff
path: root/libgomp/config
diff options
context:
space:
mode:
authorandreast <andreast@138bc75d-0d04-0410-961f-82ee72b054a4>2006-02-25 21:23:09 +0000
committerandreast <andreast@138bc75d-0d04-0410-961f-82ee72b054a4>2006-02-25 21:23:09 +0000
commit59da30e18db6518a527b4e6ad223deaab4bd71a9 (patch)
tree35e1a6bf9ec819162ff656bdf638454bf4206833 /libgomp/config
parent6003588fece0ad48b319f5fab4cced57adea8a8d (diff)
downloadgcc-59da30e18db6518a527b4e6ad223deaab4bd71a9.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@111441 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgomp/config')
-rw-r--r--libgomp/config/posix/sem.c84
-rw-r--r--libgomp/config/posix/sem.h30
2 files changed, 108 insertions, 6 deletions
diff --git a/libgomp/config/posix/sem.c b/libgomp/config/posix/sem.c
index e8374bda50d..b44cb5d16dd 100644
--- a/libgomp/config/posix/sem.c
+++ b/libgomp/config/posix/sem.c
@@ -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 @@ gomp_sem_wait (gomp_sem_t *sem)
while (sem_wait (sem) != 0)
continue;
}
+#endif
diff --git a/libgomp/config/posix/sem.h b/libgomp/config/posix/sem.h
index 776a60d1c16..7056abffcfa 100644
--- a/libgomp/config/posix/sem.h
+++ b/libgomp/config/posix/sem.h
@@ -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 @@ static inline void gomp_sem_destroy (gomp_sem_t *sem)
{
sem_destroy (sem);
}
-
-#endif /* GOMP_SEM_H */
+#endif /* doesn't HAVE_BROKEN_POSIX_SEMAPHORES */
+#endif /* GOMP_SEM_H */