+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, 0);
+}
+
+static inline int
+__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *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)
+{
+ 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)
+{
+ if (__gthread_active_p ())
+ {
+ if (--mutex->depth == 0)
+ {
+ mutex->owner = (thread_t) 0;
+ mutex_unlock (&mutex->actual);
+ }
+ }
+ return 0;
+}
+