OSDN Git Service

* ntdll.h (IsEventSignalled): New inline function.
authorcorinna <corinna>
Fri, 29 Apr 2011 08:27:09 +0000 (08:27 +0000)
committercorinna <corinna>
Fri, 29 Apr 2011 08:27:09 +0000 (08:27 +0000)
* 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
winsup/cygwin/cygthread.cc
winsup/cygwin/fhandler.cc
winsup/cygwin/fhandler_fifo.cc
winsup/cygwin/fhandler_termios.cc
winsup/cygwin/ntdll.h
winsup/cygwin/select.cc
winsup/cygwin/thread.cc

index 53da07a..b12c76f 100644 (file)
@@ -1,5 +1,17 @@
 2011-04-29  Corinna Vinschen  <corinna@vinschen.de>
 
+       * 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  <corinna@vinschen.de>
+
        * advapi32.cc (GetTokenInformation): Remove.
        (SetTokenInformation): Remove.
        * grp.cc: Replace above functions throughout with their ntdll.dll
index b59140e..ef8a4d5 100644 (file)
@@ -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 <stdlib.h>
 #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;
index 79c9a91..e3fbcbd 100644 (file)
@@ -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;
index 9142947..35bc54d 100644 (file)
@@ -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;
index 80131a7..37c4f4a 100644 (file)
@@ -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;
index e9ff11b..b420f02 100644 (file)
@@ -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*/
index eb1728f..9627096 100644 (file)
@@ -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);
 }
index 2bd5065..1eab04d 100644 (file)
@@ -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 ();
 }