From owner-cvs-src@FreeBSD.ORG Fri Jan 27 23:13:26 2006 Return-Path: X-Original-To: cvs-src@FreeBSD.org Delivered-To: cvs-src@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E280116A420; Fri, 27 Jan 2006 23:13:26 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 61BE043D46; Fri, 27 Jan 2006 23:13:26 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k0RNDQF7064748; Fri, 27 Jan 2006 23:13:26 GMT (envelope-from jhb@repoman.freebsd.org) Received: (from jhb@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k0RNDQHI064747; Fri, 27 Jan 2006 23:13:26 GMT (envelope-from jhb) Message-Id: <200601272313.k0RNDQHI064747@repoman.freebsd.org> From: John Baldwin Date: Fri, 27 Jan 2006 23:13:26 +0000 (UTC) To: src-committers@FreeBSD.org, cvs-src@FreeBSD.org, cvs-all@FreeBSD.org X-FreeBSD-CVS-Branch: HEAD Cc: Subject: cvs commit: src/sys/conf files options src/sys/kern kern_rwlock.c subr_lock.c src/sys/sys lock.h rwlock.h X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Jan 2006 23:13:27 -0000 jhb 2006-01-27 23:13:26 UTC FreeBSD src repository Modified files: sys/conf files options sys/kern subr_lock.c sys/sys lock.h Added files: sys/kern kern_rwlock.c sys/sys rwlock.h Log: 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.) Revision Changes Path 1.1087 +1 -0 src/sys/conf/files 1.525 +1 -0 src/sys/conf/options 1.1 +587 -0 src/sys/kern/kern_rwlock.c (new) 1.4 +1 -0 src/sys/kern/subr_lock.c 1.58 +1 -0 src/sys/sys/lock.h 1.1 +192 -0 src/sys/sys/rwlock.h (new)