Whamcloud - gitweb
Landing b_hd_newconfig on HEAD
[fs/lustre-release.git] / lnet / libcfs / user-lock.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2004 Cluster File Systems, Inc.
5  * Author: Nikita Danilov <nikita@clusterfs.com>
6  *
7  * This file is part of Lustre, http://www.lustre.org.
8  *
9  * Lustre is free software; you can redistribute it and/or modify it under the
10  * terms of version 2 of the GNU General Public License as published by the
11  * Free Software Foundation.
12  *
13  * Lustre is distributed in the hope that it will be useful, but WITHOUT ANY
14  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with Lustre; if not, write to the Free Software Foundation, Inc., 675 Mass
20  * Ave, Cambridge, MA 02139, USA.
21  *
22  * Implementation of portable time API for user-level.
23  *
24  */
25
26 /* Implementations of portable synchronization APIs for liblustre */
27
28 /*
29  * liblustre is single-threaded, so most "synchronization" APIs are trivial.
30  *
31  * XXX Liang: There are several branches share lnet with b_hd_newconfig,
32  * if we define lock APIs at here, there will be conflict with liblustre
33  * in other branches.
34  */
35
36 #ifndef __KERNEL__
37
38 #include <stdlib.h>
39 #include <libcfs/libcfs.h>
40 /*
41  * Optional debugging (magic stamping and checking ownership) can be added.
42  */
43
44 #if 0
45 /*
46  * spin_lock
47  *
48  * - spin_lock_init(x)
49  * - spin_lock(x)
50  * - spin_unlock(x)
51  * - spin_trylock(x)
52  *
53  * - spin_lock_irqsave(x, f)
54  * - spin_unlock_irqrestore(x, f)
55  *
56  * No-op implementation.
57  */
58
59 void spin_lock_init(spinlock_t *lock)
60 {
61         LASSERT(lock != NULL);
62         (void)lock;
63 }
64
65 void spin_lock(spinlock_t *lock)
66 {
67         (void)lock;
68 }
69
70 void spin_unlock(spinlock_t *lock)
71 {
72         (void)lock;
73 }
74
75 int spin_trylock(spinlock_t *lock)
76 {
77         (void)lock;
78         return 1;
79 }
80
81 void spin_lock_bh_init(spinlock_t *lock)
82 {
83         LASSERT(lock != NULL);
84         (void)lock;
85 }
86
87 void spin_lock_bh(spinlock_t *lock)
88 {
89         LASSERT(lock != NULL);
90         (void)lock;
91 }
92
93 void spin_unlock_bh(spinlock_t *lock)
94 {
95         LASSERT(lock != NULL);
96         (void)lock;
97 }
98
99 /*
100  * Semaphore
101  *
102  * - sema_init(x, v)
103  * - __down(x)
104  * - __up(x)
105  */
106 struct semaphore {};
107
108 void sema_init(struct semaphore *s, int val)
109 {
110         LASSERT(s != NULL);
111         (void)s;
112         (void)val;
113 }
114
115 void __down(struct semaphore *s)
116 {
117         LASSERT(s != NULL);
118         (void)s;
119 }
120
121 void __up(struct semaphore *s)
122 {
123         LASSERT(s != NULL);
124         (void)s;
125 }
126
127 /*
128  * Mutex:
129  *
130  * - init_mutex(x)
131  * - init_mutex_locked(x)
132  * - mutex_up(x)
133  * - mutex_down(x)
134  */
135
136 #define mutex_up(s)                     __up(s)
137 #define mutex_down(s)                   __down(s)
138
139 #define init_mutex(x)                   sema_init(x, 1)
140 #define init_mutex_locked(x)            sema_init(x, 0)
141
142 /*
143  * Completion:
144  *
145  * - init_completion(c)
146  * - complete(c)
147  * - wait_for_completion(c)
148  */
149 struct completion {};
150
151 void init_completion(struct completion *c)
152 {
153         LASSERT(c != NULL);
154         (void)c;
155 }
156
157 void complete(struct completion *c)
158 {
159         LASSERT(c != NULL);
160         (void)c;
161 }
162
163 void wait_for_completion(struct completion *c)
164 {
165         LASSERT(c != NULL);
166         (void)c;
167 }
168
169 /*
170  * rw_semaphore:
171  *
172  * - DECLARE_RWSEM(x)
173  * - init_rwsem(x)
174  * - down_read(x)
175  * - up_read(x)
176  * - down_write(x)
177  * - up_write(x)
178  */
179 struct rw_semaphore {};
180
181 void init_rwsem(struct rw_semaphore *s)
182 {
183         LASSERT(s != NULL);
184         (void)s;
185 }
186
187 void down_read(struct rw_semaphore *s)
188 {
189         LASSERT(s != NULL);
190         (void)s;
191 }
192
193 int down_read_trylock(struct rw_semaphore *s)
194 {
195         LASSERT(s != NULL);
196         (void)s;
197         return 1;
198 }
199
200 void down_write(struct rw_semaphore *s)
201 {
202         LASSERT(s != NULL);
203         (void)s;
204 }
205
206 int down_write_trylock(struct rw_semaphore *s)
207 {
208         LASSERT(s != NULL);
209         (void)s;
210         return 1;
211 }
212
213 void up_read(struct rw_semaphore *s)
214 {
215         LASSERT(s != NULL);
216         (void)s;
217 }
218
219 void up_write(struct rw_semaphore *s)
220 {
221         LASSERT(s != NULL);
222         (void)s;
223 }
224 #endif
225
226 /* !__KERNEL__ */
227 #endif
228
229 /*
230  * Local variables:
231  * c-indentation-style: "K&R"
232  * c-basic-offset: 8
233  * tab-width: 8
234  * fill-column: 80
235  * scroll-step: 1
236  * End:
237  */