Commit f0e5f225 authored by Eli Zaretskii's avatar Eli Zaretskii

Fix termination sequence on Windows wrt interval timers.

 src/w32proc.c <disable_itimers>: New static flag.
 (init_timers): Initialize it to zero, after creating the critical
 sections used by the timer threads.
 (term_timers): Set to 1 before deleting the critical sections.
 (getitimer, setitimer): If disable_itimers is non-zero, return an
 error indication without doing anything.  Reported by Fabrice
 Popineau <fabrice.popineau@supelec.fr> as part of bug#12544.
parent b3a4c387
2012-10-01 Eli Zaretskii <eliz@gnu.org>
* w32proc.c <disable_itimers>: New static flag.
(init_timers): Initialize it to zero, after creating the critical
sections used by the timer threads.
(term_timers): Set to 1 before deleting the critical sections.
(getitimer, setitimer): If disable_itimers is non-zero, return an
error indication without doing anything. Reported by Fabrice
Popineau <fabrice.popineau@supelec.fr> as part of bug#12544.
* emacs.c (shut_down_emacs) [WINDOWSNT]: Move the call to
term_ntproc after all the other bookkeeping, to get timers working
as long as possible.
2012-10-01 Paul Eggert <eggert@cs.ucla.edu> 2012-10-01 Paul Eggert <eggert@cs.ucla.edu>
* xdisp.c (syms_of_xdisp): Default message-log-max to 1000, not 100. * xdisp.c (syms_of_xdisp): Default message-log-max to 1000, not 100.
......
...@@ -1912,10 +1912,6 @@ shut_down_emacs (int sig, Lisp_Object stuff) ...@@ -1912,10 +1912,6 @@ shut_down_emacs (int sig, Lisp_Object stuff)
unrequest_sigio (); unrequest_sigio ();
ignore_sigio (); ignore_sigio ();
#ifdef WINDOWSNT
term_ntproc (0);
#endif
/* Do this only if terminating normally, we want glyph matrices /* Do this only if terminating normally, we want glyph matrices
etc. in a core dump. */ etc. in a core dump. */
if (sig == 0 || sig == SIGTERM) if (sig == 0 || sig == SIGTERM)
...@@ -1935,6 +1931,10 @@ shut_down_emacs (int sig, Lisp_Object stuff) ...@@ -1935,6 +1931,10 @@ shut_down_emacs (int sig, Lisp_Object stuff)
#ifdef HAVE_LIBXML2 #ifdef HAVE_LIBXML2
xml_cleanup_parser (); xml_cleanup_parser ();
#endif #endif
#ifdef WINDOWSNT
term_ntproc (0);
#endif
} }
......
...@@ -272,6 +272,9 @@ struct itimer_data { ...@@ -272,6 +272,9 @@ struct itimer_data {
static clock_t ticks_now; static clock_t ticks_now;
static struct itimer_data real_itimer, prof_itimer; static struct itimer_data real_itimer, prof_itimer;
static clock_t clocks_min; static clock_t clocks_min;
/* If non-zero, itimers are disabled. Used during shutdown, when we
delete the critical sections used by the timer threads. */
static int disable_itimers;
static CRITICAL_SECTION crit_real, crit_prof; static CRITICAL_SECTION crit_real, crit_prof;
...@@ -448,6 +451,10 @@ term_timers (void) ...@@ -448,6 +451,10 @@ term_timers (void)
if (prof_itimer.timer_thread) if (prof_itimer.timer_thread)
stop_timer_thread (ITIMER_PROF); stop_timer_thread (ITIMER_PROF);
/* We are going to delete the critical sections, so timers cannot
work after this. */
disable_itimers = 1;
DeleteCriticalSection (&crit_real); DeleteCriticalSection (&crit_real);
DeleteCriticalSection (&crit_prof); DeleteCriticalSection (&crit_prof);
DeleteCriticalSection (&crit_sig); DeleteCriticalSection (&crit_sig);
...@@ -465,6 +472,8 @@ init_timers (void) ...@@ -465,6 +472,8 @@ init_timers (void)
InitializeCriticalSection (&crit_real); InitializeCriticalSection (&crit_real);
InitializeCriticalSection (&crit_prof); InitializeCriticalSection (&crit_prof);
InitializeCriticalSection (&crit_sig); InitializeCriticalSection (&crit_sig);
disable_itimers = 0;
} }
static int static int
...@@ -525,6 +534,9 @@ getitimer (int which, struct itimerval *value) ...@@ -525,6 +534,9 @@ getitimer (int which, struct itimerval *value)
__int64 usecs; __int64 usecs;
CRITICAL_SECTION *crit; CRITICAL_SECTION *crit;
if (disable_itimers)
return -1;
ticks_now = clock (); ticks_now = clock ();
if (!value) if (!value)
...@@ -569,6 +581,9 @@ setitimer(int which, struct itimerval *value, struct itimerval *ovalue) ...@@ -569,6 +581,9 @@ setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
__int64 usecs; __int64 usecs;
CRITICAL_SECTION *crit; CRITICAL_SECTION *crit;
if (disable_itimers)
return -1;
/* Posix systems expect timer values smaller than the resolution of /* Posix systems expect timer values smaller than the resolution of
the system clock be rounded up to the clock resolution. First the system clock be rounded up to the clock resolution. First
time we are called, measure the clock tick resolution. */ time we are called, measure the clock tick resolution. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment