rx: Get rid of AFS_GLOBAL_RXLOCK_KERNEL
[openafs.git] / src / rx / LINUX24 / rx_kmutex.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 /*
11  * rx_kmutex.h - mutex and condition variable macros for kernel environment.
12  *
13  * Linux implementation.
14  * This are noops until such time as the kernel no longer has a global lock.
15  */
16 #ifndef RX_KMUTEX_H_
17 #define RX_KMUTEX_H_
18
19 #include "rx/rx_kernel.h"       /* for osi_Panic() */
20
21 #define RX_ENABLE_LOCKS 1
22
23 #ifndef _LINUX_CODA_FS_I
24 #define _LINUX_CODA_FS_I
25 struct coda_inode_info {
26 };
27 #endif
28 #include <linux/version.h>
29 #include <linux/wait.h>
30 #include <linux/sched.h>
31 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
32 #include <linux/mutex.h>
33 #else
34 #include <asm/semaphore.h>
35 #endif
36
37 typedef struct afs_kmutex {
38 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
39     struct mutex mutex;
40 #else
41     struct semaphore sem;
42 #endif
43     int owner;
44 } afs_kmutex_t;
45
46 #ifndef set_current_state
47 #define set_current_state(X) current->state=X
48 #endif
49
50 typedef struct afs_kcondvar {
51     int seq;
52 #if defined(AFS_LINUX24_ENV)
53     wait_queue_head_t waitq;
54 #else
55     struct wait_queue *waitq;
56 #endif
57 } afs_kcondvar_t;
58
59 static inline int
60 MUTEX_ISMINE(afs_kmutex_t * l)
61 {
62     return l->owner == current->pid;
63 }
64
65 #define MUTEX_INIT(a,b,c,d)     afs_mutex_init(a)
66 #define MUTEX_DESTROY(a)
67 #define MUTEX_ENTER             afs_mutex_enter
68 #define MUTEX_TRYENTER          afs_mutex_tryenter
69 #define MUTEX_EXIT              afs_mutex_exit
70
71 #if defined(AFS_LINUX24_ENV)
72 #define CV_INIT(cv,b,c,d)       do { (cv)->seq = 0; init_waitqueue_head(&(cv)->waitq); } while (0)
73 #else
74 #define CV_INIT(cv,b,c,d)       do { (cv)->seq = 0; init_waitqueue(&(cv)->waitq); } while (0)
75 #endif
76 #define CV_DESTROY(cv)
77 #define CV_WAIT_SIG(cv, m)      afs_cv_wait(cv, m, 1)
78 #define CV_WAIT(cv, m)          afs_cv_wait(cv, m, 0)
79 #define CV_TIMEDWAIT            afs_cv_timedwait
80
81 #define CV_SIGNAL(cv)          do { ++(cv)->seq; wake_up(&(cv)->waitq); } while (0)
82 #if defined(AFS_LINUX24_ENV)
83 #define CV_BROADCAST(cv)       do { ++(cv)->seq; wake_up_all(&(cv)->waitq); } while (0)
84 #else
85 #define CV_BROADCAST(cv)       do { ++(cv)->seq; wake_up(&(cv)->waitq); } while (0)
86 #endif
87
88 #endif /* RX_KMUTEX_H_ */