From bd139e52b44f2a066e6908e1cf84a85e16aa502a Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 29 Apr 2011 08:27:11 +0000 Subject: [PATCH] * ntdll.h (IsEventSignalled): New inline function. * cygthread.cc (cygthread::terminate_thread): Use IsEventSignalled in place of WaitForSingleObject on event with 0 timeout. * fhandler.cc (fhandler_base_overlapped::has_ongoing_io): Ditto. * fhandler_fifo.cc (fhandler_fifo::open_nonserver): Ditto. (fhandler_fifo::wait): Ditto. * fhandler_termios.cc (fhandler_termios::bg_check): Ditto. * select.cc (verify_tty_slave): Ditto. * thread.cc (pthread::testcancel): Ditto. --- winsup/cygwin/ChangeLog | 12 ++++++++++++ winsup/cygwin/cygthread.cc | 5 +++-- winsup/cygwin/fhandler.cc | 2 +- winsup/cygwin/fhandler_fifo.cc | 5 +++-- winsup/cygwin/fhandler_termios.cc | 3 ++- winsup/cygwin/ntdll.h | 12 ++++++++++++ winsup/cygwin/select.cc | 2 +- winsup/cygwin/thread.cc | 3 ++- 8 files changed, 36 insertions(+), 8 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 53da07a9c..b12c76f0a 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,15 @@ +2011-04-29 Corinna Vinschen + + * ntdll.h (IsEventSignalled): New inline function. + * cygthread.cc (cygthread::terminate_thread): Use IsEventSignalled in + place of WaitForSingleObject on event with 0 timeout. + * fhandler.cc (fhandler_base_overlapped::has_ongoing_io): Ditto. + * fhandler_fifo.cc (fhandler_fifo::open_nonserver): Ditto. + (fhandler_fifo::wait): Ditto. + * fhandler_termios.cc (fhandler_termios::bg_check): Ditto. + * select.cc (verify_tty_slave): Ditto. + * thread.cc (pthread::testcancel): Ditto. + 2011-04-29 Corinna Vinschen * advapi32.cc (GetTokenInformation): Remove. diff --git a/winsup/cygwin/cygthread.cc b/winsup/cygwin/cygthread.cc index b59140ef9..ef8a4d575 100644 --- a/winsup/cygwin/cygthread.cc +++ b/winsup/cygwin/cygthread.cc @@ -1,7 +1,7 @@ /* cygthread.cc Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, - 2009 2010 Red Hat, Inc. + 2009, 2010, 2011 Red Hat, Inc. This software is a copyrighted work licensed under the terms of the Cygwin license. Please consult the file "CYGWIN_LICENSE" for @@ -12,6 +12,7 @@ details. */ #include #include "sigproc.h" #include "cygtls.h" +#include "ntdll.h" #undef CloseHandle @@ -298,7 +299,7 @@ cygthread::terminate_thread () if (!inuse || exiting) goto force_notterminated; - if (ev && !(terminated = WaitForSingleObject (ev, 0) != WAIT_OBJECT_0)) + if (ev && !(terminated = !IsEventSignalled (ev))) ResetEvent (ev); MEMORY_BASIC_INFORMATION m; diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 79c9a919e..e3fbcbd16 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -1716,7 +1716,7 @@ fhandler_base_overlapped::has_ongoing_io () { if (!io_pending) return false; - if (WaitForSingleObject (get_overlapped ()->hEvent, 0) != WAIT_OBJECT_0) + if (!IsEventSignalled (get_overlapped ()->hEvent)) { set_errno (EAGAIN); return true; diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index 9142947ed..35bc54dfe 100644 --- a/winsup/cygwin/fhandler_fifo.cc +++ b/winsup/cygwin/fhandler_fifo.cc @@ -21,6 +21,7 @@ #include "sigproc.h" #include "cygtls.h" #include "shared_info.h" +#include "ntdll.h" fhandler_fifo::fhandler_fifo (): fhandler_base_overlapped (), wait_state (fifo_unknown), dummy_client (NULL) @@ -48,7 +49,7 @@ fhandler_fifo::open_nonserver (const char *npname, unsigned low_flags, return h; if (&_my_tls != _main_tls) yield (); - else if (WaitForSingleObject (signal_arrived, 0) == WAIT_OBJECT_0) + else if (IsEventSignalled (signal_arrived)) { set_errno (EINTR); return NULL; @@ -224,7 +225,7 @@ fhandler_fifo::wait (bool iswrite) __seterrno (); return false; } - else if (WaitForSingleObject (signal_arrived, 0) != WAIT_OBJECT_0) + else if (!IsEventSignalled (signal_arrived)) continue; else if (_my_tls.call_signal_handler ()) continue; diff --git a/winsup/cygwin/fhandler_termios.cc b/winsup/cygwin/fhandler_termios.cc index 80131a796..37c4f4a96 100644 --- a/winsup/cygwin/fhandler_termios.cc +++ b/winsup/cygwin/fhandler_termios.cc @@ -19,6 +19,7 @@ details. */ #include "pinfo.h" #include "tty.h" #include "cygtls.h" +#include "ntdll.h" /* Common functions shared by tty/console */ @@ -175,7 +176,7 @@ fhandler_termios::bg_check (int sig) /* Don't raise a SIGTT* signal if we have already been interrupted by another signal. */ - if (WaitForSingleObject (signal_arrived, 0) != WAIT_OBJECT_0) + if (!IsEventSignalled (signal_arrived)) { siginfo_t si = {0}; si.si_signo = sig; diff --git a/winsup/cygwin/ntdll.h b/winsup/cygwin/ntdll.h index e9ff11bf0..b420f02d5 100644 --- a/winsup/cygwin/ntdll.h +++ b/winsup/cygwin/ntdll.h @@ -1292,6 +1292,18 @@ extern "C" fbi.FileAttributes = attr ?: FILE_ATTRIBUTE_NORMAL; return NtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation); } + + /* This test for a signalled event is twice as fast as calling + WaitForSingleObject (event, 0). */ + inline + BOOL NTAPI IsEventSignalled (HANDLE event) + { + EVENT_BASIC_INFORMATION ebi; + return NT_SUCCESS (NtQueryEvent (event, EventBasicInformation, + &ebi, sizeof ebi, NULL)) + && ebi.SignalState != 0; + + } } #endif #endif /*_NTDLL_H*/ diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index eb1728f51..962709605 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -934,7 +934,7 @@ static int verify_tty_slave (select_record *me, fd_set *readfds, fd_set *writefds, fd_set *exceptfds) { - if (WaitForSingleObject (me->h, 0) == WAIT_OBJECT_0) + if (IsEventSignalled (me->h)) me->read_ready = true; return set_bits (me, readfds, writefds, exceptfds); } diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 2bd50658c..1eab04d55 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -37,6 +37,7 @@ details. */ #include "fhandler.h" #include "dtable.h" #include "cygheap.h" +#include "ntdll.h" extern "C" void __fp_lock_all (); extern "C" void __fp_unlock_all (); @@ -742,7 +743,7 @@ pthread::testcancel () if (cancelstate == PTHREAD_CANCEL_DISABLE) return; - if (WaitForSingleObject (cancel_event, 0) == WAIT_OBJECT_0) + if (IsEventSignalled (cancel_event)) cancel_self (); }