Subject: CVS commit: [wrstuden-fixsa] src/lib/libpthread
To: None <source-changes@NetBSD.org>
From: Bill Stouder-Studenmund <wrstuden@netbsd.org>
List: source-changes
Date: 09/10/2007 05:24:55
Module Name:	src
Committed By:	wrstuden
Date:		Mon Sep 10 05:24:55 UTC 2007

Modified Files:
	src/lib/libpthread [wrstuden-fixsa]: pthread.c pthread_barrier.c
	    pthread_cond.c pthread_int.h pthread_mutex.c pthread_run.c
	    pthread_rwlock.c pthread_sa.c pthread_sig.c pthread_sleep.c sem.c

Log Message:
Check in first step towards having pthread_kill() kill a thread running
on another CPU.

This change adds initial support for deferred signal handling. Just before
we go to sleep and while we hold &self->pt_statelock, check to see if we
have any deferred signals (blocked signals) pending. These are signals
that are not masked in our mask and which have been sent to us. We
were running when they came in. Further, since they are being handled
this way, there's a signal handler defined for them.

So unlock, run the signal handler(s), then carry on.

For condition variables, we consider this a spurious wakeup, so we just
return 0, having not unlocked the mutex. We run the handler with
the mutex held. This shouldn't matter, as you aren't supposed to play
with mutexes in signal handlers. :-)

For nanosleep(), we just process signals, then go to sleep.

For all other cases, we are in a loop with some external predicate. So
we process the signal then roll around the loop to see if it still applies.

In sched_yield(), spin until all deferred signals are gone. Since we hold
self->pt_statelock and that lock has to be held before sending a deferred
signal, no new deferred signals will come in until we're asleep.

While here, be more careful about locking while changing pt_state
to PT_STATE_RUNNING. Grab pt_statelock while doing it, and also set
next->pt_vpid to self->pt_vpid holding the same lock. Will make
the test to determine how to deliver a signal work right (since
a thread's vpid will soon matter in the general case). No longer
set next->pt_vpid in pthread__next().


To generate a diff of this commit:
cvs rdiff -r1.48 -r1.48.6.1 src/lib/libpthread/pthread.c
cvs rdiff -r1.6 -r1.6.18.1 src/lib/libpthread/pthread_barrier.c
cvs rdiff -r1.18 -r1.18.12.1 src/lib/libpthread/pthread_cond.c \
    src/lib/libpthread/pthread_run.c
cvs rdiff -r1.34 -r1.34.4.1 src/lib/libpthread/pthread_int.h
cvs rdiff -r1.22 -r1.22.4.1 src/lib/libpthread/pthread_mutex.c
cvs rdiff -r1.13 -r1.13.6.1 src/lib/libpthread/pthread_rwlock.c
cvs rdiff -r1.37 -r1.37.6.1 src/lib/libpthread/pthread_sa.c
cvs rdiff -r1.47 -r1.47.4.1 src/lib/libpthread/pthread_sig.c
cvs rdiff -r1.7 -r1.7.6.1 src/lib/libpthread/pthread_sleep.c
cvs rdiff -r1.9 -r1.9.6.1 src/lib/libpthread/sem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.