Whamcloud - gitweb
LU-56 libcfs: implementation of cpu partition
[fs/lustre-release.git] / libcfs / libcfs / winnt / winnt-sync.c
index 5094bef..fc62f39 100644 (file)
@@ -1,25 +1,40 @@
-/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=4:tabstop=4:
- *
- *  Copyright (c) 2004 Cluster File Systems, Inc.
- *
- *   This file is part of Lustre, http://www.lustre.org.
- *
- *   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. 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 along with Lustre; if not, write
- *   to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
- *   USA.
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * 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.
+ *
+ * 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
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * 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 (c) 2008, 2010, Oracle and/or its affiliates. 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.
  */
 
-#define DEBUG_SUBSYSTEM S_LIBCFS
+#define DEBUG_SUBSYSTEM S_LNET
 
 #include <libcfs/libcfs.h>
-#include <libcfs/kp30.h>
 
 
 /*
@@ -44,8 +59,8 @@ void cfs_waitq_init(cfs_waitq_t *waitq)
 {
     waitq->magic = CFS_WAITQ_MAGIC;
     waitq->flags = 0;
-    INIT_LIST_HEAD(&(waitq->waiters));
-    spin_lock_init(&(waitq->guard));
+    CFS_INIT_LIST_HEAD(&(waitq->waiters));
+    cfs_spin_lock_init(&(waitq->guard));
 }
 
 /*
@@ -84,10 +99,10 @@ void cfs_waitlink_init(cfs_waitlink_t *link)
     link->event = &(slot->Event);
     link->hits  = &(slot->hits);
 
-    atomic_inc(&slot->count);
+    cfs_atomic_inc(&slot->count);
 
-    INIT_LIST_HEAD(&(link->waitq[0].link));
-    INIT_LIST_HEAD(&(link->waitq[1].link));
+    CFS_INIT_LIST_HEAD(&(link->waitq[0].link));
+    CFS_INIT_LIST_HEAD(&(link->waitq[1].link));
 
     link->waitq[0].waitl = link->waitq[1].waitl = link;
 }
@@ -124,7 +139,7 @@ void cfs_waitlink_fini(cfs_waitlink_t *link)
     cfs_assert(link->waitq[0].waitq == NULL);
     cfs_assert(link->waitq[1].waitq == NULL);
 
-    atomic_dec(&slot->count);
+    cfs_atomic_dec(&slot->count);
 }
 
 
@@ -154,15 +169,15 @@ void cfs_waitq_add_internal(cfs_waitq_t *waitq,
     LASSERT(link->magic == CFS_WAITLINK_MAGIC);
     LASSERT(waitqid < CFS_WAITQ_CHANNELS);
 
-    spin_lock(&(waitq->guard));
+    cfs_spin_lock(&(waitq->guard));
     LASSERT(link->waitq[waitqid].waitq == NULL);
     link->waitq[waitqid].waitq = waitq;
     if (link->flags & CFS_WAITQ_EXCLUSIVE) {
-        list_add_tail(&link->waitq[waitqid].link, &waitq->waiters);
+        cfs_list_add_tail(&link->waitq[waitqid].link, &waitq->waiters);
     } else {
-        list_add(&link->waitq[waitqid].link, &waitq->waiters);
+        cfs_list_add(&link->waitq[waitqid].link, &waitq->waiters);
     }
-    spin_unlock(&(waitq->guard));
+    cfs_spin_unlock(&(waitq->guard));
 }
 /*
  * cfs_waitq_add
@@ -214,27 +229,6 @@ void cfs_waitq_add_exclusive( cfs_waitq_t *waitq,
 }
 
 /*
- * cfs_waitq_forward
- *   To be determinated.
- *
- * Arguments:
- *   waitq:  pointer to the cfs_waitq_t structure
- *   link:  pointer to the cfs_waitlink_t structure
- *
- * Return Value:
- *   N/A
- *
- * Notes: 
- *   N/A
- */
-
-void cfs_waitq_forward( cfs_waitlink_t *link,
-                        cfs_waitq_t *waitq)
-{
-    cfs_waitq_add_internal(waitq, link, CFS_WAITQ_CHAN_FORWARD);
-}
-
-/*
  * cfs_waitq_del
  *   To remove the wait link node from the waitq
  *
@@ -260,7 +254,7 @@ void cfs_waitq_del( cfs_waitq_t *waitq,
     LASSERT(waitq->magic == CFS_WAITQ_MAGIC);
     LASSERT(link->magic == CFS_WAITLINK_MAGIC);
 
-    spin_lock(&(waitq->guard));
+    cfs_spin_lock(&(waitq->guard));
 
     for (i=0; i < CFS_WAITQ_CHANNELS; i++) {
         if (link->waitq[i].waitq == waitq)
@@ -269,12 +263,12 @@ void cfs_waitq_del( cfs_waitq_t *waitq,
 
     if (i < CFS_WAITQ_CHANNELS) {
         link->waitq[i].waitq = NULL;
-        list_del_init(&link->waitq[i].link);
+        cfs_list_del_init(&link->waitq[i].link);
     } else {
         cfs_enter_debugger();
     }
 
-    spin_unlock(&(waitq->guard));
+    cfs_spin_unlock(&(waitq->guard));
 }
 
 /*
@@ -325,9 +319,10 @@ void cfs_waitq_signal_nr(cfs_waitq_t *waitq, int nr)
     LASSERT(waitq != NULL);
     LASSERT(waitq->magic == CFS_WAITQ_MAGIC);
 
-    spin_lock(&waitq->guard);
-
-    list_for_each_entry(scan, &waitq->waiters, cfs_waitlink_channel_t, link) {
+    cfs_spin_lock(&waitq->guard);
+    cfs_list_for_each_entry_typed(scan, &waitq->waiters, 
+                            cfs_waitlink_channel_t,
+                            link) {
 
         cfs_waitlink_t *waitl = scan->waitl;
 
@@ -335,14 +330,14 @@ void cfs_waitq_signal_nr(cfs_waitq_t *waitq, int nr)
         LASSERT( result == FALSE || result == TRUE );
 
         if (result) {
-            atomic_inc(waitl->hits);
+            cfs_atomic_inc(waitl->hits);
         }
 
         if ((waitl->flags & CFS_WAITQ_EXCLUSIVE) && --nr == 0)
             break;
     }
 
-    spin_unlock(&waitq->guard);
+    cfs_spin_unlock(&waitq->guard);
     return;
 }
 
@@ -407,11 +402,11 @@ void cfs_waitq_wait(cfs_waitlink_t *link, cfs_task_state_t state)
     LASSERT(link != NULL);
     LASSERT(link->magic == CFS_WAITLINK_MAGIC);
 
-    if (atomic_read(link->hits) > 0) {
-        atomic_dec(link->hits);
-        LASSERT((__u32)atomic_read(link->hits) < (__u32)0xFFFFFF00);
+    if (cfs_atomic_read(link->hits) > 0) {
+        cfs_atomic_dec(link->hits);
+        LASSERT((__u32)cfs_atomic_read(link->hits) < (__u32)0xFFFFFF00);
     } else {
-        cfs_wait_event(link->event, 0);
+        cfs_wait_event_internal(link->event, 0);
     }
 }
 
@@ -432,18 +427,16 @@ void cfs_waitq_wait(cfs_waitlink_t *link, cfs_task_state_t state)
  *   What if it happens to be woken up at the just timeout time !?
  */
 
-cfs_duration_t cfs_waitq_timedwait( cfs_waitlink_t *link,
-                                    cfs_task_state_t state,
-                                    cfs_duration_t timeout)
+int64_t cfs_waitq_timedwait( cfs_waitlink_t *link,
+                             cfs_task_state_t state,
+                             int64_t timeout)
 { 
 
-    if (atomic_read(link->hits) > 0) {
-        atomic_dec(link->hits);
-        LASSERT((__u32)atomic_read(link->hits) < (__u32)0xFFFFFF00);
-        return TRUE;
+    if (cfs_atomic_read(link->hits) > 0) {
+        cfs_atomic_dec(link->hits);
+        LASSERT((__u32)cfs_atomic_read(link->hits) < (__u32)0xFFFFFF00);
+        return (int64_t)TRUE;
     }
 
-    return (cfs_duration_t)cfs_wait_event(link->event, timeout);
+    return (int64_t)cfs_wait_event_internal(link->event, timeout);
 }
-
-