2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #if defined(AFS_NT40_ENV) && defined(AFS_PTHREAD_ENV)
17 #define AFS_GRMUTEX_DECLSPEC __declspec(dllexport)
19 #include <afs/pthread_glock.h>
23 * Implement a pthread based recursive global lock for use in porting
24 * old lwp style code to pthreads.
27 pthread_recursive_mutex_t grmutex;
29 static int glock_init = 0;
30 static pthread_once_t glock_init_once = PTHREAD_ONCE_INIT;
35 pthread_mutex_init(&grmutex.mut, (const pthread_mutexattr_t *)0);
36 grmutex.times_inside = 0;
37 grmutex.owner = (pthread_t) 0;
43 pthread_recursive_mutex_lock(pthread_recursive_mutex_t * mut)
48 * FSLog("Entered pthread_recursive_mutex_lock, thread id is %d\n",
52 (glock_init || pthread_once(&glock_init_once, glock_init_func));
55 if (pthread_equal(mut->owner, pthread_self())) {
60 rc = pthread_mutex_lock(&mut->mut);
62 mut->times_inside = 1;
63 mut->owner = pthread_self();
71 pthread_recursive_mutex_unlock(pthread_recursive_mutex_t * mut)
76 * FSLog("Entered pthread_recursive_mutex_unlock, thread id is %d\n",
81 (glock_init || pthread_once(&glock_init_once, glock_init_func));
83 if ((mut->locked) && (pthread_equal(mut->owner, pthread_self()))) {
85 if (mut->times_inside == 0) {
87 rc = pthread_mutex_unlock(&mut->mut);
91 * Note that you might want to try to differentiate between
92 * the two possible reasons you're here, but since we don't
93 * hold the mutex, it's useless to try.