From 1d2fc9b3c59d0e83e04139ddf633731264b76ea2 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 5 Jan 2000 02:09:12 +0000 Subject: Redesigned how cancellation unblocks a thread from internal cancellation points (sem_wait, pthread_join, pthread_cond_{wait,timedwait}). Cancellation won't eat a signal in any of these functions (*required* by POSIX and Single Unix Spec!). 2000-01-03 Kaz Kylheku Redesigned how cancellation unblocks a thread from internal cancellation points (sem_wait, pthread_join, pthread_cond_{wait,timedwait}). Cancellation won't eat a signal in any of these functions (*required* by POSIX and Single Unix Spec!). * condvar.c: spontaneous wakeup on pthread_cond_timedwait won't eat a simultaneous condition variable signal (not required by POSIX or Single Unix Spec, but nice). * spinlock.c: __pthread_lock queues back any received restarts that don't belong to it instead of assuming ownership of lock upon any restart; fastlock can no longer be acquired by two threads simultaneously. * restart.h: restarts queue even on kernels that don't have queued real time signals (2.0, early 2.1), thanks to atomic counter, avoiding a rare race condition in pthread_cond_timedwait. --- linuxthreads/restart.h | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) (limited to 'linuxthreads/restart.h') diff --git a/linuxthreads/restart.h b/linuxthreads/restart.h index 749201391d..702d7d15c6 100644 --- a/linuxthreads/restart.h +++ b/linuxthreads/restart.h @@ -18,41 +18,10 @@ static inline void restart(pthread_descr th) { - kill(th->p_pid, __pthread_sig_restart); + __pthread_restart(th); /* see pthread.c */ } static inline void suspend(pthread_descr self) { - sigset_t mask; - - sigprocmask(SIG_SETMASK, NULL, &mask); /* Get current signal mask */ - sigdelset(&mask, __pthread_sig_restart); /* Unblock the restart signal */ - do { - self->p_signal = 0; - sigsuspend(&mask); /* Wait for signal */ - } while (self->p_signal !=__pthread_sig_restart ); -} - -#define suspend_with_cancellation(self) \ -{ \ - sigset_t mask; \ - sigjmp_buf jmpbuf; \ - \ - sigprocmask(SIG_SETMASK, NULL, &mask); /* Get current signal mask */ \ - sigdelset(&mask, __pthread_sig_restart); /* Unblock the restart signal */ \ - /* No need to save the signal mask, we'll restore it ourselves */ \ - if (sigsetjmp(jmpbuf, 0) == 0) { \ - self->p_cancel_jmp = &jmpbuf; \ - if (! (self->p_canceled \ - && self->p_cancelstate == PTHREAD_CANCEL_ENABLE)) { \ - do { \ - self->p_signal = 0; \ - sigsuspend(&mask); /* Wait for a signal */ \ - } while (self->p_signal != __pthread_sig_restart); \ - } \ - self->p_cancel_jmp = NULL; \ - } else { \ - sigaddset(&mask, __pthread_sig_restart); /* Reblock the restart signal */ \ - sigprocmask(SIG_SETMASK, &mask, NULL); \ - } \ + __pthread_suspend(self); /* see pthread.c */ } -- cgit v1.2.3