1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 # define DEBUG_SUBSYSTEM S_LNET
40 #include <libcfs/libcfs.h>
45 void __declspec (naked) FASTCALL
52 // EDX = v ; [EDX][0] = v->counter
55 lock add dword ptr [edx][0], ecx
60 void __declspec (naked) FASTCALL
67 // EDX = v ; [EDX][0] = v->counter
70 lock sub dword ptr [edx][0], ecx
75 void __declspec (naked) FASTCALL
80 //InterlockedIncrement((PULONG)(&((v)->counter)));
82 //` ECX = v ; [ECX][0] = v->counter
85 lock inc dword ptr [ecx][0]
90 void __declspec (naked) FASTCALL
95 // ECX = v ; [ECX][0] = v->counter
98 lock dec dword ptr [ecx][0]
103 int __declspec (naked) FASTCALL
111 // EDX = v ; [EDX][0] = v->counter
115 lock sub dword ptr [edx][0], ecx
121 int __declspec (naked) FASTCALL
126 // ECX = v ; [ECX][0] = v->counter
130 lock inc dword ptr [ecx][0]
136 int __declspec (naked) FASTCALL
141 // ECX = v ; [ECX][0] = v->counter
145 lock dec dword ptr [ecx][0]
159 InterlockedExchangeAdd( (PULONG)(&((v)->counter)) , (LONG) (i));
168 InterlockedExchangeAdd( (PULONG)(&((v)->counter)) , (LONG) (-1*i));
176 InterlockedIncrement((PULONG)(&((v)->counter)));
184 InterlockedDecrement((PULONG)(&((v)->counter)));
197 counter = v->counter;
198 result = counter - i;
200 } while ( InterlockedCompareExchange(
203 counter) != counter);
205 return (result == 0);
217 counter = v->counter;
218 result = counter + 1;
220 } while ( InterlockedCompareExchange(
223 counter) != counter);
225 return (result == 0);
237 counter = v->counter;
238 result = counter + 1;
240 } while ( InterlockedCompareExchange(
243 counter) != counter);
245 return (result == 0);
257 rwlock_init(rwlock_t * rwlock)
259 spin_lock_init(&rwlock->guard);
264 rwlock_fini(rwlock_t * rwlock)
269 read_lock(rwlock_t * rwlock)
271 cfs_task_t * task = cfs_current();
272 PTASK_SLOT slot = NULL;
275 /* should bugchk here */
276 cfs_enter_debugger();
280 slot = CONTAINING_RECORD(task, TASK_SLOT, task);
281 ASSERT(slot->Magic == TASKSLT_MAGIC);
283 slot->irql = KeRaiseIrqlToDpcLevel();
286 spin_lock(&rwlock->guard);
287 if (rwlock->count >= 0)
289 spin_unlock(&rwlock->guard);
293 spin_unlock(&rwlock->guard);
297 read_unlock(rwlock_t * rwlock)
299 cfs_task_t * task = cfs_current();
300 PTASK_SLOT slot = NULL;
303 /* should bugchk here */
304 cfs_enter_debugger();
308 slot = CONTAINING_RECORD(task, TASK_SLOT, task);
309 ASSERT(slot->Magic == TASKSLT_MAGIC);
311 spin_lock(&rwlock->guard);
312 ASSERT(rwlock->count > 0);
315 cfs_enter_debugger();
317 spin_unlock(&rwlock->guard);
319 KeLowerIrql(slot->irql);
323 write_lock(rwlock_t * rwlock)
325 cfs_task_t * task = cfs_current();
326 PTASK_SLOT slot = NULL;
329 /* should bugchk here */
330 cfs_enter_debugger();
334 slot = CONTAINING_RECORD(task, TASK_SLOT, task);
335 ASSERT(slot->Magic == TASKSLT_MAGIC);
337 slot->irql = KeRaiseIrqlToDpcLevel();
340 spin_lock(&rwlock->guard);
341 if (rwlock->count == 0)
343 spin_unlock(&rwlock->guard);
347 spin_unlock(&rwlock->guard);
351 write_unlock(rwlock_t * rwlock)
353 cfs_task_t * task = cfs_current();
354 PTASK_SLOT slot = NULL;
357 /* should bugchk here */
358 cfs_enter_debugger();
362 slot = CONTAINING_RECORD(task, TASK_SLOT, task);
363 ASSERT(slot->Magic == TASKSLT_MAGIC);
365 spin_lock(&rwlock->guard);
366 ASSERT(rwlock->count == -1);
368 spin_unlock(&rwlock->guard);
370 KeLowerIrql(slot->irql);