aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>2004-11-23 12:59:26 +0000
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>2004-11-23 12:59:26 +0000
commit9a1131445883cc11e4cbd8c38ca96fe1dfc58031 (patch)
tree9f10538b0f84abdc14d89454c5fbdb5abd358ac9 /gcc
parent351c2004d74261d7e793948b93aa6906e3a193f4 (diff)
* gthr-solaris.h (__gthread_recursive_mutex_t): New type.
(__GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION): Define to __gthread_recursive_mutex_init_function. (__gthread_key_create): Properly cast -1. (__gthread_recursive_mutex_init_function): New function. (__gthread_recursive_mutex_lock): Rewrite. (__gthread_recursive_mutex_trylock): Likewise. (__gthread_recursive_mutex_unlock): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@91086 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog11
-rw-r--r--gcc/gthr-solaris.h60
2 files changed, 64 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 95367aa2811..7488b6561a4 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@
+2004-11-23 Eric Botcazou <ebotcazou@libertysurf.fr>
+
+ * gthr-solaris.h (__gthread_recursive_mutex_t): New type.
+ (__GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION): Define to
+ __gthread_recursive_mutex_init_function.
+ (__gthread_key_create): Properly cast -1.
+ (__gthread_recursive_mutex_init_function): New function.
+ (__gthread_recursive_mutex_lock): Rewrite.
+ (__gthread_recursive_mutex_trylock): Likewise.
+ (__gthread_recursive_mutex_unlock): Likewise.
+
2004-11-23 Ralf Corsepius <ralf.corsepius@rtems.org>
* config/c4x/t-rtems: New.
diff --git a/gcc/gthr-solaris.h b/gcc/gthr-solaris.h
index f9b258035ba..a102262190d 100644
--- a/gcc/gthr-solaris.h
+++ b/gcc/gthr-solaris.h
@@ -44,11 +44,16 @@ typedef struct {
int once;
} __gthread_once_t;
typedef mutex_t __gthread_mutex_t;
-typedef mutex_t __gthread_recursive_mutex_t;
+
+typedef struct {
+ long depth;
+ thread_t owner;
+ mutex_t actual;
+} __gthread_recursive_mutex_t;
#define __GTHREAD_ONCE_INIT { DEFAULTMUTEX, 0 }
#define __GTHREAD_MUTEX_INIT DEFAULTMUTEX
-#define __GTHREAD_RECURSIVE_MUTEX_INIT RECURSIVE_ERRORCHECKMUTEX
+#define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
#if SUPPORTS_WEAK && GTHREAD_USE_WEAK
@@ -411,8 +416,8 @@ __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
{
/* Solaris 2.5 contains thr_* routines no-op in libc, so test if we actually
got a reasonable key value, and if not, fail. */
- *key = -1;
- if (thr_keycreate (key, dtor) != 0 || *key == -1)
+ *key = (__gthread_key_t)-1;
+ if (thr_keycreate (key, dtor) != 0 || *key == (__gthread_key_t)-1)
return -1;
else
return 0;
@@ -469,21 +474,62 @@ __gthread_mutex_unlock (__gthread_mutex_t *mutex)
}
static inline int
+__gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *mutex)
+{
+ mutex->depth = 0;
+ mutex->owner = (thread_t) 0;
+ return mutex_init (&mutex->actual, USYNC_THREAD, NULL);
+}
+
+static inline int
__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
{
- return __gthread_mutex_lock (mutex);
+ if (__gthread_active_p ())
+ {
+ thread_t me = thr_self ();
+
+ if (mutex->owner != me)
+ {
+ mutex_lock (&mutex->actual);
+ mutex->owner = me;
+ }
+
+ mutex->depth++;
+ }
+ return 0;
}
static inline int
__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
{
- return __gthread_mutex_trylock (mutex);
+ if (__gthread_active_p ())
+ {
+ thread_t me = thr_self ();
+
+ if (mutex->owner != me)
+ {
+ if (mutex_trylock (&mutex->actual))
+ return 1;
+ mutex->owner = me;
+ }
+
+ mutex->depth++;
+ }
+ return 0;
}
static inline int
__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
{
- return __gthread_mutex_unlock (mutex);
+ if (__gthread_active_p ())
+ {
+ if (--mutex->depth == 0)
+ {
+ mutex->owner = (thread_t) 0;
+ mutex_unlock (&mutex->actual);
+ }
+ }
+ return 0;
}
#endif /* _LIBOBJC */