diff options
author | Niklas Hallqvist <niklas@cvs.openbsd.org> | 2005-05-27 20:47:00 +0000 |
---|---|---|
committer | Niklas Hallqvist <niklas@cvs.openbsd.org> | 2005-05-27 20:47:00 +0000 |
commit | 422d1a1e834f32d2a13e2c9c12a3da66839443a9 (patch) | |
tree | 9e1db68a889c9fc350cc91882589092dede88428 | |
parent | af1fbfa8d8dda608f563481f1fe1a013d472cceb (diff) |
add a __mp_lock_try implementation. ok art@
-rw-r--r-- | sys/sys/mplock.h | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/sys/sys/mplock.h b/sys/sys/mplock.h index 1df8d7ef5f4..cd816a8fc2d 100644 --- a/sys/sys/mplock.h +++ b/sys/sys/mplock.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mplock.h,v 1.5 2005/05/25 23:17:47 niklas Exp $ */ +/* $OpenBSD: mplock.h,v 1.6 2005/05/27 20:46:59 niklas Exp $ */ /* * Copyright (c) 2004 Niklas Hallqvist. All rights reserved. @@ -99,6 +99,28 @@ __mp_lock(struct __mp_lock *lock) splx(s); } +/* + * Try to acquire the lock, if another cpu has it, fill it in the + * call-by-reference cpu parameter. Return true if acquired. + */ +static __inline int +__mp_lock_try(struct __mp_lock *lock, cpuid_t *cpu) +{ + int s = spllock(); + + if (lock->mpl_cpu != cpu_number()) { + if (!__cpu_simple_lock_try(&lock->mpl_lock)) { + *cpu = lock->mpl_cpu; + splx(s); + return 0; + } + lock->mpl_cpu = cpu_number(); + } + lock->mpl_count++; + splx(s); + return 1; +} + static __inline void __mp_unlock(struct __mp_lock *lock) { |