From owner-freebsd-arch Sun Sep 10 19:36: 4 2000 Delivered-To: freebsd-arch@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id A2F0937B423 for ; Sun, 10 Sep 2000 19:36:02 -0700 (PDT) Received: (from bright@localhost) by fw.wintelcom.net (8.10.0/8.10.0) id e8B2a2F02199 for arch@freebsd.org; Sun, 10 Sep 2000 19:36:02 -0700 (PDT) Date: Sun, 10 Sep 2000 19:36:02 -0700 From: Alfred Perlstein To: arch@freebsd.org Subject: Interruptable mutex aquires. Message-ID: <20000910193602.B12231@fw.wintelcom.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.4i Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG There's a lot of code in the kernel that does this: while(lock != mine) { error = tsleep(&lock, PRIBIO, "foo", PCATCH); if (error) return(error); } lock = mine; Ok, well the equivelant way to do this with mutexes would be to add a new function 'mtx_enter_interruptable()' [*] that attempts to aquire a mutex but if interrupted returns an error suitable for aborting the operation. Nice, easy, simple and fits well as a replacement tool for the current while(lock != mine) mechnism. Some people have discussed making a new flag 'MTX_CATCH', personally that sounds terrible, I'm already not really thrilled with the 'do-all' functions that have been put into place as our primatives, as they are not very intuative, it's hard to tell at a glance exactly what is a spinlock and what is a task switching mutex, let's _please_ try to keep this readable and stick away from the flags. I also think that we don't really need the overhead of a return value if at all possible. At the BSDi/FreeBSD SMP meeting I remeber asking Chuck why he implemented it this way, his respnonse was something along the lines of "it seemed like a good idea to have an object that one could spin or sleep on depending on the locatation or state of the object encapsulating the mutex, but in practice we've never used nor needed to use a mutex as a spinlock or a spinlock as a mutex" [*] yes, today's C compilers actually support identifiers longer than 6 characters! if mtx_enter_interruptable is too offensive I could live with mtx_enter_intr(). thanks, -- -Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org] "I have the heart of a child; I keep it in a jar on my desk." To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message