Update.
[glibc/history.git] / linuxthreads / restart.h
blob4b4a1d79378849f160ec4996772b9f42f5654f02
1 /* Linuxthreads - a simple clone()-based implementation of Posix */
2 /* threads for Linux. */
3 /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */
4 /* */
5 /* This program is free software; you can redistribute it and/or */
6 /* modify it under the terms of the GNU Library General Public License */
7 /* as published by the Free Software Foundation; either version 2 */
8 /* of the License, or (at your option) any later version. */
9 /* */
10 /* This program is distributed in the hope that it will be useful, */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13 /* GNU Library General Public License for more details. */
15 #include <signal.h>
17 /* Primitives for controlling thread execution */
19 static inline void restart(pthread_descr th)
21 kill(th->p_pid, PTHREAD_SIG_RESTART);
24 static inline void suspend(pthread_descr self)
26 sigset_t mask;
28 sigprocmask(SIG_SETMASK, NULL, &mask); /* Get current signal mask */
29 sigdelset(&mask, PTHREAD_SIG_RESTART); /* Unblock the restart signal */
30 do {
31 self->p_signal = 0;
32 sigsuspend(&mask); /* Wait for signal */
33 } while (self->p_signal != PTHREAD_SIG_RESTART);
36 static inline void suspend_with_cancellation(pthread_descr self)
38 sigset_t mask;
39 sigjmp_buf jmpbuf;
41 sigprocmask(SIG_SETMASK, NULL, &mask); /* Get current signal mask */
42 sigdelset(&mask, PTHREAD_SIG_RESTART); /* Unblock the restart signal */
43 /* No need to save the signal mask, we'll restore it ourselves */
44 if (sigsetjmp(jmpbuf, 0) == 0) {
45 self->p_cancel_jmp = &jmpbuf;
46 if (! (self->p_canceled && self->p_cancelstate == PTHREAD_CANCEL_ENABLE)) {
47 do {
48 self->p_signal = 0;
49 sigsuspend(&mask); /* Wait for a signal */
50 } while (self->p_signal != PTHREAD_SIG_RESTART);
52 self->p_cancel_jmp = NULL;
53 } else {
54 sigaddset(&mask, PTHREAD_SIG_RESTART); /* Reblock the restart signal */
55 sigprocmask(SIG_SETMASK, &mask, NULL);