Recent lwkt_token work broke UP builds. Fix the token code to operate
authorMatthew Dillon <dillon@dragonflybsd.org>
Fri, 19 May 2006 18:26:29 +0000 (18:26 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Fri, 19 May 2006 18:26:29 +0000 (18:26 +0000)
commitdd55d70747a2fb8e8781f200d63adc1f31c8af4a
treee14dd2b1eb28bae7fe85cf6053e1df938e15d4d1
parent228b401dc8841ecde6fe4b281e31686684b29a82
Recent lwkt_token work broke UP builds.  Fix the token code to operate
properly for both UP and SMP builds.  The SMP build uses spinlocks to
control access and also to do the preemption check.  The tokens are
explicitly obtained when a thread is switched in and released when a
thread is (non-preemptively) switched out.  Spinlocks cannot be
used for this purpose on UP because they are coded to a degenerate
case on a UP build.

On a UP build an explicit preemption check is needed, but no spinlock or
per-thread counter is required because the definition of a token is that
it is only 'held' while a thread is actually running or preempted.  So,
by definition, a token can always be obtained and held by a thread on UP
EXCEPT in the case where a preempting thread is trying to obtain a token
held by the preempted thread.

Conditionalize elements in the lwkt_token structure definition to guarentee
that SMP fields cannot be used in UP builds or vise-versa.  The lwkt_token
structure is made the same size for both builds.  Also remove some of
the degenerate spinlock functions (spin_trylock() and spin_tryunlock())
for UP builds to force a compile-time error if an attempt is made to use
them.  spin_lock*() and spin_unlock*() are retained as degenerate cases
on UP.

Reported-by: Sascha Wildner <saw@online.de>, walt <wa1ter@myrealbox.com>
sys/ddb/db_ps.c
sys/kern/lwkt_thread.c
sys/kern/lwkt_token.c
sys/sys/spinlock2.h
sys/sys/thread.h