Subject: Re: New spl level: splsched()
To: Bill Sommerfeld <sommerfeld@orchard.east-arlington.ma.us>
From: Eduardo E. Horvath <eeh@one-o.com>
List: tech-kern
Date: 03/11/1997 09:23:58
On Thu, 6 Mar 1997, Bill Sommerfeld wrote:
> > #define mutex_init(m,s) (m).spl=(s)
> >
> > #define mutex_enter(m) (m).oldspl = splraise((m).spl)
> > #define mutex_exit(m) splx((m).oldspl)
> >
> > You will need to replace all the spl stuff with this. Then you can
> > start worrying about isolating critical sections that are not currently
> > protected due to our single-threaded kernel design.
>
> The problem with this implementation is that `oldspl' needs to be
> stuffed in a temporary variable with a scope covering the lock/unlock,
> not in a global variable..
>
> i.e., it's currently legal to do:
>
> x = splfoo();
> y = splfoo();
>
> splx(y);
> splx(x);
>
> Nesting your mutex_enter/mutex_exit, on the other hand, leave things
> locked on exit...
While you are correct, in most mutex implementations I am familliar with
it is illegal to attempt to acquire the same mutex more than once, so this
is not really an issue. So we make the following changes:
#define mutex_enter(m) \
do { \
if ((m).oldspl) \
panic("Recursive mutex enter"); \
(m).oldspl = splraise((m).spl); \
} while(0)
#define mutex_exit(m) \
do { \
int s = (m).oldspl; \
(m).oldspl = 0; \
splx(s); \
} while (0)
Then it'll behave just like Solaris 8^)
=========================================================================
Eduardo Horvath eeh@btr.com
"Cliffs are for climbing. That's why God invented grappling hooks."
- Benton Frasier