/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=8:tabstop=8:
*
- * Copyright (C) 2004 Cluster File Systems, Inc.
- * Author: Nikita Danilov <nikita@clusterfs.com>
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
*
- * This file is part of Lustre, http://www.lustre.org.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
*
- * Lustre is free software; you can redistribute it and/or modify it under the
- * terms of version 2 of the GNU General Public License as published by the
- * Free Software Foundation.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
*
- * Lustre is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
*
- * You should have received a copy of the GNU General Public License along
- * with Lustre; if not, write to the Free Software Foundation, Inc., 675 Mass
- * Ave, Cambridge, MA 02139, USA.
+ * GPL HEADER END
+ */
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
*
- * Implementation of portable time API for user-level.
+ * libcfs/include/libcfs/user-lock.h
*
+ * Author: Nikita Danilov <nikita@clusterfs.com>
*/
#ifndef __LIBCFS_USER_LOCK_H__
*/
#ifndef __KERNEL__
-#include <stdio.h>
-#include <stdlib.h>
-#if 0
+/*
+ * The userspace implementations of linux/spinlock.h vary; we just
+ * include our own for all of them
+ */
+#define __LINUX_SPINLOCK_H
+
/*
* Optional debugging (magic stamping and checking ownership) can be added.
*/
#define SPIN_LOCK_UNLOCKED (spinlock_t) { }
#define LASSERT_SPIN_LOCKED(lock) do {} while(0)
+#define LASSERT_SEM_LOCKED(sem) do {} while(0)
void spin_lock_init(spinlock_t *lock);
void spin_lock(spinlock_t *lock);
void spin_lock_bh_init(spinlock_t *lock);
void spin_lock_bh(spinlock_t *lock);
void spin_unlock_bh(spinlock_t *lock);
-static inline int spin_is_locked(spinlock_t *l) {return 1;}
+static inline int spin_is_locked(spinlock_t *l) {return 1;}
static inline void spin_lock_irqsave(spinlock_t *l, unsigned long f){}
static inline void spin_unlock_irqrestore(spinlock_t *l, unsigned long f){}
* - mutex_up(x)
* - mutex_down(x)
*/
-#define mutex_up(s) __up(s)
-#define mutex_down(s) __down(s)
+#define DECLARE_MUTEX(name) \
+ struct semaphore name = { 1 }
+
+#define mutex_up(s) __up(s)
+#define up(s) mutex_up(s)
+#define mutex_down(s) __down(s)
+#define down(s) mutex_down(s)
-#define init_mutex(x) sema_init(x, 1)
-#define init_mutex_locked(x) sema_init(x, 0)
+#define init_MUTEX(x) sema_init(x, 1)
+#define init_MUTEX_LOCKED(x) sema_init(x, 0)
+#define init_mutex(s) init_MUTEX(s)
/*
* Completion:
* - complete(c)
* - wait_for_completion(c)
*/
-#if 0
-struct completion {};
+struct completion {
+ unsigned int done;
+ cfs_waitq_t wait;
+};
void init_completion(struct completion *c);
void complete(struct completion *c);
void wait_for_completion(struct completion *c);
-#endif
+
+#define COMPLETION_INITIALIZER(work) \
+ { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
+
+#define DECLARE_COMPLETION(work) \
+ struct completion work = COMPLETION_INITIALIZER(work)
+
+#define INIT_COMPLETION(x) ((x).done = 0)
+
/*
* rw_semaphore:
* - down_write(x)
* - up_write(x)
*/
-struct rw_semaphore {};
+struct rw_semaphore {
+ int foo;
+};
void init_rwsem(struct rw_semaphore *s);
void down_read(struct rw_semaphore *s);
* - write_unlock(x)
*/
typedef struct rw_semaphore rwlock_t;
+#define RW_LOCK_UNLOCKED (rwlock_t) { }
-#define rwlock_init(pl) init_rwsem(pl)
+#define rwlock_init(pl) init_rwsem(pl)
-#define read_lock(l) down_read(l)
-#define read_unlock(l) up_read(l)
-#define write_lock(l) down_write(l)
-#define write_unlock(l) up_write(l)
+#define read_lock(l) down_read(l)
+#define read_unlock(l) up_read(l)
+#define write_lock(l) down_write(l)
+#define write_unlock(l) up_write(l)
static inline void
write_lock_irqsave(rwlock_t *l, unsigned long f) { write_lock(l); }
typedef struct { volatile int counter; } atomic_t;
#define ATOMIC_INIT(i) { (i) }
+
#define atomic_read(a) ((a)->counter)
#define atomic_set(a,b) do {(a)->counter = b; } while (0)
#define atomic_dec_and_test(a) ((--((a)->counter)) == 0)
+#define atomic_dec_and_lock(a,b) ((--((a)->counter)) == 0)
#define atomic_inc(a) (((a)->counter)++)
#define atomic_dec(a) do { (a)->counter--; } while (0)
#define atomic_add(b,a) do {(a)->counter += b;} while (0)
-#define atomic_add_return(n,a) ((a)->counter = n)
+#define atomic_add_return(n,a) ((a)->counter += n)
#define atomic_inc_return(a) atomic_add_return(1,a)
#define atomic_sub(b,a) do {(a)->counter -= b;} while (0)
+#define atomic_sub_return(n,a) ((a)->counter -= n)
+#define atomic_dec_return(a) atomic_sub_return(1,a)
-#endif
#ifdef HAVE_LIBPTHREAD
#include <pthread.h>