Date: Fri, 18 Jul 1997 11:56:00 +0400 (MSD) From: =?KOI8-R?B?4c7E0sXKIP7F0s7P1w==?= <ache@nagual.pp.ru> To: Peter Wemm <peter@spinner.dialix.com.au> Cc: FreeBSD-current <current@freebsd.org> Subject: Re: sleep.c fix for review Message-ID: <Pine.BSF.3.96.970718115254.26764A-100000@lsd.relcom.eu.net> In-Reply-To: <199707180733.PAA13192@spinner.dialix.com.au>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 18 Jul 1997, Peter Wemm wrote:
> As I read it, this doesn't actually change anything.. If the application
> has masked SIGALRM, unconditionally installing and removing the handler
> does nothing.. That's what the optimization does.. If SIGALRM is
> impossible, don't waste syscalls on something that will not happen.
You are right, I overlook it, here is new variant:
*** sleep.c.orig Fri Jun 6 00:30:02 1997
--- sleep.c Fri Jul 18 11:49:37 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,99 ----
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);
!
! /* Always enable SIGALRM to be compatible */
! mask = omask;
! sigdelset(&mask, SIGALRM);
/*
* signanosleep() uses the given mask for the lifetime of
***************
*** 105,117 ****
* to end the timout. If the process blocks SIGALRM, it
* gets what it asks for.
*/
! 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;
--- 103,113 ----
* to end the timout. If the process blocks SIGALRM, it
* gets what it asks for.
*/
! signanosleep(&time_to_sleep, &time_remaining, &mask);
! /* 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.970718115254.26764A-100000>
