Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Sep 2000 19:36:02 -0700
From:      Alfred Perlstein <bright@wintelcom.net>
To:        arch@freebsd.org
Subject:   Interruptable mutex aquires.
Message-ID:  <20000910193602.B12231@fw.wintelcom.net>

next in thread | raw e-mail | index | archive | help

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000910193602.B12231>