-/* -*- 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.
* 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/
#define ATOMIC_INIT(i) { i }
#define atomic_read(v) ((v)->counter)
-#define atomic_set(v,i) (((v)->counter) = (i))
+#define atomic_set(v,i) (((v)->counter) = (i))
void FASTCALL atomic_add(int i, atomic_t *v);
void FASTCALL atomic_sub(int i, atomic_t *v);
* N/A
*/
static inline void
- cfs_init_event(event_t *event, int type, int status)
+cfs_init_event(event_t *event, int type, int status)
{
KeInitializeEvent(
event,
*/
struct spin_lock {
- KSPIN_LOCK lock;
- KIRQL irql;
+ KSPIN_LOCK lock;
+ KIRQL irql;
};
-#define CFS_DECL_SPIN(name) spinlock_t name;
-#define CFS_DECL_SPIN_EXTERN(name) extern spinlock_t name;
+#define CFS_DECL_SPIN(name) spinlock_t name;
+#define CFS_DECL_SPIN_EXTERN(name) extern spinlock_t name;
-#define SPIN_LOCK_UNLOCKED {0}
+#define DEFINE_SPINLOCK {0}
static inline void spin_lock_init(spinlock_t *lock)
{
- KeInitializeSpinLock(&(lock->lock));
+ KeInitializeSpinLock(&(lock->lock));
}
static inline void spin_lock(spinlock_t *lock)
{
- KeAcquireSpinLock(&(lock->lock), &(lock->irql));
+ KeAcquireSpinLock(&(lock->lock), &(lock->irql));
}
static inline void spin_lock_nested(spinlock_t *lock, unsigned subclass)
{
- KeAcquireSpinLock(&(lock->lock), &(lock->irql));
+ KeAcquireSpinLock(&(lock->lock), &(lock->irql));
}
static inline void spin_unlock(spinlock_t *lock)
{
- KIRQL irql = lock->irql;
- KeReleaseSpinLock(&(lock->lock), irql);
+ KIRQL irql = lock->irql;
+ KeReleaseSpinLock(&(lock->lock), irql);
}
-#define spin_lock_irqsave(lock, flags) do {(flags) = 0; spin_lock(lock);} while(0)
-#define spin_unlock_irqrestore(lock, flags) do {spin_unlock(lock);} while(0)
+#define spin_lock_irqsave(lock, flags) \
+ do { (flags) = 0; spin_lock(lock); } while (0)
+
+#define spin_unlock_irqrestore(lock, flags) \
+ do { spin_unlock(lock); } while (0)
/* There's no corresponding routine in windows kernel.
static int spin_trylock(spinlock_t *lock)
{
- KIRQL Irql;
- int rc = 0;
+ KIRQL Irql;
+ int rc = 0;
- ASSERT(lock != NULL);
+ ASSERT(lock != NULL);
- KeRaiseIrql(DISPATCH_LEVEL, &Irql);
+ KeRaiseIrql(DISPATCH_LEVEL, &Irql);
- if (libcfs_mp_system) {
- if (0 == (ulong_ptr_t)lock->lock) {
+ if (libcfs_mp_system) {
+ if (0 == (ulong_ptr_t)lock->lock) {
#if _X86_
- __asm {
- mov edx, dword ptr [ebp + 8]
- lock bts dword ptr[edx], 0
- jb lock_failed
- mov rc, TRUE
- lock_failed:
- }
+ __asm {
+ mov edx, dword ptr [ebp + 8]
+ lock bts dword ptr[edx], 0
+ jb lock_failed
+ mov rc, TRUE
+ lock_failed:
+ }
#else
- KdBreakPoint();
+ KdBreakPoint();
#endif
- }
- } else {
- rc = TRUE;
- }
+ }
+ } else {
+ rc = TRUE;
+ }
- if (rc) {
- lock->irql = Irql;
- } else {
- KeLowerIrql(Irql);
- }
+ if (rc) {
+ lock->irql = Irql;
+ } else {
+ KeLowerIrql(Irql);
+ }
- return rc;
+ return rc;
}
static int spin_is_locked(spinlock_t *lock)
{
#if _WIN32_WINNT >= 0x502
- /* KeTestSpinLock only avalilable on 2k3 server or later */
- return (!KeTestSpinLock(&lock->lock));
+ /* KeTestSpinLock only avalilable on 2k3 server or later */
+ return !KeTestSpinLock(&lock->lock);
#else
- return (int) (lock->lock);
+ return (int) (lock->lock);
#endif
}
/* synchronization between cpus: it will disable all DPCs
kernel task scheduler on the CPU */
-#define spin_lock_bh(x) spin_lock(x)
-#define spin_unlock_bh(x) spin_unlock(x)
+#define spin_lock_bh(x) spin_lock(x)
+#define spin_unlock_bh(x) spin_unlock(x)
#define spin_lock_bh_init(x) spin_lock_init(x)
/*
*/
-typedef struct rw_semaphore {
- ERESOURCE rwsem;
-} rw_semaphore_t;
+struct rw_semaphore {
+ ERESOURCE rwsem;
+};
-#define CFS_DECL_RWSEM(name) rw_semaphore_t name
-#define CFS_DECL_RWSEM_EXTERN(name) extern rw_semaphore_t name
-#define DECLARE_RWSEM CFS_DECL_RWSEM
+#define DECLARE_RWSEM(name) struct rw_semaphore name
+#define CFS_DECLARE_RWSEM_EXTERN(name) extern struct rw_semaphore name
/*
* init_rwsem
- * To initialize the the rw_semaphore_t structure
+ * To initialize the the rw_semaphore structure
*
* Arguments:
- * rwsem: pointer to the rw_semaphore_t structure
+ * rwsem: pointer to the rw_semaphore structure
*
* Return Value:
* N/A
* N/A
*/
-static inline void init_rwsem(rw_semaphore_t *s)
+static inline void init_rwsem(struct rw_semaphore *s)
{
ExInitializeResourceLite(&s->rwsem);
}
/*
* fini_rwsem
- * To finilize/destroy the the rw_semaphore_t structure
+ * To finilize/destroy the the rw_semaphore structure
*
* Arguments:
- * rwsem: pointer to the rw_semaphore_t structure
+ * rwsem: pointer to the rw_semaphore structure
*
* Return Value:
* N/A
* Just define it NULL for other systems.
*/
-static inline void fini_rwsem(rw_semaphore_t *s)
+static inline void fini_rwsem(struct rw_semaphore *s)
{
- ExDeleteResourceLite(&s->rwsem);
+ ExDeleteResourceLite(&s->rwsem);
}
-#define rwsem_fini fini_rwsem
/*
* down_read
- * To acquire read-lock of the rw_semahore
+ * To acquire read-lock of the rw_semaphore
*
* Arguments:
- * rwsem: pointer to the rw_semaphore_t structure
+ * rwsem: pointer to the struct rw_semaphore
*
* Return Value:
* N/A
/*
* down_read_trylock
- * To acquire read-lock of the rw_semahore without blocking
+ * To acquire read-lock of the rw_semaphore without blocking
*
* Arguments:
- * rwsem: pointer to the rw_semaphore_t structure
+ * rwsem: pointer to the struct rw_semaphore
*
* Return Value:
* Zero: failed to acquire the read lock
/*
* down_write
- * To acquire write-lock of the rw_semahore
+ * To acquire write-lock of the struct rw_semaphore
*
* Arguments:
- * rwsem: pointer to the rw_semaphore_t structure
+ * rwsem: pointer to the struct rw_semaphore
*
* Return Value:
* N/A
/*
* down_write_trylock
- * To acquire write-lock of the rw_semahore without blocking
+ * To acquire write-lock of the rw_semaphore without blocking
*
* Arguments:
- * rwsem: pointer to the rw_semaphore_t structure
+ * rwsem: pointer to the struct rw_semaphore
*
* Return Value:
* Zero: failed to acquire the write lock
static inline int down_write_trylock(struct rw_semaphore *s)
{
- return ExAcquireResourceExclusiveLite(&(s->rwsem), FALSE);
+ return ExAcquireResourceExclusiveLite(&(s->rwsem), FALSE);
}
/*
* up_read
- * To release read-lock of the rw_semahore
+ * To release read-lock of the rw_semaphore
*
* Arguments:
- * rwsem: pointer to the rw_semaphore_t structure
+ * rwsem: pointer to the struct rw_semaphore
*
* Return Value:
* N/A
static inline void up_read(struct rw_semaphore *s)
{
- ExReleaseResourceForThreadLite(
- &(s->rwsem),
- ExGetCurrentResourceThread());
+ ExReleaseResourceForThreadLite(&(s->rwsem),
+ ExGetCurrentResourceThread());
}
/*
* up_write
- * To release write-lock of the rw_semahore
+ * To release write-lock of the rw_semaphore
*
* Arguments:
- * rwsem: pointer to the rw_semaphore_t structure
+ * rwsem: pointer to the struct rw_semaphore
*
* Return Value:
* N/A
static inline void up_write(struct rw_semaphore *s)
{
- ExReleaseResourceForThreadLite(
- &(s->rwsem),
- ExGetCurrentResourceThread());
+ ExReleaseResourceForThreadLite(&(s->rwsem),
+ ExGetCurrentResourceThread());
}
/*
*/
typedef struct {
- spinlock_t guard;
- int count;
+ spinlock_t guard;
+ int count;
} rwlock_t;
-void rwlock_init(rwlock_t * rwlock);
-void rwlock_fini(rwlock_t * rwlock);
+void rwlock_init(rwlock_t *rwlock);
+void cfs_rwlock_fini(rwlock_t *rwlock);
-void read_lock(rwlock_t * rwlock);
-void read_unlock(rwlock_t * rwlock);
-void write_lock(rwlock_t * rwlock);
-void write_unlock(rwlock_t * rwlock);
+void read_lock(rwlock_t *rwlock);
+void read_unlock(rwlock_t *rwlock);
+void write_lock(rwlock_t *rwlock);
+void write_unlock(rwlock_t *rwlock);
-#define write_lock_irqsave(l, f) do {f = 0; write_lock(l);} while(0)
-#define write_unlock_irqrestore(l, f) do {write_unlock(l);} while(0)
-#define read_lock_irqsave(l, f) do {f=0; read_lock(l);} while(0)
-#define read_unlock_irqrestore(l, f) do {read_unlock(l);} while(0)
+#define write_lock_irqsave(l, f) do { f = 0; write_lock(l); } while (0)
+#define write_unlock_irqrestore(l, f) do { write_unlock(l); } while (0)
+#define read_lock_irqsave(l, f) do { f = 0; read_lock(l); } while (0)
+#define read_unlock_irqrestore(l, f) do { read_unlock(l); } while (0)
-#define write_lock_bh write_lock
-#define write_unlock_bh write_unlock
+#define write_lock_bh write_lock
+#define write_unlock_bh write_unlock
-struct lock_class_key {int foo;};
-#define lockdep_set_class(lock, class) do {} while(0)
+struct lock_class_key {
+ int foo;
+};
+
+#define lockdep_set_class(lock, class) do {} while (0)
static inline void lockdep_off(void)
{
* - __up(x)
*/
-struct semaphore{
+struct semaphore {
KSEMAPHORE sem;
};
static inline void __down(struct semaphore *s)
{
- KeWaitForSingleObject( &(s->sem), Executive,
- KernelMode, FALSE, NULL );
+ KeWaitForSingleObject(&(s->sem), Executive, KernelMode, FALSE, NULL);
}
static inline void __up(struct semaphore *s)
KeReleaseSemaphore(&s->sem, 0, 1, FALSE);
}
-static inline int down_trylock(struct semaphore * s)
+static inline int down_trylock(struct semaphore *s)
{
- LARGE_INTEGER timeout = {0};
- NTSTATUS status =
- KeWaitForSingleObject( &(s->sem), Executive,
- KernelMode, FALSE, &timeout);
+ LARGE_INTEGER timeout = {0};
+ NTSTATUS status = KeWaitForSingleObject(&(s->sem), Executive,
+ KernelMode, FALSE, &timeout);
- if (status == STATUS_SUCCESS) {
- return 0;
- }
+ if (status == STATUS_SUCCESS)
+ return 0;
- return 1;
+ return 1;
}
/*
*/
#define mutex semaphore
-typedef struct semaphore mutex_t;
-#define DECLARE_MUTEX(x) mutex_t x
+#define CFS_DECLARE_MUTEX(x) struct mutex x
/*
* init_mutex
* Notes:
* N/A
*/
-#define mutex_init init_mutex
-static inline void init_mutex(mutex_t *mutex)
+#define mutex_init cfs_init_mutex
+static inline void cfs_init_mutex(struct mutex *mutex)
{
- sema_init(mutex, 1);
+ sema_init(mutex, 1);
}
-#define init_MUTEX init_mutex
/*
* mutex_down
* To acquire the mutex lock
* N/A
*/
-static inline void mutex_down(mutex_t *mutex)
+static inline void cfs_mutex_down(struct mutex *mutex)
{
- __down(mutex);
+ __down(mutex);
}
-#define mutex_lock(m) mutex_down(m)
-#define mutex_trylock(s) down_trylock(s)
-#define mutex_lock_nested(m) mutex_down(m)
-#define down(m) mutex_down(m)
+static inline int cfs_mutex_down_interruptible(struct mutex *mutex)
+{
+ __down(mutex);
+ return 0;
+}
+
+#define mutex_lock(m) cfs_mutex_down(m)
+#define mutex_trylock(s) down_trylock(s)
+#define mutex_lock_nested(m) cfs_mutex_down(m)
+#define down(m) cfs_mutex_down(m)
+#define down_interruptible(m) cfs_mutex_down_interruptible(m)
/*
* mutex_up
* N/A
*/
-static inline void mutex_up(mutex_t *mutex)
+static inline void cfs_mutex_up(struct mutex *mutex)
{
- __up(mutex);
+ __up(mutex);
}
-#define mutex_unlock(m) mutex_up(m)
-#define up(m) mutex_up(m)
+#define mutex_unlock(m) cfs_mutex_up(m)
+#define up(m) cfs_mutex_up(m)
/*
* init_mutex_locked
* N/A
*/
-static inline void init_mutex_locked(mutex_t *mutex)
+static inline void cfs_init_mutex_locked(struct mutex *mutex)
{
- init_mutex(mutex);
- mutex_down(mutex);
+ cfs_init_mutex(mutex);
+ cfs_mutex_down(mutex);
}
-#define init_MUTEX_LOCKED init_mutex_locked
-
-static inline void mutex_destroy(mutex_t *mutex)
+static inline void mutex_destroy(struct mutex *mutex)
{
}
* - wait_for_completion(c)
*/
-struct completion {
+struct completion{
event_t event;
};
static inline void wait_for_completion(struct completion *c)
{
- cfs_wait_event_internal(&(c->event), 0);
+ cfs_wait_event_internal(&(c->event), 0);
}
static inline int wait_for_completion_interruptible(struct completion *c)
{
- cfs_wait_event_internal(&(c->event), 0);
- return 0;
+ cfs_wait_event_internal(&(c->event), 0);
+ return 0;
}
-/*
- * spinlock "implementation"
- */
-
-typedef spinlock_t cfs_spinlock_t;
-
-#define cfs_spin_lock_init(lock) spin_lock_init(lock)
-#define cfs_spin_lock(lock) spin_lock(lock)
-#define cfs_spin_lock_bh(lock) spin_lock_bh(lock)
-#define cfs_spin_unlock(lock) spin_unlock(lock)
-#define cfs_spin_unlock_bh(lock) spin_unlock_bh(lock)
-
-/*
- * rwlock "implementation"
- */
-
-typedef rwlock_t cfs_rwlock_t;
-
-#define cfs_rwlock_init(lock) rwlock_init(lock)
-#define cfs_read_lock(lock) read_lock(lock)
-#define cfs_read_unlock(lock) read_unlock(lock)
-#define cfs_write_lock_bh(lock) write_lock_bh(lock)
-#define cfs_write_unlock_bh(lock) write_unlock_bh(lock)
-
-/*
- * atomic
- */
-
-typedef atomic_t cfs_atomic_t;
-
-#define cfs_atomic_read(atom) atomic_read(atom)
-#define cfs_atomic_inc(atom) atomic_inc(atom)
-#define cfs_atomic_dec(atom) atomic_dec(atom)
-#define cfs_atomic_dec_and_test(atom) atomic_dec_and_test(atom)
-#define cfs_atomic_set(atom, value) atomic_set(atom, value)
-#define cfs_atomic_add(value, atom) atomic_add(value, atom)
-#define cfs_atomic_sub(value, atom) atomic_sub(value, atom)
-
-#else /* !__KERNEL__ */
#endif /* !__KERNEL__ */
#endif