linux-warning-reduction-20090318
[openafs.git] / src / rx / LINUX / 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 /* AFS_GLOBAL_RXLOCK_KERNEL is defined so that the busy tq code paths are
22  * used. The thread can sleep when sending packets.
23  */
24 #define AFS_GLOBAL_RXLOCK_KERNEL 1
25
26
27 #define RX_ENABLE_LOCKS 1
28
29 #ifndef _LINUX_CODA_FS_I
30 #define _LINUX_CODA_FS_I
31 struct coda_inode_info {
32 };
33 #endif
34 #include <linux/version.h>
35 #include <linux/wait.h>
36 #include <linux/sched.h>
37 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
38 #include <linux/mutex.h>
39 #else
40 #include <asm/semaphore.h>
41 #endif
42
43 typedef struct afs_kmutex {
44 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
45     struct mutex mutex;
46 #else
47     struct semaphore sem;
48 #endif
49     int owner;
50 } afs_kmutex_t;
51
52 #ifndef set_current_state
53 #define set_current_state(X) current->state=X
54 #endif
55
56 typedef struct afs_kcondvar {
57     int seq;
58 #if defined(AFS_LINUX24_ENV)
59     wait_queue_head_t waitq;
60 #else
61     struct wait_queue *waitq;
62 #endif
63 } afs_kcondvar_t;
64
65 static inline int
66 MUTEX_ISMINE(afs_kmutex_t * l)
67 {
68     return l->owner == current->pid;
69 }
70
71 #define MUTEX_INIT(a,b,c,d)     afs_mutex_init(a)
72 #define MUTEX_DESTROY(a)
73 #define MUTEX_ENTER             afs_mutex_enter
74 #define MUTEX_TRYENTER          afs_mutex_tryenter
75 #define MUTEX_EXIT              afs_mutex_exit
76
77 #if defined(AFS_LINUX24_ENV)
78 #define CV_INIT(cv,b,c,d)       do { (cv)->seq = 0; init_waitqueue_head(&(cv)->waitq); } while (0)
79 #else
80 #define CV_INIT(cv,b,c,d)       do { (cv)->seq = 0; init_waitqueue(&(cv)->waitq); } while (0)
81 #endif
82 #define CV_DESTROY(cv)
83 #define CV_WAIT_SIG(cv, m)      afs_cv_wait(cv, m, 1)
84 #define CV_WAIT(cv, m)          afs_cv_wait(cv, m, 0)
85 #define CV_TIMEDWAIT            afs_cv_timedwait
86
87 #define CV_SIGNAL(cv)          do { ++(cv)->seq; wake_up(&(cv)->waitq); } while (0)
88 #if defined(AFS_LINUX24_ENV)
89 #define CV_BROADCAST(cv)       do { ++(cv)->seq; wake_up_all(&(cv)->waitq); } while (0)
90 #else
91 #define CV_BROADCAST(cv)       do { ++(cv)->seq; wake_up(&(cv)->waitq); } while (0)
92 #endif
93
94 #endif /* RX_KMUTEX_H_ */