* 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.
This commit is contained in:
Corinna Vinschen 2011-04-29 08:27:11 +00:00
parent 12eac211c9
commit bd139e52b4
8 changed files with 36 additions and 8 deletions

View File

@ -1,3 +1,15 @@
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.

View 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;

View 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;

View 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;

View 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;

View 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*/

View 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);
}

View 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 ();
}