1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2004 Cluster File Systems, Inc.
5 * Author: Nikita Danilov <nikita@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
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.
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
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.
22 * Implementation of portable time API for user-level.
26 #ifndef __LIBCFS_USER_LOCK_H__
27 #define __LIBCFS_USER_LOCK_H__
29 #ifndef __LIBCFS_LIBCFS_H__
30 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
33 /* Implementations of portable synchronization APIs for liblustre */
36 * liblustre is single-threaded, so most "synchronization" APIs are trivial.
42 * Optional debugging (magic stamping and checking ownership) can be added.
53 * - spin_lock_irqsave(x, f)
54 * - spin_unlock_irqrestore(x, f)
56 * No-op implementation.
60 typedef struct spin_lock spinlock_t;
62 void spin_lock_init(spinlock_t *lock);
63 void spin_lock(spinlock_t *lock);
64 void spin_unlock(spinlock_t *lock);
65 int spin_trylock(spinlock_t *lock);
66 void spin_lock_bh_init(spinlock_t *lock);
67 void spin_lock_bh(spinlock_t *lock);
68 void spin_unlock_bh(spinlock_t *lock);
70 #define spin_lock_irqsave(l, flags) ({ spin_lock(l); (void)flags; })
71 #define spin_unlock_irqrestore(l, flags) ({ spin_unlock(l); (void)flags; })
82 void sema_init(struct semaphore *s, int val);
83 void __down(struct semaphore *s);
84 void __up(struct semaphore *s);
90 * - init_mutex_locked(x)
94 #define mutex_up(s) __up(s)
95 #define mutex_down(s) __down(s)
97 #define init_mutex(x) sema_init(x, 1)
98 #define init_mutex_locked(x) sema_init(x, 0)
103 * - init_completion(c)
105 * - wait_for_completion(c)
107 struct completion {};
109 void init_completion(struct completion *c);
110 void complete(struct completion *c);
111 void wait_for_completion(struct completion *c);
122 struct rw_semaphore {};
124 void init_rwsem(struct rw_semaphore *s);
125 void down_read(struct rw_semaphore *s);
126 int down_read_trylock(struct rw_semaphore *s);
127 void down_write(struct rw_semaphore *s);
128 int down_write_trylock(struct rw_semaphore *s);
129 void up_read(struct rw_semaphore *s);
130 void up_write(struct rw_semaphore *s);
133 * read-write lock : Need to be investigated more!!
134 * XXX nikita: for now, let rwlock_t to be identical to rw_semaphore
136 * - DECLARE_RWLOCK(l)
143 typedef struct rw_semaphore rwlock_t;
145 #define rwlock_init(pl) init_rwsem(pl)
147 #define read_lock(l) down_read(l)
148 #define read_unlock(l) up_read(l)
149 #define write_lock(l) down_write(l)
150 #define write_unlock(l) up_write(l)
152 #define write_lock_irqsave(l, f) write_lock(l)
153 #define write_unlock_irqrestore(l, f) write_unlock(l)
155 #define read_lock_irqsave(l, f) read_lock(l)
156 #define read_unlock_irqrestore(l, f) read_unlock(l)
161 /* __LIBCFS_USER_LOCK_H__ */
165 * c-indentation-style: "K&R"