Date: Fri, 18 Jul 1997 10:19:57 +0400 (MSD) From: =?KOI8-R?B?4c7E0sXKIP7F0s7P1w==?= <ache@nagual.pp.ru> To: FreeBSD-current <current@freebsd.org> Subject: sleep.c fix for review Message-ID: <Pine.BSF.3.96.970718100424.239A-100000@nagual.pp.ru>
next in thread | raw e-mail | index | archive | help
Our current implementation do not enable ALARM handler, if it was disabled
previously. Since such case is very rare, there is no real optimization
occurse, but potential incompatibility: all other Unix sleep
implementations including GNU one enable ALARM handler in _any_ case.
This patch makes our sleep compatible with our previous code and the rest
of the world sleep codes.
*** sleep.c.bak Sun Jun 8 15:11:01 1997
--- sleep.c Tue Jul 15 00:57:59 1997
***************
*** 73,79 ****
struct timespec time_remaining;
struct sigaction act, oact;
sigset_t mask, omask;
- int alarm_blocked;
if (seconds != 0) {
time_to_sleep.tv_sec = seconds;
--- 73,78 ----
***************
*** 84,101 ****
sigaddset(&mask, SIGALRM);
sigprocmask(SIG_BLOCK, &mask, &omask);
! /* Was SIGALRM blocked already? */
! alarm_blocked = sigismember(&omask, SIGALRM);
!
! if (!alarm_blocked) {
! /*
! * Set up handler to interrupt signanosleep only if
! * SIGALRM was unblocked. (Save some syscalls)
! */
! memset(&act, 0, sizeof(act));
! act.sa_handler = sleephandler;
! sigaction(SIGALRM, &act, &oact);
! }
/*
* signanosleep() uses the given mask for the lifetime of
--- 83,95 ----
sigaddset(&mask, SIGALRM);
sigprocmask(SIG_BLOCK, &mask, &omask);
! /*
! * Set up handler to interrupt signanosleep only if
! * SIGALRM was unblocked. (Save some syscalls)
! */
! memset(&act, 0, sizeof(act));
! act.sa_handler = sleephandler;
! sigaction(SIGALRM, &act, &oact);
/*
* signanosleep() uses the given mask for the lifetime of
***************
*** 107,117 ****
*/
signanosleep(&time_to_sleep, &time_remaining, &omask);
! if (!alarm_blocked) {
! /* Unwind */
! sigaction(SIGALRM, &oact, (struct sigaction *)0);
! sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0);
! }
/* return how long is left */
seconds = time_remaining.tv_sec;
--- 101,109 ----
*/
signanosleep(&time_to_sleep, &time_remaining, &omask);
! /* Unwind */
! sigaction(SIGALRM, &oact, (struct sigaction *)0);
! sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0);
/* return how long is left */
seconds = time_remaining.tv_sec;
--
Andrey A. Chernov
<ache@null.net>
http://www.nagual.pp.ru/~ache/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.96.970718100424.239A-100000>
