summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thr_sigwait.c
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2003-07-09 14:30:51 +0000
committerdavidxu <davidxu@FreeBSD.org>2003-07-09 14:30:51 +0000
commitb14a2d89ea07034f41b853267f8f06d65fc33377 (patch)
treed2daeb2dd73fe7becbb0e19db3e0b8d877165b8a /lib/libpthread/thread/thr_sigwait.c
parentbeedaf29a12e8ffafdcd93268ebb750b3b44d254 (diff)
downloadFreeBSD-src-b14a2d89ea07034f41b853267f8f06d65fc33377.zip
FreeBSD-src-b14a2d89ea07034f41b853267f8f06d65fc33377.tar.gz
POSIX says if a thread is in sigwait state, although a signal may not in
its waitset, but if the signal is not masked by the thread, the signal can interrupt the thread and signal action can be invoked by the thread, sigwait should return with errno set to EINTR. Also save and restore thread internal state(timeout and interrupted) around signal handler invoking.
Diffstat (limited to 'lib/libpthread/thread/thr_sigwait.c')
-rw-r--r--lib/libpthread/thread/thr_sigwait.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/libpthread/thread/thr_sigwait.c b/lib/libpthread/thread/thr_sigwait.c
index ac44972..46dac92 100644
--- a/lib/libpthread/thread/thr_sigwait.c
+++ b/lib/libpthread/thread/thr_sigwait.c
@@ -123,6 +123,7 @@ lib_sigtimedwait(const sigset_t *set, siginfo_t *info,
}
}
curthread->timeout = 0;
+ curthread->interrupted = 0;
_thr_set_timeout(timeout);
/* Wait for a signal: */
curthread->oldsigmask = curthread->sigmask;
@@ -134,18 +135,18 @@ lib_sigtimedwait(const sigset_t *set, siginfo_t *info,
_thr_sched_switch_unlocked(curthread);
/*
* Return the signal number to the caller:
- * XXX Here is race, how about a signal come in before
- * we reach here? so we might got an incorrect timeout
- * status.
*/
if (siginfo.si_signo > 0) {
ret = siginfo.si_signo;
} else {
- if (curthread->timeout)
+ if (curthread->interrupted)
+ errno = EINTR;
+ else if (curthread->timeout)
errno = EAGAIN;
ret = -1;
}
-
+ curthread->timeout = 0;
+ curthread->interrupted = 0;
/*
* Probably unnecessary, but since it's in a union struct
* we don't know how it could be used in the future.
OpenPOWER on IntegriCloud