Whamcloud - gitweb
b=17167 libcfs: ensure all libcfs exported symbols to have cfs_ prefix
[fs/lustre-release.git] / libcfs / include / libcfs / winnt / winnt-lock.h
index cbff12d..4c7bd5e 100644 (file)
  *  spinlock & event definitions
  */
 
-typedef struct spin_lock spinlock_t;
+typedef struct cfs_spin_lock cfs_spinlock_t;
 
 /* atomic */
 
-typedef struct { volatile int counter; } atomic_t;
+typedef struct { volatile int counter; } cfs_atomic_t;
 
-#define ATOMIC_INIT(i) { i }
+#define CFS_ATOMIC_INIT(i)     { i }
 
-#define atomic_read(v) ((v)->counter)
-#define atomic_set(v,i)                (((v)->counter) = (i))
+#define cfs_atomic_read(v)     ((v)->counter)
+#define cfs_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);
+void FASTCALL cfs_atomic_add(int i, cfs_atomic_t *v);
+void FASTCALL cfs_atomic_sub(int i, cfs_atomic_t *v);
 
-int FASTCALL atomic_sub_and_test(int i, atomic_t *v);
+int FASTCALL cfs_atomic_sub_and_test(int i, cfs_atomic_t *v);
 
-void FASTCALL atomic_inc(atomic_t *v);
-void FASTCALL atomic_dec(atomic_t *v);
+void FASTCALL cfs_atomic_inc(cfs_atomic_t *v);
+void FASTCALL cfs_atomic_dec(cfs_atomic_t *v);
 
-int FASTCALL atomic_dec_and_test(atomic_t *v);
-int FASTCALL atomic_inc_and_test(atomic_t *v);
+int FASTCALL cfs_atomic_dec_and_test(cfs_atomic_t *v);
+int FASTCALL cfs_atomic_inc_and_test(cfs_atomic_t *v);
 
-int FASTCALL atomic_add_return(int i, atomic_t *v);
-int FASTCALL atomic_sub_return(int i, atomic_t *v);
+int FASTCALL cfs_atomic_add_return(int i, cfs_atomic_t *v);
+int FASTCALL cfs_atomic_sub_return(int i, cfs_atomic_t *v);
 
-#define atomic_inc_return(v)  atomic_add_return(1, v)
-#define atomic_dec_return(v)  atomic_sub_return(1, v)
+#define cfs_atomic_inc_return(v)  cfs_atomic_add_return(1, v)
+#define cfs_atomic_dec_return(v)  cfs_atomic_sub_return(1, v)
 
-int FASTCALL atomic_dec_and_lock(atomic_t *v, spinlock_t *lock);
+int FASTCALL cfs_atomic_dec_and_lock(cfs_atomic_t *v, cfs_spinlock_t *lock);
 
 /* event */
 
@@ -113,7 +113,7 @@ typedef KEVENT          event_t;
  *   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,
@@ -144,7 +144,7 @@ cfs_wait_event_internal(event_t * event, int64_t timeout)
     NTSTATUS        Status;
     LARGE_INTEGER   TimeOut;
 
