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 <afs/param.h>
11 #if defined(AFS_NT40_ENV) && defined(AFS_PTHREAD_ENV)
12 #define AFS_GRMUTEX_DECLSPEC __declspec(dllexport)
14 #include <afs/pthread_glock.h>
18 * Implement a pthread based recursive global lock for use in porting
19 * old lwp style code to pthreads.
22 pthread_recursive_mutex_t grmutex;
24 static int glock_init;
25 static pthread_once_t glock_init_once = PTHREAD_ONCE_INIT;
27 static void glock_init_func(void) {
28 pthread_mutex_init(&grmutex.mut, (const pthread_mutexattr_t *) 0);
29 grmutex.times_inside = 0;
30 grmutex.owner = (pthread_t) 0;
35 int pthread_recursive_mutex_lock(pthread_recursive_mutex_t *mut) {
38 (glock_init || pthread_once(&glock_init_once, glock_init_func));
41 if (pthread_equal(mut->owner,pthread_self())) {
46 rc = pthread_mutex_lock(&mut->mut);
48 mut->times_inside = 1;
49 mut->owner = pthread_self();
56 int pthread_recursive_mutex_unlock(pthread_recursive_mutex_t *mut) {
59 (glock_init || pthread_once(&glock_init_once, glock_init_func));
61 if ((mut->locked) && (pthread_equal(mut->owner,pthread_self()))) {
63 if (mut->times_inside == 0) {
65 rc = pthread_mutex_unlock(&mut->mut);
69 * Note that you might want to try to differentiate between
70 * the two possible reasons you're here, but since we don't
71 * hold the mutex, it's useless to try.