path: root/sys/sys/lock.h
diff options
authorJohn Baldwin <jhb@FreeBSD.org>2006-01-27 23:13:26 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2006-01-27 23:13:26 +0000
commit3f08bd8bce954577e7bb023a30ac9c733bfc40b7 (patch)
tree8668cae30688a7758d1778375d322def630558d9 /sys/sys/lock.h
parent135161049e07ac66e6c63b458b5be4f6829efffd (diff)
Add a basic reader/writer lock implementation to the kernel. This
implementation is by no means perfect as far as some of the algorithms that it uses and the fact that it is missing some functionality (try locks and upgrades/downgrades are not there yet), however it does seem to work in my local testing. There is more detail in the comments in the code, but the short version follows. A reader/writer lock is very much like a regular mutex: it cannot be held across a voluntary sleep; it can be acquired in an interrupt thread; if the lock is held by a writer then the priority of any threads that block on the lock will be lent to the owner; the simple case lock operations all are done in a single atomic op. It also shares some similiarities with sx locks: it supports reader/writer semantics (multiple readers, but single writers); readers are allowed to recurse, but writers are not. We can extend this implementation further by either improving algorithms or adding new functionality, but this should at least give us a base to work with now. Reviewed by: arch (in theory) Tested on: i386 (4 cpu box with a kernel module that used 4 threads that randomly chose between read locks and write locks that ran w/o panicing for over a day solid. It usually panic'd within a few seconds when there were bugs during testing. :) The kernel module source is available on request.)
Notes: svn path=/head/; revision=154941
Diffstat (limited to 'sys/sys/lock.h')
1 files changed, 1 insertions, 0 deletions
diff --git a/sys/sys/lock.h b/sys/sys/lock.h
index 6fcb03312063..99a7e5d3f001 100644
--- a/sys/sys/lock.h
+++ b/sys/sys/lock.h
@@ -211,6 +211,7 @@ struct lock_list_entry {
extern struct lock_class lock_class_mtx_sleep;
extern struct lock_class lock_class_mtx_spin;
extern struct lock_class lock_class_sx;
+extern struct lock_class lock_class_rw;
extern struct lock_class *lock_classes[];