From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#32746: stop using obsolescent setitimer API Date: Mon, 17 Sep 2018 18:01:56 +0300 Message-ID: <83lg80gobf.fsf@gnu.org> References: <3c8e16a0-bae6-4ee7-d8e1-5da307ff6e84@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1537197083 12776 195.159.176.226 (17 Sep 2018 15:11:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 17 Sep 2018 15:11:23 +0000 (UTC) Cc: 32746@debbugs.gnu.org To: Paul Eggert Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Sep 17 17:11:18 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g1vBG-0003DQ-Cb for geb-bug-gnu-emacs@m.gmane.org; Mon, 17 Sep 2018 17:11:18 +0200 Original-Received: from localhost ([::1]:36064 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1vDM-0000LC-Nu for geb-bug-gnu-emacs@m.gmane.org; Mon, 17 Sep 2018 11:13:28 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1v3M-00089G-47 for bug-gnu-emacs@gnu.org; Mon, 17 Sep 2018 11:03:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g1v3G-0004NQ-2l for bug-gnu-emacs@gnu.org; Mon, 17 Sep 2018 11:03:08 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39005) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g1v3F-0004ND-Ue for bug-gnu-emacs@gnu.org; Mon, 17 Sep 2018 11:03:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1g1v3F-0006YG-Mw for bug-gnu-emacs@gnu.org; Mon, 17 Sep 2018 11:03:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 17 Sep 2018 15:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32746 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 32746-submit@debbugs.gnu.org id=B32746.153719654225128 (code B ref 32746); Mon, 17 Sep 2018 15:03:01 +0000 Original-Received: (at 32746) by debbugs.gnu.org; 17 Sep 2018 15:02:22 +0000 Original-Received: from localhost ([127.0.0.1]:43263 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g1v2b-0006XD-LM for submit@debbugs.gnu.org; Mon, 17 Sep 2018 11:02:21 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:33935) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g1v2Z-0006Wz-Ok for 32746@debbugs.gnu.org; Mon, 17 Sep 2018 11:02:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g1v2K-0007Eg-8W for 32746@debbugs.gnu.org; Mon, 17 Sep 2018 11:02:09 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:51624) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1v2G-0007D3-OO; Mon, 17 Sep 2018 11:02:02 -0400 Original-Received: from [176.228.60.248] (port=2495 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1g1v2G-0007sV-9f; Mon, 17 Sep 2018 11:02:00 -0400 In-reply-to: <3c8e16a0-bae6-4ee7-d8e1-5da307ff6e84@cs.ucla.edu> (message from Paul Eggert on Sun, 16 Sep 2018 13:19:45 -0700) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:150371 Archived-At: > From: Paul Eggert > Date: Sun, 16 Sep 2018 13:19:45 -0700 > > POSIX obsoleted the getitimer/setitimer API a decade ago, and now's a good time > for Emacs to stop using this obsolescent API, partly to simplify other timestamp > improvements that I have in mind, partly to head off any other lurking bugs like > the problem I just fixed in commit 238c7cd730819ddba2dbde3c46ee36136575695b > relating to a mistaken assumption about the old API. > > Attached please find two proposed patches. The first simplifies Emacs proper to > just use the current timer_gettime/timer_settime API instead (this is the > standard replacement for the obsolescent API). The second patch affects only the > MS-Windows code, modifying it to use the new API instead of the old one; I > haven't tested it as I don't use MS-Windows. Thanks, I have a couple of comments/questions about the MS-Windows changes (thanks for working on that): > +struct sigevent > { > - struct timeval it_interval; /* timer interval */ > - struct timeval it_value; /* current value */ > + int sigev_notify; > + int sigev_signo; > + union sigval sigev_value; > + void (*sigev_notify_function) (union sigval); > + pthread_attr_t *sigev_notify_attributes; I'd prefer not to use pthread_attr_t, as that could clash with some MinGW header. > +typedef enum { CLOCK_REALTIME, CLOCK_THREAD_CPUTIME_ID } clockid_t; Some versions of MinGW have clockid_t (for clock_gettime and clock_settime), so this might cause conflicts. > +#define CLOCK_REALTIME CLOCK_REALTIME > +#define CLOCK_THREAD_CPUTIME_ID CLOCK_THREAD_CPUTIME_ID Some of these are declared/defined in MinGW headers in some versions. > + HANDLE thread_hand; This seems to be unused, and is probably related to the other issues below. > - itimer = (which == ITIMER_REAL) ? &real_itimer : &prof_itimer; > + itimer = realtime ? &real_itimer : &prof_itimer; > > - ticks_now = w32_get_timer_time ((which == ITIMER_REAL) > + ticks_now = w32_get_timer_time (realtime > ? NULL > : GetCurrentThread ()); > > + itimer = realtime ? &real_itimer : &prof_itimer; > + > + ticks_now = w32_get_timer_time (thread_hand); This seems to do the same stuff twicer, using thread_hand that is uninitialized. > - expire = value->it_value.tv_sec * TIMER_TICKS_PER_SEC; > - usecs = value->it_value.tv_usec; > - if (value->it_value.tv_sec == 0 > - && usecs * TIMER_TICKS_PER_SEC < clocks_min * 1000000) > + expire = ex.tv_sec * TIMER_TICKS_PER_SEC; > + ns = ex.tv_nsec; > + if (ex.tv_sec == 0 > + && 0 < ns && ns < clocks_min * (1000000000 / TIMER_TICKS_PER_SEC)) > expire = clocks_min; This seems to use an undefined variable 'ex'. > - expire += ticks_now; > + if (flags & TIMER_ABSTIME) > + expire += ticks_now; I don't think I understand the reason for the condition you added. > +#ifdef HAVE_ITIMERSPEC If we will have a test for itimerspec, we will probably need to edit nt/mingw-cfg.site to keep the configure script happy. Thanks again for working on this.