1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=4:tabstop=4:
4 * Copyright (c) 2004 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or modify it under
9 * the terms of version 2 of the GNU General Public License as published by
10 * the Free Software Foundation. Lustre is distributed in the hope that it
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. You should have received a
14 * copy of the GNU General Public License along with Lustre; if not, write
15 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
20 # define DEBUG_SUBSYSTEM S_LNET
22 #include <libcfs/libcfs.h>
27 void __declspec (naked) FASTCALL
34 // EDX = v ; [EDX][0] = v->counter
37 lock add dword ptr [edx][0], ecx
42 void __declspec (naked) FASTCALL
49 // EDX = v ; [EDX][0] = v->counter
52 lock sub dword ptr [edx][0], ecx
57 void __declspec (naked) FASTCALL
62 //InterlockedIncrement((PULONG)(&((v)->counter)));
64 //` ECX = v ; [ECX][0] = v->counter
67 lock inc dword ptr [ecx][0]
72 void __declspec (naked) FASTCALL
77 // ECX = v ; [ECX][0] = v->counter
80 lock dec dword ptr [ecx][0]
85 int __declspec (naked) FASTCALL
93 // EDX = v ; [EDX][0] = v->counter
97 lock sub dword ptr [edx][0], ecx
103 int __declspec (naked) FASTCALL
108 // ECX = v ; [ECX][0] = v->counter
112 lock inc dword ptr [ecx][0]
118 int __declspec (naked) FASTCALL
123 // ECX = v ; [ECX][0] = v->counter
127 lock dec dword ptr [ecx][0]
141 InterlockedExchangeAdd( (PULONG)(&((v)->counter)) , (LONG) (i));
150 InterlockedExchangeAdd( (PULONG)(&((v)->counter)) , (LONG) (-1*i));
158 InterlockedIncrement((PULONG)(&((v)->counter)));
166 InterlockedDecrement((PULONG)(&((v)->counter)));
179 counter = v->counter;
180 result = counter - i;
182 } while ( InterlockedCompareExchange(
185 counter) != counter);
187 return (result == 0);
199 counter = v->counter;
200 result = counter + 1;
202 } while ( InterlockedCompareExchange(
205 counter) != counter);
207 return (result == 0);
219 counter = v->counter;
220 result = counter + 1;
222 } while ( InterlockedCompareExchange(
225 counter) != counter);
227 return (result == 0);
239 rwlock_init(rwlock_t * rwlock)
241 spin_lock_init(&rwlock->guard);
246 rwlock_fini(rwlock_t * rwlock)
251 read_lock(rwlock_t * rwlock)
253 cfs_task_t * task = cfs_current();
254 PTASK_SLOT slot = NULL;
257 /* should bugchk here */
258 cfs_enter_debugger();
262 slot = CONTAINING_RECORD(task, TASK_SLOT, task);
263 ASSERT(slot->Magic == TASKSLT_MAGIC);
265 slot->irql = KeRaiseIrqlToDpcLevel();
268 spin_lock(&rwlock->guard);
269 if (rwlock->count >= 0)
271 spin_unlock(&rwlock->guard);
275 spin_unlock(&rwlock->guard);
279 read_unlock(rwlock_t * rwlock)
281 cfs_task_t * task = cfs_current();
282 PTASK_SLOT slot = NULL;
285 /* should bugchk here */
286 cfs_enter_debugger();
290 slot = CONTAINING_RECORD(task, TASK_SLOT, task);
291 ASSERT(slot->Magic == TASKSLT_MAGIC);
293 spin_lock(&rwlock->guard);
294 ASSERT(rwlock->count > 0);
297 cfs_enter_debugger();
299 spin_unlock(&rwlock->guard);
301 KeLowerIrql(slot->irql);
305 write_lock(rwlock_t * rwlock)
307 cfs_task_t * task = cfs_current();
308 PTASK_SLOT slot = NULL;
311 /* should bugchk here */
312 cfs_enter_debugger();
316 slot = CONTAINING_RECORD(task, TASK_SLOT, task);
317 ASSERT(slot->Magic == TASKSLT_MAGIC);
319 slot->irql = KeRaiseIrqlToDpcLevel();
322 spin_lock(&rwlock->guard);
323 if (rwlock->count == 0)
325 spin_unlock(&rwlock->guard);
329 spin_unlock(&rwlock->guard);
333 write_unlock(rwlock_t * rwlock)
335 cfs_task_t * task = cfs_current();
336 PTASK_SLOT slot = NULL;
339 /* should bugchk here */
340 cfs_enter_debugger();
344 slot = CONTAINING_RECORD(task, TASK_SLOT, task);
345 ASSERT(slot->Magic == TASKSLT_MAGIC);
347 spin_lock(&rwlock->guard);
348 ASSERT(rwlock->count == -1);
350 spin_unlock(&rwlock->guard);
352 KeLowerIrql(slot->irql);