From owner-freebsd-current Fri Jul 18 00:56:53 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id AAA07700 for current-outgoing; Fri, 18 Jul 1997 00:56:53 -0700 (PDT) Received: from lsd.relcom.eu.net (lsd.relcom.eu.net [193.124.23.23]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id AAA07689 for ; Fri, 18 Jul 1997 00:56:46 -0700 (PDT) Received: (from ache@localhost) by lsd.relcom.eu.net (8.8.6/8.8.5) id LAA26807; Fri, 18 Jul 1997 11:56:00 +0400 (MSD) Date: Fri, 18 Jul 1997 11:56:00 +0400 (MSD) From: =?KOI8-R?B?4c7E0sXKIP7F0s7P1w==?= X-Sender: ache@lsd.relcom.eu.net To: Peter Wemm cc: FreeBSD-current Subject: Re: sleep.c fix for review In-Reply-To: <199707180733.PAA13192@spinner.dialix.com.au> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-current@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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 http://www.nagual.pp.ru/~ache/