From c402095aae0cc5bc6d059e0313bf0f59eaa106d8 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 3 May 2011 10:11:19 +0000 Subject: [PATCH] * fhandler.cc (fhandler_base_overlapped::wait_overlapped): Make cancelable. Remove test for main thread, always add signal_arrived to waited objects. --- winsup/cygwin/ChangeLog | 6 ++++++ winsup/cygwin/fhandler.cc | 11 ++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 0a5e7cbf7..330bd8131 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2011-05-03 Corinna Vinschen + + * fhandler.cc (fhandler_base_overlapped::wait_overlapped): Make + cancelable. Remove test for main thread, always add signal_arrived + to waited objects. + 2011-05-03 Corinna Vinschen * fhandler_tty.cc (fhandler_tty_slave::read): Set WFMO timeout to 0 for diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index e3fbcbd16..858be1088 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -1754,11 +1754,9 @@ fhandler_base_overlapped::wait_overlapped (bool inres, bool writing, DWORD *byte if (!get_overlapped ()->hEvent) system_printf ("hEvent is zero?"); #endif - DWORD n = 1; - HANDLE w4[2]; - w4[0] = get_overlapped ()->hEvent; - if (&_my_tls == _main_tls) - w4[n++] = signal_arrived; + HANDLE w4[3] = { get_overlapped ()->hEvent, signal_arrived, + pthread::get_cancel_event () }; + DWORD n = w4[2] ? 3 : 2; HANDLE h = writing ? get_output_handle () : get_handle (); DWORD wfres = WaitForMultipleObjects (n, w4, false, INFINITE); if (wfres != WAIT_OBJECT_0) @@ -1766,6 +1764,7 @@ fhandler_base_overlapped::wait_overlapped (bool inres, bool writing, DWORD *byte *bytes = 0; BOOL wores = GetOverlappedResult (h, get_overlapped (), bytes, false); bool signalled = !wores && (wfres == WAIT_OBJECT_0 + 1); + bool canceled = !wores && (wfres == WAIT_OBJECT_0 + 2); if (signalled) { debug_printf ("got a signal"); @@ -1779,6 +1778,8 @@ fhandler_base_overlapped::wait_overlapped (bool inres, bool writing, DWORD *byte *bytes = (DWORD) -1; err = 0; } + else if (canceled) + pthread::static_cancel_self (); else if (!wores) { err = GetLastError (); -- 2.43.5