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
11 * rx_kmutex.h - mutex and condition variable macros for kernel environment.
13 * Linux implementation.
14 * This are noops until such time as the kernel no longer has a global lock.
19 #include "../rx/rx_kernel.h" /* for osi_Panic() */
21 /* AFS_GLOBAL_RXLOCK_KERNEL is defined so that the busy tq code paths are
22 * used. The thread can sleep when sending packets.
24 #define AFS_GLOBAL_RXLOCK_KERNEL 1
28 #define RX_ENABLE_LOCKS 1
30 #ifndef _LINUX_CODA_FS_I
31 #define _LINUX_CODA_FS_I
32 struct coda_inode_info {};
34 #include "linux/wait.h"
35 #include "linux/sched.h"
37 typedef struct afs_kmutex {
42 #if defined(AFS_LINUX24_ENV)
43 typedef wait_queue_head_t afs_kcondvar_t;
45 typedef struct wait_queue *afs_kcondvar_t;
48 static inline int MUTEX_ISMINE(afs_kmutex_t *l)
50 return l->owner == current->pid;
54 static inline void afs_mutex_init(afs_kmutex_t *l)
56 #if defined(AFS_LINUX24_ENV)
63 #define MUTEX_INIT(a,b,c,d) afs_mutex_init(a)
65 #define MUTEX_DESTROY(a)
67 static inline void MUTEX_ENTER(afs_kmutex_t *l)
71 osi_Panic("mutex_enter: 0x%x held by %d", l, l->owner);
72 l->owner = current->pid;
75 /* And how to do a good tryenter? */
76 static inline int MUTEX_TRYENTER(afs_kmutex_t *l)
86 static inline void MUTEX_EXIT(afs_kmutex_t *l)
88 if (l->owner != current->pid)
89 osi_Panic("mutex_exit: 0x%x held by %d",
95 #if defined(AFS_LINUX24_ENV)
96 #define CV_INIT(cv,b,c,d) init_waitqueue_head((wait_queue_head_t *)(cv))
98 #define CV_INIT(cv,b,c,d) init_waitqueue((struct wait_queue**)(cv))
100 #define CV_DESTROY(cv)
102 /* CV_WAIT and CV_TIMEDWAIT rely on the fact that the Linux kernel has
103 * a global lock. Thus we can safely drop our locks before calling the
104 * kernel sleep services.
106 static inline CV_WAIT(afs_kcondvar_t *cv, afs_kmutex_t *l)
108 int isAFSGlocked = ISAFS_GLOCK();
110 if (isAFSGlocked) AFS_GUNLOCK();
113 #if defined(AFS_LINUX24_ENV)
114 interruptible_sleep_on((wait_queue_head_t *)cv);
116 interruptible_sleep_on((struct wait_queue**)cv);
120 if (isAFSGlocked) AFS_GLOCK();
125 static inline CV_TIMEDWAIT(afs_kcondvar_t *cv, afs_kmutex_t *l, int waittime)
127 int isAFSGlocked = ISAFS_GLOCK();
128 long t = waittime * HZ / 1000;
130 if (isAFSGlocked) AFS_GUNLOCK();
133 #if defined(AFS_LINUX24_ENV)
134 t = interruptible_sleep_on_timeout((wait_queue_head_t *)cv, t);
136 t = interruptible_sleep_on_timeout((struct wait_queue**)cv, t);
140 if (isAFSGlocked) AFS_GLOCK();
145 #if defined(AFS_LINUX24_ENV)
146 #define CV_SIGNAL(cv) wake_up((wait_queue_head_t *)cv)
147 #define CV_BROADCAST(cv) wake_up((wait_queue_head_t *)cv)
149 #define CV_SIGNAL(cv) wake_up((struct wait_queue**)cv)
150 #define CV_BROADCAST(cv) wake_up((struct wait_queue**)cv)
155 #define MUTEX_ISMINE(a)
156 #define osirx_AssertMine(addr, msg)
158 #define MUTEX_DESTROY(a)
159 #define MUTEX_ENTER(a)
160 #define MUTEX_TRYENTER(a) 1
161 #define MUTEX_EXIT(a)
162 #define MUTEX_INIT(a,b,c,d)
163 #define CV_INIT(a,b,c,d)
164 #define CV_DESTROY(a)
167 /* Since we're using the RX listener daemon, we don't need to hold off
174 #endif /* RX_KMUTEX_H_ */