Whamcloud - gitweb
libcfs: page_private() is not always defined, use page->private.
[fs/lustre-release.git] / libcfs / libcfs / user-lock.c
index a5ef616..b01319f 100644 (file)
@@ -1,26 +1,41 @@
 /* -*- 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
  *
- * This file is part of Lustre, http://www.lustre.org.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- * 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.
+ * 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.
  *
- * 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.
+ * 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).
  *
- * 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.
+ * 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
  *
- * Implementation of portable time API for user-level.
+ * 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.
  *
+ * 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.
+ *
+ * libcfs/libcfs/user-lock.c
+ *
+ * Author: Nikita Danilov <nikita@clusterfs.com>
  */
 
 /* Implementations of portable synchronization APIs for liblustre */
 
 #ifndef __KERNEL__
 
-#include <stdlib.h>
 #include <libcfs/libcfs.h>
 
 /*
  * Optional debugging (magic stamping and checking ownership) can be added.
  */
 
-#if 0
 /*
  * spin_lock
  *
  * - spin_lock_init(x)
  * - spin_lock(x)
+ * - spin_lock_nested(x, subclass)
  * - spin_unlock(x)
  * - spin_trylock(x)
  *
@@ -68,6 +82,12 @@ void spin_lock(spinlock_t *lock)
         (void)lock;
 }
 
+void spin_lock_nested(spinlock_t *lock, unsigned int subclass)
+{
+        (void)lock;
+        (void)subclass;
+}
+
 void spin_unlock(spinlock_t *lock)
 {
         (void)lock;
@@ -104,7 +124,6 @@ void spin_unlock_bh(spinlock_t *lock)
  * - __down(x)
  * - __up(x)
  */
-struct semaphore {};
 
 void sema_init(struct semaphore *s, int val)
 {
@@ -125,20 +144,6 @@ void __up(struct semaphore *s)
         (void)s;
 }
 
-/*
- * Mutex:
- *
- * - init_mutex(x)
- * - init_mutex_locked(x)
- * - mutex_up(x)
- * - mutex_down(x)
- */
-
-#define mutex_up(s)                    __up(s)
-#define mutex_down(s)                  __down(s)
-
-#define init_mutex(x)                  sema_init(x, 1)
-#define init_mutex_locked(x)           sema_init(x, 0)
 
 /*
  * Completion:
@@ -147,24 +152,30 @@ void __up(struct semaphore *s)
  * - complete(c)
  * - wait_for_completion(c)
  */
-struct completion {};
 
 void init_completion(struct completion *c)
 {
         LASSERT(c != NULL);
-        (void)c;
+        c->done = 0;
+        cfs_waitq_init(&c->wait);
 }
 
 void complete(struct completion *c)
 {
         LASSERT(c != NULL);
-        (void)c;
+        c->done  = 1;
+        cfs_waitq_signal(&c->wait);
 }
 
 void wait_for_completion(struct completion *c)
 {
         LASSERT(c != NULL);
-        (void)c;
+}
+
+int wait_for_completion_interruptible(struct completion *c)
+{
+        LASSERT(c != NULL);
+        return 0;
 }
 
 /*
@@ -177,7 +188,6 @@ void wait_for_completion(struct completion *c)
  * - down_write(x)
  * - up_write(x)
  */
-struct rw_semaphore {};
 
 void init_rwsem(struct rw_semaphore *s)
 {
@@ -222,7 +232,6 @@ void up_write(struct rw_semaphore *s)
         LASSERT(s != NULL);
         (void)s;
 }
-#endif
 
 #ifdef HAVE_LIBPTHREAD