X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=libcfs%2Flibcfs%2Fuser-lock.c;h=fcba2cdd49d7c7db562c70125b0e55dae93515ee;hb=9e15e5077311150712f900fba80879cbf20d4ffb;hp=2b1c11eaba7d86560dd38464765d0e4922375fd7;hpb=004cc2b4c6eb32672985e2f4b4bbf9413e314547;p=fs%2Flustre-release.git diff --git a/libcfs/libcfs/user-lock.c b/libcfs/libcfs/user-lock.c index 2b1c11e..fcba2cd 100644 --- a/libcfs/libcfs/user-lock.c +++ b/libcfs/libcfs/user-lock.c @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -26,8 +24,10 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2012, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -71,44 +71,44 @@ * No-op implementation. */ -void cfs_spin_lock_init(cfs_spinlock_t *lock) +void spin_lock_init(spinlock_t *lock) { - LASSERT(lock != NULL); - (void)lock; + LASSERT(lock != NULL); + (void)lock; } -void cfs_spin_lock(cfs_spinlock_t *lock) +void spin_lock(spinlock_t *lock) { - (void)lock; + (void)lock; } -void cfs_spin_unlock(cfs_spinlock_t *lock) +void spin_unlock(spinlock_t *lock) { - (void)lock; + (void)lock; } -int cfs_spin_trylock(cfs_spinlock_t *lock) +int spin_trylock(spinlock_t *lock) { - (void)lock; + (void)lock; return 1; } -void cfs_spin_lock_bh_init(cfs_spinlock_t *lock) +void spin_lock_bh_init(spinlock_t *lock) { - LASSERT(lock != NULL); - (void)lock; + LASSERT(lock != NULL); + (void)lock; } -void cfs_spin_lock_bh(cfs_spinlock_t *lock) +void spin_lock_bh(spinlock_t *lock) { - LASSERT(lock != NULL); - (void)lock; + LASSERT(lock != NULL); + (void)lock; } -void cfs_spin_unlock_bh(cfs_spinlock_t *lock) +void spin_unlock_bh(spinlock_t *lock) { - LASSERT(lock != NULL); - (void)lock; + LASSERT(lock != NULL); + (void)lock; } /* @@ -119,23 +119,30 @@ void cfs_spin_unlock_bh(cfs_spinlock_t *lock) * - __up(x) */ -void cfs_sema_init(cfs_semaphore_t *s, int val) +void sema_init(struct semaphore *s, int val) +{ + LASSERT(s != NULL); + (void)s; + (void)val; +} + +void __down(struct semaphore *s) { - LASSERT(s != NULL); - (void)s; - (void)val; + LASSERT(s != NULL); + (void)s; } -void __down(cfs_semaphore_t *s) +int __down_interruptible(struct semaphore *s) { - LASSERT(s != NULL); - (void)s; + LASSERT(s != NULL); + (void)s; + return 0; } -void __up(cfs_semaphore_t *s) +void __up(struct semaphore *s) { - LASSERT(s != NULL); - (void)s; + LASSERT(s != NULL); + (void)s; } @@ -146,53 +153,58 @@ void __up(cfs_semaphore_t *s) * - complete(c) * - wait_for_completion(c) */ +static wait_handler_t wait_handler; -static cfs_wait_handler_t wait_handler; +void init_completion_module(wait_handler_t handler) +{ + wait_handler = handler; +} -void cfs_init_completion_module(cfs_wait_handler_t handler) +int call_wait_handler(int timeout) { - wait_handler = handler; + if (!wait_handler) + return -ENOSYS; + return wait_handler(timeout); } -int cfs_call_wait_handler(int timeout) +#ifndef HAVE_LIBPTHREAD +void init_completion(struct completion *c) { - if (!wait_handler) - return -ENOSYS; - return wait_handler(timeout); + LASSERT(c != NULL); + c->done = 0; + init_waitqueue_head(&c->wait); } -void cfs_init_completion(cfs_completion_t *c) +void fini_completion(struct completion *c) { - LASSERT(c != NULL); - c->done = 0; - cfs_waitq_init(&c->wait); } -void cfs_complete(cfs_completion_t *c) +void complete(struct completion *c) { - LASSERT(c != NULL); - c->done = 1; - cfs_waitq_signal(&c->wait); + LASSERT(c != NULL); + c->done = 1; + wake_up(&c->wait); } -void cfs_wait_for_completion(cfs_completion_t *c) +void wait_for_completion(struct completion *c) { - LASSERT(c != NULL); - do { - if (cfs_call_wait_handler(1000) < 0) - break; - } while (c->done == 0); + LASSERT(c != NULL); + do { + if (call_wait_handler(1000) < 0) + break; + } while (c->done == 0); } -int cfs_wait_for_completion_interruptible(cfs_completion_t *c) +int wait_for_completion_interruptible(struct completion *c) { - LASSERT(c != NULL); - do { - if (cfs_call_wait_handler(1000) < 0) - break; - } while (c->done == 0); - return 0; + LASSERT(c != NULL); + do { + if (call_wait_handler(1000) < 0) + break; + } while (c->done == 0); + return 0; } +#endif /* HAVE_LIBPTHREAD */ /* * rw_semaphore: @@ -205,63 +217,69 @@ int cfs_wait_for_completion_interruptible(cfs_completion_t *c) * - up_write(x) */ -void cfs_init_rwsem(cfs_rw_semaphore_t *s) +void init_rwsem(struct rw_semaphore *s) { - LASSERT(s != NULL); - (void)s; + LASSERT(s != NULL); + (void)s; } -void cfs_down_read(cfs_rw_semaphore_t *s) +void down_read(struct rw_semaphore *s) { - LASSERT(s != NULL); - (void)s; + LASSERT(s != NULL); + (void)s; } -int cfs_down_read_trylock(cfs_rw_semaphore_t *s) +int down_read_trylock(struct rw_semaphore *s) { - LASSERT(s != NULL); - (void)s; + LASSERT(s != NULL); + (void)s; return 1; } -void cfs_down_write(cfs_rw_semaphore_t *s) +void down_write(struct rw_semaphore *s) +{ + LASSERT(s != NULL); + (void)s; +} + +void downgrade_write(struct rw_semaphore *s) { - LASSERT(s != NULL); - (void)s; + LASSERT(s != NULL); + (void)s; } -int cfs_down_write_trylock(cfs_rw_semaphore_t *s) +int down_write_trylock(struct rw_semaphore *s) { - LASSERT(s != NULL); - (void)s; + LASSERT(s != NULL); + (void)s; return 1; } -void cfs_up_read(cfs_rw_semaphore_t *s) +void up_read(struct rw_semaphore *s) { - LASSERT(s != NULL); - (void)s; + LASSERT(s != NULL); + (void)s; } -void cfs_up_write(cfs_rw_semaphore_t *s) +void up_write(struct rw_semaphore *s) { - LASSERT(s != NULL); - (void)s; + LASSERT(s != NULL); + (void)s; } -void cfs_fini_rwsem(cfs_rw_semaphore_t *s) +void fini_rwsem(struct rw_semaphore *s) { - LASSERT(s != NULL); - (void)s; + LASSERT(s != NULL); + (void)s; } -#ifdef HAVE_PTHREAD +#ifdef HAVE_LIBPTHREAD /* * Multi-threaded user space completion */ -void cfs_mt_init_completion(cfs_mt_completion_t *c) +void init_completion(struct completion *c) { LASSERT(c != NULL); c->c_done = 0; @@ -269,14 +287,14 @@ void cfs_mt_init_completion(cfs_mt_completion_t *c) pthread_cond_init(&c->c_cond, NULL); } -void cfs_mt_fini_completion(cfs_mt_completion_t *c) +void fini_completion(struct completion *c) { LASSERT(c != NULL); pthread_mutex_destroy(&c->c_mut); pthread_cond_destroy(&c->c_cond); } -void cfs_mt_complete(cfs_mt_completion_t *c) +void complete(struct completion *c) { LASSERT(c != NULL); pthread_mutex_lock(&c->c_mut); @@ -285,7 +303,7 @@ void cfs_mt_complete(cfs_mt_completion_t *c) pthread_mutex_unlock(&c->c_mut); } -void cfs_mt_wait_for_completion(cfs_mt_completion_t *c) +void wait_for_completion(struct completion *c) { LASSERT(c != NULL); pthread_mutex_lock(&c->c_mut); @@ -301,7 +319,7 @@ void cfs_mt_wait_for_completion(cfs_mt_completion_t *c) static pthread_mutex_t atomic_guard_lock = PTHREAD_MUTEX_INITIALIZER; -int cfs_mt_atomic_read(cfs_mt_atomic_t *a) +int mt_atomic_read(mt_atomic_t *a) { int r; @@ -311,14 +329,14 @@ int cfs_mt_atomic_read(cfs_mt_atomic_t *a) return r; } -void cfs_mt_atomic_set(cfs_mt_atomic_t *a, int b) +void mt_atomic_set(mt_atomic_t *a, int b) { pthread_mutex_lock(&atomic_guard_lock); a->counter = b; pthread_mutex_unlock(&atomic_guard_lock); } -int cfs_mt_atomic_dec_and_test(cfs_mt_atomic_t *a) +int mt_atomic_dec_and_test(mt_atomic_t *a) { int r; @@ -328,20 +346,20 @@ int cfs_mt_atomic_dec_and_test(cfs_mt_atomic_t *a) return (r == 0); } -void cfs_mt_atomic_inc(cfs_mt_atomic_t *a) +void mt_atomic_inc(mt_atomic_t *a) { pthread_mutex_lock(&atomic_guard_lock); ++a->counter; pthread_mutex_unlock(&atomic_guard_lock); } -void cfs_mt_atomic_dec(cfs_mt_atomic_t *a) +void mt_atomic_dec(mt_atomic_t *a) { pthread_mutex_lock(&atomic_guard_lock); --a->counter; pthread_mutex_unlock(&atomic_guard_lock); } -void cfs_mt_atomic_add(int b, cfs_mt_atomic_t *a) +void mt_atomic_add(int b, mt_atomic_t *a) { pthread_mutex_lock(&atomic_guard_lock); @@ -349,14 +367,14 @@ void cfs_mt_atomic_add(int b, cfs_mt_atomic_t *a) pthread_mutex_unlock(&atomic_guard_lock); } -void cfs_mt_atomic_sub(int b, cfs_mt_atomic_t *a) +void mt_atomic_sub(int b, mt_atomic_t *a) { pthread_mutex_lock(&atomic_guard_lock); a->counter -= b; pthread_mutex_unlock(&atomic_guard_lock); } -#endif /* HAVE_PTHREAD */ +#endif /* HAVE_LIBPTHREAD */ /* !__KERNEL__ */