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>
14 #if defined(AFS_NT40_ENV) && defined(AFS_PTHREAD_ENV)
15 #define AFS_GRMUTEX_DECLSPEC __declspec(dllexport)
17 #include <afs/pthread_glock.h>
21 * Implement a pthread based recursive global lock for use in porting
22 * old lwp style code to pthreads.
25 pthread_recursive_mutex_t grmutex;
27 static int glock_init = 0;
28 static pthread_once_t glock_init_once = PTHREAD_ONCE_INIT;
33 pthread_mutex_init(&grmutex.mut, (const pthread_mutexattr_t *)0);
34 grmutex.times_inside = 0;
35 grmutex.owner = (pthread_t) 0;
41 pthread_recursive_mutex_lock(pthread_recursive_mutex_t * mut)
45 (glock_init || pthread_once(&glock_init_once, glock_init_func));
48 if (pthread_equal(mut->owner, pthread_self())) {
53 rc = pthread_mutex_lock(&mut->mut);
55 mut->times_inside = 1;
56 mut->owner = pthread_self();
64 pthread_recursive_mutex_unlock(pthread_recursive_mutex_t * mut)
68 (glock_init || pthread_once(&glock_init_once, glock_init_func));
70 if ((mut->locked) && (pthread_equal(mut->owner, pthread_self()))) {
72 if (mut->times_inside == 0) {
74 rc = pthread_mutex_unlock(&mut->mut);
78 * Note that you might want to try to differentiate between
79 * the two possible reasons you're here, but since we don't
80 * hold the mutex, it's useless to try.