Subject: Re: Is there any way to tell if the current thread has a user context?
To: Alan Ritter <rittera@cc.wwu.edu>
From: Matthew Orgass <darkstar@city-net.com>
List: tech-kern
Date: 09/06/2005 01:16:41
On 2005-08-31 rittera@cc.wwu.edu wrote:

> if(curlwp != NULL) {
>     lockmgr(&lock, LK_EXCLUSIVE, NULL);
> }

  This is wrong.  Locks need to be used everywhere you access the data
structure being protected.  Any data that will be accessed from an
interrupt must be protected by a simple_lock.  You also need to use
splfoo() and a simple lock to avoid your wake before sleep problem (see
the slock argument to ltsleep; the context switch will change the IPL then
restore it for you so you can use the PNORELOCK flag and splx after the
resume if you don't want the lock for anything else).

> but from running the kernel debugger it seems that sometimes while in my interrupt
> handler curlwp points to a "struct lwp" from a thread that was previously running.

  I thought it was always supposed to be NULL in interrupt context, but
looking at the code I don't see this set anywhere except the idle loop
and on process exit.  I guess it is just likely to be NULL at some point
if you are in an interrupt and useful only for diagnostic tests.  If this
is correct, it looks like dev/ic/awi.c is using it incorrectly.

Matthew Orgass
darkstar@city-net.com