e323e3f4b4a1cc19a4e56f597e2a2ee641f2bb53
[openafs.git] / src / util / pthread_glock.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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
8  */
9
10 #ifndef _AFS_PTHREAD_GLOCK_H_
11 #define _AFS_PTHREAD_GLOCK_H_
12
13 #ifdef AFS_PTHREAD_ENV
14 #include <pthread.h>
15 #include <afs/opr.h>
16
17 typedef struct {
18     pthread_mutex_t mut;
19     volatile pthread_t owner;
20     volatile unsigned int locked;
21     volatile unsigned int times_inside;
22 } pthread_recursive_mutex_t, *pthread_recursive_mutex_p;
23
24 #if defined(AFS_NT40_ENV) && defined(AFS_PTHREAD_ENV)
25 #ifndef AFS_GRMUTEX_DECLSPEC
26 #define AFS_GRMUTEX_DECLSPEC __declspec(dllimport) extern
27 #endif
28 #else
29 #define AFS_GRMUTEX_DECLSPEC extern
30 #endif
31
32 AFS_GRMUTEX_DECLSPEC pthread_recursive_mutex_t grmutex;
33
34 extern int pthread_recursive_mutex_lock(pthread_recursive_mutex_p);
35 extern int pthread_recursive_mutex_unlock(pthread_recursive_mutex_p);
36
37 #define LOCK_GLOBAL_MUTEX \
38     opr_Verify(pthread_recursive_mutex_lock(&grmutex)==0)
39
40 #define UNLOCK_GLOBAL_MUTEX \
41     opr_Verify(pthread_recursive_mutex_unlock(&grmutex)==0)
42
43 #else
44
45 #define LOCK_GLOBAL_MUTEX
46 #define UNLOCK_GLOBAL_MUTEX
47
48 #endif /* AFS_PTHREAD_ENV */
49
50 #endif /* _AFS_PTHREAD_GLOCK_H_ */