[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] /srv/bzr/emacs/emacs-24 r110867: Clean up w32 timer thread
From: |
Eli Zaretskii |
Subject: |
[Emacs-diffs] /srv/bzr/emacs/emacs-24 r110867: Clean up w32 timer thread code in the hope of solving bug #12832. |
Date: |
Wed, 14 Nov 2012 18:41:43 +0200 |
User-agent: |
Bazaar (2.5.0) |
------------------------------------------------------------
revno: 110867
fixes bug: http://debbugs.gnu.org/12832
committer: Eli Zaretskii <address@hidden>
branch nick: emacs-24
timestamp: Wed 2012-11-14 18:41:43 +0200
message:
Clean up w32 timer thread code in the hope of solving bug #12832.
src/w32proc.c (timer_loop): Make sure SuspendThread and ResumeThread
use the same value of thread handle.
(start_timer_thread): If the timer thread exited (due to error),
clean up by closing the two handles it used. Duplicate the caller
thread's handle here, so it gets duplicated only once, when
launching the timer thread. Set priority of the timer thread, not
the caller thread.
(getitimer): Don't duplicate the caller thread's handle here.
modified:
src/ChangeLog
src/w32proc.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog 2012-11-13 07:56:15 +0000
+++ b/src/ChangeLog 2012-11-14 16:41:43 +0000
@@ -1,3 +1,15 @@
+2012-11-14 Eli Zaretskii <address@hidden>
+
+ * w32proc.c (timer_loop): Make sure SuspendThread and ResumeThread
+ use the same value of thread handle.
+ (start_timer_thread): If the timer thread exited (due to error),
+ clean up by closing the two handles it used. Duplicate the caller
+ thread's handle here, so it gets duplicated only once, when
+ launching the timer thread. Set priority of the timer thread, not
+ the caller thread.
+ (getitimer): Don't duplicate the caller thread's handle here.
+ (Bug#12832)
+
2012-11-13 Jan Djärv <address@hidden>
* nsterm.m (hold_event): Send SIGIO to make sure ns_read_socket is
=== modified file 'src/w32proc.c'
--- a/src/w32proc.c 2012-11-01 14:21:45 +0000
+++ b/src/w32proc.c 2012-11-14 16:41:43 +0000
@@ -425,13 +425,14 @@
/* Simulate a signal delivered to the thread which installed
the timer, by suspending that thread while the handler
runs. */
- DWORD result = SuspendThread (itimer->caller_thread);
+ HANDLE th = itimer->caller_thread;
+ DWORD result = SuspendThread (th);
if (result == (DWORD)-1)
return 2;
handler (sig);
- ResumeThread (itimer->caller_thread);
+ ResumeThread (th);
}
/* Update expiration time and loop. */
@@ -556,6 +557,7 @@
start_timer_thread (int which)
{
DWORD exit_code;
+ HANDLE th;
struct itimer_data *itimer =
(which == ITIMER_REAL) ? &real_itimer : &prof_itimer;
@@ -564,9 +566,29 @@
&& exit_code == STILL_ACTIVE)
return 0;
+ /* Clean up after possibly exited thread. */
+ if (itimer->timer_thread)
+ {
+ CloseHandle (itimer->timer_thread);
+ itimer->timer_thread = NULL;
+ }
+ if (itimer->caller_thread)
+ {
+ CloseHandle (itimer->caller_thread);
+ itimer->caller_thread = NULL;
+ }
+
/* Start a new thread. */
+ if (!DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
+ GetCurrentProcess (), &th, 0, FALSE,
+ DUPLICATE_SAME_ACCESS))
+ {
+ errno = ESRCH;
+ return -1;
+ }
itimer->terminate = 0;
itimer->type = which;
+ itimer->caller_thread = th;
/* Request that no more than 64KB of stack be reserved for this
thread, to avoid reserving too much memory, which would get in
the way of threads we start to wait for subprocesses. See also
@@ -585,7 +607,7 @@
/* This is needed to make sure that the timer thread running for
profiling gets CPU as soon as the Sleep call terminates. */
if (which == ITIMER_PROF)
- SetThreadPriority (itimer->caller_thread, THREAD_PRIORITY_TIME_CRITICAL);
+ SetThreadPriority (itimer->timer_thread, THREAD_PRIORITY_TIME_CRITICAL);
return 0;
}
@@ -620,17 +642,9 @@
itimer = (which == ITIMER_REAL) ? &real_itimer : &prof_itimer;
- if (!DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
- GetCurrentProcess (), &itimer->caller_thread, 0,
- FALSE, DUPLICATE_SAME_ACCESS))
- {
- errno = ESRCH;
- return -1;
- }
-
ticks_now = w32_get_timer_time ((which == ITIMER_REAL)
? NULL
- : itimer->caller_thread);
+ : GetCurrentThread ());
t_expire = &itimer->expire;
t_reload = &itimer->reload;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] /srv/bzr/emacs/emacs-24 r110867: Clean up w32 timer thread code in the hope of solving bug #12832.,
Eli Zaretskii <=