2 * Copyright (C) 1998 Transarc Corporation. All rights reserved.
7 #if defined(AFS_NT40_ENV) && defined(AFS_PTHREAD_ENV)
8 #define AFS_GRMUTEX_DECLSPEC __declspec(dllexport)
10 #include <afs/pthread_glock.h>
14 * Implement a pthread based recursive global lock for use in porting
15 * old lwp style code to pthreads.
18 pthread_recursive_mutex_t grmutex;
20 static int glock_init;
21 static pthread_once_t glock_init_once = PTHREAD_ONCE_INIT;
23 static void glock_init_func(void) {
24 pthread_mutex_init(&grmutex.mut, (const pthread_mutexattr_t *) 0);
25 grmutex.times_inside = 0;
26 grmutex.owner = (pthread_t) 0;
31 int pthread_recursive_mutex_lock(pthread_recursive_mutex_t *mut) {
34 (glock_init || pthread_once(&glock_init_once, glock_init_func));
37 if (pthread_equal(mut->owner,pthread_self())) {
42 rc = pthread_mutex_lock(&mut->mut);
44 mut->times_inside = 1;
45 mut->owner = pthread_self();
52 int pthread_recursive_mutex_unlock(pthread_recursive_mutex_t *mut) {
55 (glock_init || pthread_once(&glock_init_once, glock_init_func));
57 if ((mut->locked) && (pthread_equal(mut->owner,pthread_self()))) {
59 if (mut->times_inside == 0) {
61 rc = pthread_mutex_unlock(&mut->mut);
65 * Note that you might want to try to differentiate between
66 * the two possible reasons you're here, but since we don't
67 * hold the mutex, it's useless to try.