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>
15 #if defined(AFS_NT40_ENV) && defined(AFS_PTHREAD_ENV)
16 #define AFS_GRMUTEX_DECLSPEC __declspec(dllexport)
18 #ifdef AFS_PTHREAD_ENV
19 #include <afs/pthread_glock.h>
22 * Implement a pthread based recursive global lock for use in porting
23 * old lwp style code to pthreads.
26 pthread_recursive_mutex_t grmutex;
28 static int glock_init = 0;
29 static pthread_once_t glock_init_once = PTHREAD_ONCE_INIT;
34 pthread_mutex_init(&grmutex.mut, (const pthread_mutexattr_t *)0);
35 grmutex.times_inside = 0;
36 grmutex.owner = (pthread_t) 0;
42 pthread_recursive_mutex_lock(pthread_recursive_mutex_t * mut)
47 pthread_once(&glock_init_once, glock_init_func);
50 if (pthread_equal(mut->owner, pthread_self())) {
55 rc = pthread_mutex_lock(&mut->mut);
57 mut->times_inside = 1;
58 mut->owner = pthread_self();
66 pthread_recursive_mutex_unlock(pthread_recursive_mutex_t * mut)
71 pthread_once(&glock_init_once, glock_init_func);
73 if ((mut->locked) && (pthread_equal(mut->owner, pthread_self()))) {
75 if (mut->times_inside == 0) {
77 rc = pthread_mutex_unlock(&mut->mut);
81 * Note that you might want to try to differentiate between
82 * the two possible reasons you're here, but since we don't
83 * hold the mutex, it's useless to try.