backport to buster
[hcoop/debian/openafs.git] / src / util / pthread_glock.h
CommitLineData
805e021f
CE
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#if defined(AFS_PTHREAD_ENV) && !defined(KERNEL)
14#include <pthread.h>
15#include <afs/opr.h>
16
17typedef 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
32AFS_GRMUTEX_DECLSPEC pthread_recursive_mutex_t grmutex;
33
34extern int pthread_recursive_mutex_lock(pthread_recursive_mutex_p);
35extern 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 /* AFS_PTHREAD_ENV && !KERNEL */
44
45#define LOCK_GLOBAL_MUTEX
46#define UNLOCK_GLOBAL_MUTEX
47
48#endif /* AFS_PTHREAD_ENV && !KERNEL */
49
50#endif /* _AFS_PTHREAD_GLOCK_H_ */