This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[libgomp] Add Unix95 mutex support
- From: Eric Botcazou <ebotcazou at libertysurf dot fr>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 16 Feb 2006 00:45:29 +0100
- Subject: [libgomp] Add Unix95 mutex support
Unix98 mutex support is not available on Solaris 2.5.1 and 2.6.
Built and tested on SPARC/Solaris 2.5.1 and SPARC/Solaris 2.6, results are
identical to SPARC/Solaris 7 which is Unix98. Also tested on AMD64/Linux.
OK for mainline?
2006-02-15 Eric Botcazou <ebotcazou@libertysurf.fr>
* configure.tgt: Pass -DLIBGOMP_UNIX95 to the compiler
and -lposix4 to the linker on Solaris 2.5.1 and 2.6.
* config/posix/omp-lock.h (omp_nest_lock_t): Add 'owner' field
for the Unix95 implementation.
* config/posix/lock.c: Do not define _XOPEN_SOURCE to 500 if Unix95.
(omp_init_nest_lock): Add Unix95 support.
(omp_set_nest_lock): Likewise.
(omp_unset_nest_lock): Likewise.
(omp_test_nest_lock): Likewise.
--
Eric Botcazou
Index: configure.tgt
===================================================================
--- configure.tgt (revision 111111)
+++ configure.tgt (working copy)
@@ -91,7 +91,9 @@ case "${target}" in
XLDFLAGS="${XLDFLAGS} -lrt"
;;
- *)
+ *-*-solaris2.[56]*)
+ XCFLAGS="$(XCFLAGS) -DLIBGOMP_UNIX95"
+ XLDFLAGS="${XLDFLAGS} -lposix4"
;;
esac
Index: config/posix/omp-lock.h
===================================================================
--- config/posix/omp-lock.h (revision 111111)
+++ config/posix/omp-lock.h (working copy)
@@ -8,4 +8,12 @@
#include <pthread.h>
typedef pthread_mutex_t omp_lock_t;
-typedef struct { pthread_mutex_t lock; int count; } omp_nest_lock_t;
+
+typedef struct
+{
+ pthread_mutex_t lock;
+#ifdef LIBGOMP_UNIX95
+ pthread_t owner;
+#endif
+ int count;
+} omp_nest_lock_t;
Index: config/posix/lock.c
===================================================================
--- config/posix/lock.c (revision 111111)
+++ config/posix/lock.c (working copy)
@@ -33,8 +33,10 @@
to do better and streamline the locking as well as reduce the size
of the types exported. */
+#ifndef LIBGOMP_UNIX95
/* We need Unix98 extensions to get recursive locks. */
#define _XOPEN_SOURCE 500
+#endif
#include "libgomp.h"
@@ -74,11 +76,16 @@ omp_init_nest_lock (omp_nest_lock_t *loc
{
pthread_mutexattr_t attr;
+#ifdef LIBGOMP_UNIX95
+ pthread_mutex_init (&lock->lock, NULL);
+#else
pthread_mutexattr_init (&attr);
pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init (&lock->lock, &attr);
- lock->count = 0;
pthread_mutexattr_destroy (&attr);
+#endif
+
+ lock->count = 0;
}
void
@@ -90,7 +97,18 @@ omp_destroy_nest_lock (omp_nest_lock_t *
void
omp_set_nest_lock (omp_nest_lock_t *lock)
{
+#ifdef LIBGOMP_UNIX95
+ pthread_t me = pthread_self ();
+
+ if (lock->owner != me)
+ {
+ pthread_mutex_lock (&lock->lock);
+ lock->owner = me;
+ }
+#else
pthread_mutex_lock (&lock->lock);
+#endif
+
lock->count++;
}
@@ -98,15 +116,36 @@ void
omp_unset_nest_lock (omp_nest_lock_t *lock)
{
lock->count--;
+
+#ifdef LIBGOMP_UNIX95
+ if (lock->count == 0)
+ {
+ lock->owner = (pthread_t) 0;
+ pthread_mutex_unlock (&lock->lock);
+ }
+#else
pthread_mutex_unlock (&lock->lock);
+#endif
}
int
omp_test_nest_lock (omp_nest_lock_t *lock)
{
+#ifdef LIBGOMP_UNIX95
+ pthread_t me = pthread_self ();
+
+ if (lock->owner != me)
+ {
+ if (pthread_mutex_trylock (&lock->lock) != 0)
+ return 0;
+ lock->owner = me;
+ }
+ return ++lock->count;
+#else
if (pthread_mutex_trylock (&lock->lock) == 0)
return ++lock->count;
return 0;
+#endif
}
ialias (omp_init_lock)