-    TimeOut.QuadPart = -1 * (10000000/HZ) * timeout;
+    TimeOut.QuadPart = -1 * (10000000/CFS_HZ) * timeout;
 
     Status = KeWaitForSingleObject(
                 event,
@@ -215,40 +215,43 @@ cfs_clear_event(event_t * event)
  *
  */
 
-struct spin_lock {
+struct cfs_spin_lock {
     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)  cfs_spinlock_t name;
+#define CFS_DECL_SPIN_EXTERN(name)  extern cfs_spinlock_t name;
 
-#define SPIN_LOCK_UNLOCKED {0}
+#define CFS_SPIN_LOCK_UNLOCKED {0}
 
-static inline void spin_lock_init(spinlock_t *lock)
+static inline void cfs_spin_lock_init(cfs_spinlock_t *lock)
 {
     KeInitializeSpinLock(&(lock->lock));
 }
 
-static inline void spin_lock(spinlock_t *lock)
+static inline void cfs_spin_lock(cfs_spinlock_t *lock)
 {
     KeAcquireSpinLock(&(lock->lock), &(lock->irql));
 }
 
-static inline void spin_lock_nested(spinlock_t *lock, unsigned subclass)
+static inline void cfs_spin_lock_nested(cfs_spinlock_t *lock, unsigned subclass)
 {
     KeAcquireSpinLock(&(lock->lock), &(lock->irql));
 }
 
-static inline void spin_unlock(spinlock_t *lock)
+static inline void cfs_spin_unlock(cfs_spinlock_t *lock)
 {
     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 cfs_spin_lock_irqsave(lock, flags)  \
+do {(flags) = 0; cfs_spin_lock(lock);} while(0)
+
+#define cfs_spin_unlock_irqrestore(lock, flags) \
+do {cfs_spin_unlock(lock);} while(0)
 
 
 /* There's no  corresponding routine in windows kernel.
@@ -258,7 +261,7 @@ static inline void spin_unlock(spinlock_t *lock)
 
 extern int libcfs_mp_system;
 
-static int spin_trylock(spinlock_t *lock)
+static int cfs_spin_trylock(cfs_spinlock_t *lock)
 {
     KIRQL   Irql;
     int     rc = 0;
@@ -295,7 +298,7 @@ static int spin_trylock(spinlock_t *lock)
     return rc;
 }
 
-static int spin_is_locked(spinlock_t *lock)
+static int cfs_spin_is_locked(cfs_spinlock_t *lock)
 {
 #if _WIN32_WINNT >= 0x502
     /* KeTestSpinLock only avalilable on 2k3 server or later */
@@ -307,30 +310,29 @@ static int spin_is_locked(spinlock_t *lock)
 
 /* 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_init(x)   spin_lock_init(x)
+#define cfs_spin_lock_bh(x)                cfs_spin_lock(x)
+#define cfs_spin_unlock_bh(x)      cfs_spin_unlock(x)
+#define cfs_spin_lock_bh_init(x)       cfs_spin_lock_init(x)
 
 /*
- * rw_semaphore (using ERESOURCE)
+ * cfs_rw_semaphore (using ERESOURCE)
  */
 
 
-typedef struct rw_semaphore {
+typedef struct cfs_rw_semaphore {
     ERESOURCE   rwsem;
-} rw_semaphore_t;
+} cfs_rw_semaphore_t;
 
 
-#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 CFS_DECLARE_RWSEM(name) cfs_rw_semaphore_t name
+#define CFS_DECLARE_RWSEM_EXTERN(name) extern cfs_rw_semaphore_t name
 
 /*
- * init_rwsem
- *   To initialize the the rw_semaphore_t structure
+ * cfs_init_rwsem
+ *   To initialize the the cfs_rw_semaphore_t structure
  *
  * Arguments:
- *   rwsem:  pointer to the rw_semaphore_t structure
+ *   rwsem:  pointer to the cfs_rw_semaphore_t structure
  *
  * Return Value:
  *   N/A
@@ -339,18 +341,18 @@ typedef struct rw_semaphore {
  *   N/A
  */
 
-static inline void init_rwsem(rw_semaphore_t *s)
+static inline void cfs_init_rwsem(cfs_rw_semaphore_t *s)
 {
        ExInitializeResourceLite(&s->rwsem);
 }
-#define rwsem_init init_rwsem
+#define rwsem_init cfs_init_rwsem
 
 /*
- * fini_rwsem
- *   To finilize/destroy the the rw_semaphore_t structure
+ * cfs_fini_rwsem
+ *   To finilize/destroy the the cfs_rw_semaphore_t structure
  *
  * Arguments:
- *   rwsem:  pointer to the rw_semaphore_t structure
+ *   rwsem:  pointer to the cfs_rw_semaphore_t structure
  *
  * Return Value:
  *   N/A
@@ -360,18 +362,17 @@ static inline void init_rwsem(rw_semaphore_t *s)
  *   Just define it NULL for other systems.
  */
 
-static inline void fini_rwsem(rw_semaphore_t *s)
+static inline void cfs_fini_rwsem(cfs_rw_semaphore_t *s)
 {
     ExDeleteResourceLite(&s->rwsem);
 }
-#define rwsem_fini fini_rwsem
 
 /*
- * down_read
- *   To acquire read-lock of the rw_semahore
+ * cfs_down_read
+ *   To acquire read-lock of the cfs_rw_semaphore
  *
  * Arguments:
- *   rwsem:  pointer to the rw_semaphore_t structure
+ *   rwsem:  pointer to the cfs_rw_semaphore_t structure
  *
  * Return Value:
  *   N/A
@@ -380,19 +381,19 @@ static inline void fini_rwsem(rw_semaphore_t *s)
  *   N/A
  */
 
-static inline void down_read(struct rw_semaphore *s)
+static inline void cfs_down_read(cfs_rw_semaphore_t *s)
 {
        ExAcquireResourceSharedLite(&s->rwsem, TRUE);
 }
-#define down_read_nested down_read
+#define cfs_down_read_nested cfs_down_read
 
 
 /*
- * down_read_trylock
- *   To acquire read-lock of the rw_semahore without blocking
+ * cfs_down_read_trylock
+ *   To acquire read-lock of the cfs_rw_semaphore without blocking
  *
  * Arguments:
- *   rwsem:  pointer to the rw_semaphore_t structure
+ *   rwsem:  pointer to the cfs_rw_semaphore_t structure
  *
  * Return Value:
  *   Zero: failed to acquire the read lock
@@ -402,18 +403,18 @@ static inline void down_read(struct rw_semaphore *s)
  *   This routine will return immediately without waiting.
  */
 
-static inline int down_read_trylock(struct rw_semaphore *s)
+static inline int cfs_down_read_trylock(cfs_rw_semaphore_t *s)
 {
        return ExAcquireResourceSharedLite(&s->rwsem, FALSE);
 }
 
 
 /*
- * down_write
- *   To acquire write-lock of the rw_semahore
+ * cfs_down_write
+ *   To acquire write-lock of the cfs_rw_semaphore
  *
  * Arguments:
- *   rwsem:  pointer to the rw_semaphore_t structure
+ *   rwsem:  pointer to the cfs_rw_semaphore_t structure
  *
  * Return Value:
  *   N/A
@@ -422,18 +423,18 @@ static inline int down_read_trylock(struct rw_semaphore *s)
  *   N/A
  */
 
-static inline void down_write(struct rw_semaphore *s)
+static inline void cfs_down_write(cfs_rw_semaphore_t *s)
 {
        ExAcquireResourceExclusiveLite(&(s->rwsem), TRUE);
 }
-#define down_write_nested down_write
+#define cfs_down_write_nested cfs_down_write
 
 /*
  * down_write_trylock
- *   To acquire write-lock of the rw_semahore without blocking
+ *   To acquire write-lock of the cfs_rw_semaphore without blocking
  *
  * Arguments:
- *   rwsem:  pointer to the rw_semaphore_t structure
+ *   rwsem:  pointer to the cfs_rw_semaphore_t structure
  *
  * Return Value:
  *   Zero: failed to acquire the write lock
@@ -443,18 +444,18 @@ static inline void down_write(struct rw_semaphore *s)
  *   This routine will return immediately without waiting.
  */
 
-static inline int down_write_trylock(struct rw_semaphore *s)
+static inline int cfs_down_write_trylock(cfs_rw_semaphore_t *s)
 {
     return ExAcquireResourceExclusiveLite(&(s->rwsem), FALSE);
 }
 
 
 /*
- * up_read
- *   To release read-lock of the rw_semahore
+ * cfs_up_read
+ *   To release read-lock of the cfs_rw_semaphore
  *
  * Arguments:
- *   rwsem:  pointer to the rw_semaphore_t structure
+ *   rwsem:  pointer to the cfs_rw_semaphore_t structure
  *
  * Return Value:
  *   N/A
@@ -463,7 +464,7 @@ static inline int down_write_trylock(struct rw_semaphore *s)
  *   N/A
  */
 
-static inline void up_read(struct rw_semaphore *s)
+static inline void cfs_up_read(cfs_rw_semaphore_t *s)
 {
     ExReleaseResourceForThreadLite(
             &(s->rwsem),
@@ -472,11 +473,11 @@ static inline void up_read(struct rw_semaphore *s)
 
 
 /*
- * up_write
- *   To release write-lock of the rw_semahore
+ * cfs_up_write
+ *   To release write-lock of the cfs_rw_semaphore
  *
  * Arguments:
- *   rwsem:  pointer to the rw_semaphore_t structure
+ *   rwsem:  pointer to the cfs_rw_semaphore_t structure
  *
  * Return Value:
  *   N/A
@@ -485,7 +486,7 @@ static inline void up_read(struct rw_semaphore *s)
  *   N/A
  */
 
-static inline void up_write(struct rw_semaphore *s)
+static inline void cfs_up_write(cfs_rw_semaphore_t *s)
 {
     ExReleaseResourceForThreadLite(
                 &(s->rwsem),
@@ -503,34 +504,37 @@ static inline void up_write(struct rw_semaphore *s)
  */
 
 typedef struct {
-    spinlock_t guard;
-    int        count;
-} rwlock_t;
+    cfs_spinlock_t guard;
+    int            count;
+} cfs_rwlock_t;
+
+void cfs_rwlock_init(cfs_rwlock_t * rwlock);
+void cfs_rwlock_fini(cfs_rwlock_t * rwlock);
 
-void rwlock_init(rwlock_t * rwlock);
-void rwlock_fini(rwlock_t * rwlock);
+void cfs_read_lock(cfs_rwlock_t * rwlock);
+void cfs_read_unlock(cfs_rwlock_t * rwlock);
+void cfs_write_lock(cfs_rwlock_t * rwlock);
+void cfs_write_unlock(cfs_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 cfs_write_lock_irqsave(l, f)     do {f = 0; cfs_write_lock(l);} while(0)
+#define cfs_write_unlock_irqrestore(l, f)   do {cfs_write_unlock(l);} while(0)
+#define cfs_read_lock_irqsave(l, f         do {f=0; cfs_read_lock(l);} while(0)
+#define cfs_read_unlock_irqrestore(l, f)    do {cfs_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 cfs_write_lock_bh   cfs_write_lock
+#define cfs_write_unlock_bh cfs_write_unlock
 
-#define write_lock_bh   write_lock
-#define write_unlock_bh write_unlock
+typedef struct cfs_lock_class_key {
+        int foo;
+} cfs_lock_class_key_t;
 
-struct lock_class_key {int foo;};
-#define lockdep_set_class(lock, class) do {} while(0)
+#define cfs_lockdep_set_class(lock, class) do {} while(0)
 
-static inline void lockdep_off(void)
+static inline void cfs_lockdep_off(void)
 {
 }
 
-static inline void lockdep_on(void)
+static inline void cfs_lockdep_on(void)
 {
 }
 
@@ -542,27 +546,27 @@ static inline void lockdep_on(void)
  * - __up(x)
  */
 
-struct semaphore{
+typedef struct cfs_semaphore {
        KSEMAPHORE sem;
-};
+} cfs_semaphore_t;
 
-static inline void sema_init(struct semaphore *s, int val)
+static inline void cfs_sema_init(cfs_semaphore_t *s, int val)
 {
        KeInitializeSemaphore(&s->sem, val, val);
 }
 
-static inline void __down(struct semaphore *s)
+static inline void __down(cfs_semaphore_t *s)
 {
    KeWaitForSingleObject( &(s->sem), Executive,
                           KernelMode, FALSE, NULL );
 
 }
-static inline void __up(struct semaphore *s)
+static inline void __up(cfs_semaphore_t *s)
 {
        KeReleaseSemaphore(&s->sem, 0, 1, FALSE);
 }
 
-static inline int down_trylock(struct semaphore * s)
+static inline int down_trylock(cfs_semaphore_t *s)
 {
     LARGE_INTEGER  timeout = {0};
     NTSTATUS status =
@@ -585,10 +589,9 @@ static inline int down_trylock(struct semaphore * s)
  * - mutex_down(x)
  */
 
-#define mutex semaphore
-typedef struct semaphore mutex_t;
+typedef struct cfs_semaphore cfs_mutex_t;
 
-#define DECLARE_MUTEX(x) mutex_t x
+#define CFS_DECLARE_MUTEX(x) cfs_mutex_t x
 
 /*
  * init_mutex
@@ -603,13 +606,12 @@ typedef struct semaphore mutex_t;
  * Notes:
  *   N/A
  */
-#define mutex_init init_mutex
-static inline void init_mutex(mutex_t *mutex)
+#define cfs_mutex_init cfs_init_mutex
+static inline void cfs_init_mutex(cfs_mutex_t *mutex)
 {
-    sema_init(mutex, 1);
+    cfs_sema_init(mutex, 1);
 }
 
-#define init_MUTEX init_mutex
 /*
  * mutex_down
  *   To acquire the mutex lock
@@ -624,15 +626,15 @@ static inline void init_mutex(mutex_t *mutex)
  *   N/A
  */
 
-static inline void mutex_down(mutex_t *mutex)
+static inline void cfs_mutex_down(cfs_mutex_t *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)
+#define cfs_mutex_lock(m) cfs_mutex_down(m)
+#define cfs_mutex_trylock(s) down_trylock(s)
+#define cfs_mutex_lock_nested(m) cfs_mutex_down(m)
+#define cfs_down(m)       cfs_mutex_down(m)
 
 /*
  * mutex_up
@@ -648,13 +650,13 @@ static inline void mutex_down(mutex_t *mutex)
  *   N/A
  */
 
-static inline void mutex_up(mutex_t *mutex)
+static inline void cfs_mutex_up(cfs_mutex_t *mutex)
 {
     __up(mutex);
 }
 
-#define mutex_unlock(m) mutex_up(m)
-#define up(m)           mutex_up(m)
+#define cfs_mutex_unlock(m) cfs_mutex_up(m)
+#define cfs_up(m)           cfs_mutex_up(m)
 
 /*
  * init_mutex_locked
@@ -670,15 +672,13 @@ static inline void mutex_up(mutex_t *mutex)
  *   N/A
  */
 
-static inline void init_mutex_locked(mutex_t *mutex)
+static inline void cfs_init_mutex_locked(cfs_mutex_t *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 cfs_mutex_destroy(cfs_mutex_t *mutex)
 {
 }
 
@@ -690,9 +690,9 @@ static inline void mutex_destroy(mutex_t *mutex)
  * - wait_for_completion(c)
  */
 
-struct completion {
+typedef struct {
        event_t  event;
-};
+} cfs_completion_t;
 
 
 /*
@@ -709,7 +709,7 @@ struct completion {
  *   N/A
  */
 
-static inline void init_completion(struct completion *c)
+static inline void cfs_init_completion(cfs_completion_t *c)
 {
        cfs_init_event(&(c->event), 1, FALSE);
 }
@@ -729,7 +729,7 @@ static inline void init_completion(struct completion *c)
  *   N/A
  */
 
-static inline void complete(struct completion *c)
+static inline void cfs_complete(cfs_completion_t *c)
 {
        cfs_wake_event(&(c->event));
 }
@@ -749,55 +749,17 @@ static inline void complete(struct completion *c)
  *   N/A
  */
 
-static inline void wait_for_completion(struct completion *c)
+static inline void cfs_wait_for_completion(cfs_completion_t *c)
 {
     cfs_wait_event_internal(&(c->event), 0);
 }
 
-static inline int wait_for_completion_interruptible(struct completion *c)
+static inline int cfs_wait_for_completion_interruptible(cfs_completion_t *c)
 {
     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