/* -*- 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 file is part of Lustre, http://www.lustre.org.
+ * 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 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 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 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.
+ * 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
*
- * 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.
+ * 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.
*
- * Implementation of portable time API for user-level.
+ * 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)
*
* - __down(x)
* - __up(x)
*/
-struct semaphore {};
void sema_init(struct semaphore *s, int val)
{
(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:
* - complete(c)
* - wait_for_completion(c)
*/
-struct completion {};
+
+static cfs_wait_handler_t wait_handler;
+
+void init_completion_module(cfs_wait_handler_t handler)
+{
+ wait_handler = handler;
+}
+
+int call_wait_handler(int timeout)
+{
+ if (!wait_handler)
+ return -ENOSYS;
+ return wait_handler(timeout);
+}
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;
+ do {
+ if (call_wait_handler(1000) < 0)
+ break;
+ } while (c->done == 0);
+}
+
+int wait_for_completion_interruptible(struct completion *c)
+{
+ LASSERT(c != NULL);
+ do {
+ if (call_wait_handler(1000) < 0)
+ break;
+ } while (c->done == 0);
+ return 0;
}
/*
* - down_write(x)
* - up_write(x)
*/
-struct rw_semaphore {};
void init_rwsem(struct rw_semaphore *s)
{
LASSERT(s != NULL);
(void)s;
}
-#endif
+
+void fini_rwsem(struct rw_semaphore *s)
+{
+ LASSERT(s != NULL);
+ (void)s;
+}
#ifdef HAVE_LIBPTHREAD