1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light Super operations
6 * Copyright (c) 2004 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or modify it under
11 * the terms of version 2 of the GNU General Public License as published by
12 * the Free Software Foundation. Lustre is distributed in the hope that it
13 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
14 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. You should have received a
16 * copy of the GNU General Public License along with Lustre; if not, write
17 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
24 * Created by nikita on Sun Jul 18 2004.
26 * Prototypes of XNU synchronization primitives.
29 #ifndef __LIBCFS_DARWIN_XNU_SYNC_H__
30 #define __LIBCFS_DARWIN_XNU_SYNC_H__
32 #ifndef __LIBCFS_LIBCFS_H__
33 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
36 #define XNU_SYNC_DEBUG (0)
39 #define ON_SYNC_DEBUG(e) e
41 #define ON_SYNC_DEBUG(e)
45 /* "egrep -i '^(o?x)?[abcdeflo]*$' /usr/dict/words" is your friend */
46 KMUT_MAGIC = 0x0bac0cab, /* [a, [b, c]] = b (a, c) - c (a, b) */
47 KSEM_MAGIC = 0x1abe11ed,
48 KCOND_MAGIC = 0xb01dface,
49 KRW_MAGIC = 0xdabb1edd,
50 KSPIN_MAGIC = 0xca11ab1e,
51 KSLEEP_CHAN_MAGIC = 0x0debac1e,
52 KSLEEP_LINK_MAGIC = 0xacc01ade,
53 KTIMER_MAGIC = 0xbefadd1e
56 /* ------------------------- spin lock ------------------------- */
59 * XXX nikita: don't use NCPUS it's hardcoded to (1) in cpus.h
63 #include <kern/simple_lock.h>
65 #include <libcfs/list.h>
78 * XXX nikita: we cannot use simple_* functions, because bsd/sys/lock.h
79 * redefines them to nothing. Use low-level hw_lock_* instead.
82 void kspin_init(struct kspin *spin);
83 void kspin_done(struct kspin *spin);
84 void kspin_lock(struct kspin *spin);
85 void kspin_unlock(struct kspin *spin);
86 int kspin_trylock(struct kspin *spin);
90 * two functions below are for use in assertions
92 /* true, iff spin-lock is locked by the current thread */
93 int kspin_islocked(struct kspin *spin);
94 /* true, iff spin-lock is not locked by the current thread */
95 int kspin_isnotlocked(struct kspin *spin);
97 #define kspin_islocked(s) (1)
98 #define kspin_isnotlocked(s) (1)
101 /* ------------------------- semaphore ------------------------- */
112 void ksem_init(struct ksem *sem, int value);
113 void ksem_done(struct ksem *sem);
114 int ksem_up (struct ksem *sem, int value);
115 void ksem_down(struct ksem *sem, int value);
116 int ksem_trydown(struct ksem *sem, int value);
118 /* ------------------------- mutex ------------------------- */
128 void kmut_init(struct kmut *mut);
129 void kmut_done(struct kmut *mut);
131 void kmut_lock (struct kmut *mut);
132 void kmut_unlock (struct kmut *mut);
133 int kmut_trylock(struct kmut *mut);
137 * two functions below are for use in assertions
139 /* true, iff mutex is locked by the current thread */
140 int kmut_islocked(struct kmut *mut);
141 /* true, iff mutex is not locked by the current thread */
142 int kmut_isnotlocked(struct kmut *mut);
144 #define kmut_islocked(m) (1)
145 #define kmut_isnotlocked(m) (1)
148 /* ------------------------- condition variable ------------------------- */
151 struct kcond_link *next;
157 struct kcond_link *waiters;
163 void kcond_init(struct kcond *cond);
164 void kcond_done(struct kcond *cond);
165 void kcond_wait(struct kcond *cond, struct kspin *lock);
166 void kcond_signal(struct kcond *cond);
167 void kcond_broadcast(struct kcond *cond);
169 void kcond_wait_guard(struct kcond *cond);
170 void kcond_signal_guard(struct kcond *cond);
171 void kcond_broadcast_guard(struct kcond *cond);
173 /* ------------------------- read-write semaphore ------------------------- */
183 void krw_sem_init(struct krw_sem *sem);
184 void krw_sem_done(struct krw_sem *sem);
185 void krw_sem_down_r(struct krw_sem *sem);
186 int krw_sem_down_r_try(struct krw_sem *sem);
187 void krw_sem_down_w(struct krw_sem *sem);
188 int krw_sem_down_w_try(struct krw_sem *sem);
189 void krw_sem_up_r(struct krw_sem *sem);
190 void krw_sem_up_w(struct krw_sem *sem);
192 /* ------------------------- sleep-channel ------------------------- */
196 struct list_head waiters;
202 #define KSLEEP_CHAN_INITIALIZER {{{0}}}
208 struct ksleep_chan *forward;
209 struct list_head linkage;
219 void ksleep_chan_init(struct ksleep_chan *chan);
220 void ksleep_chan_done(struct ksleep_chan *chan);
222 void ksleep_link_init(struct ksleep_link *link);
223 void ksleep_link_done(struct ksleep_link *link);
225 void ksleep_add(struct ksleep_chan *chan, struct ksleep_link *link);
226 void ksleep_del(struct ksleep_chan *chan, struct ksleep_link *link);
228 void ksleep_wait(struct ksleep_chan *chan);
229 int64_t ksleep_timedwait(struct ksleep_chan *chan, uint64_t timeout);
231 void ksleep_wake(struct ksleep_chan *chan);
232 void ksleep_wake_all(struct ksleep_chan *chan);
233 void ksleep_wake_nr(struct ksleep_chan *chan, int nr);
235 #define KSLEEP_LINK_DECLARE(name) \
240 .linkage = PTL_LIST_HEAD_INIT(name.linkage), \
241 .magic = KSLEEP_LINK_MAGIC \
244 /* ------------------------- timer ------------------------- */
248 void (*func)(void *);
250 u_int64_t deadline; /* timer deadline in absolute nanoseconds */
257 void ktimer_init(struct ktimer *t, void (*func)(void *), void *arg);
258 void ktimer_done(struct ktimer *t);
259 void ktimer_arm(struct ktimer *t, u_int64_t deadline);
260 void ktimer_disarm(struct ktimer *t);
261 int ktimer_is_armed(struct ktimer *t);
263 u_int64_t ktimer_deadline(struct ktimer *t);
270 * c-indentation-style: "K&R"