From: Christopher Faylor Date: Wed, 13 Nov 2002 19:36:12 +0000 (+0000) Subject: * miscfuncs.cc (low_priority_sleep): New function. Use throughout where code X-Git-Tag: newlib-1_11_0~180 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=c0a02a4b42accbc574e84654cd845f8971d6a298;p=newlib-cygwin.git * miscfuncs.cc (low_priority_sleep): New function. Use throughout where code is supposed to be giving up time slice. * fhandler_console.cc (fhandler_console::read): Switch button 2/3 output escape sequences to be consistent with xterm. --- diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index b35da5cba..b36bd8073 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,11 @@ +2002-11-13 Christopher Faylor + + * miscfuncs.cc (low_priority_sleep): New function. Use throughout + where code is supposed to be giving up time slice. + + * fhandler_console.cc (fhandler_console::read): Switch button 2/3 + output escape sequences to be consistent with xterm. + 2002-11-12 Pierre Humblet * syscalls.cc (chmod): Simplify conditional. diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index 0b66278f6..5210623a0 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -214,7 +214,7 @@ std_dll_init () do { InterlockedDecrement (&dll->here); - Sleep (0); + low_priority_sleep (0); } while (InterlockedIncrement (&dll->here)); else if (!dll->handle) @@ -263,7 +263,7 @@ wsock_init () while (InterlockedIncrement (&here)) { InterlockedDecrement (&here); - Sleep (0); + low_priority_sleep (0); } if (!wsock_started && (winsock_active || winsock2_active)) diff --git a/winsup/cygwin/cygthread.cc b/winsup/cygwin/cygthread.cc index 70225f0cf..27e7f9442 100644 --- a/winsup/cygwin/cygthread.cc +++ b/winsup/cygwin/cygthread.cc @@ -170,11 +170,11 @@ cygthread::cygthread (LPTHREAD_START_ROUTINE start, LPVOID param, thread_printf ("name %s, id %p", name, id); while (!h) #ifndef DEBUGGING - Sleep (0); + low_priority_sleep (0); #else { thread_printf ("waiting for %s<%p> to become active", __name, h); - Sleep (0); + low_priority_sleep (0); } #endif __name = name; @@ -217,7 +217,7 @@ cygthread::operator HANDLE () { while (!ev) - Sleep (0); + low_priority_sleep (0); return ev; } diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 4e18e2791..05f285b2e 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -666,7 +666,7 @@ sigthread::get_winapi_lock (int test) /* Need to do a busy loop because we can't block or a potential SuspendThread will hang. */ while (InterlockedExchange (&winapi_lock, 1)) - Sleep (1); + low_priority_sleep (1); return 1; } @@ -855,7 +855,7 @@ setup_handler (int sig, void *handler, struct sigaction& siga) resume_thread: ResumeThread (hth); - Sleep (0); + low_priority_sleep (0); continue; } @@ -879,7 +879,7 @@ setup_handler (int sig, void *handler, struct sigaction& siga) pending_signals = 1; /* FIXME: Probably need to be more tricky here */ sig_set_pending (sig); sig_dispatch_pending (1); - Sleep (0); /* Hopefully, other process will be waking up soon. */ + low_priority_sleep (0); /* Hopefully, other process will be waking up soon. */ sigproc_printf ("couldn't send signal %d", sig); } diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 5be009eb9..80ea71a43 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -412,12 +412,12 @@ fhandler_console::read (void *pv, size_t buflen) } else if ((mouse_event.dwButtonState & 2) != (dev_state->dwLastButtonState & 2)) { - b = 1; + b = 2; strcpy (sz, "btn2 down"); } else if ((mouse_event.dwButtonState & 4) != (dev_state->dwLastButtonState & 4)) { - b = 2; + b = 1; strcpy (sz, "btn3 down"); } diff --git a/winsup/cygwin/fhandler_serial.cc b/winsup/cygwin/fhandler_serial.cc index fd7abb808..3c951801b 100644 --- a/winsup/cygwin/fhandler_serial.cc +++ b/winsup/cygwin/fhandler_serial.cc @@ -508,7 +508,7 @@ fhandler_serial::tcflush (int queue) COMSTAT st; if (!PurgeComm (get_handle (), PURGE_RXABORT | PURGE_RXCLEAR)) break; - Sleep (100); + low_priority_sleep (100); if (!ClearCommError (get_handle (), &ev, &st) || !st.cbInQue) break; } diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index ed1092776..82dae85ed 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -175,7 +175,7 @@ fhandler_pty_master::accept_input () debug_printf ("to_slave pipe is full"); SetEvent (input_available_event); ReleaseMutex (input_mutex); - Sleep (10); + low_priority_sleep (10); rc = WaitForSingleObject (input_mutex, INFINITE); } } @@ -279,7 +279,7 @@ fhandler_pty_master::process_slave_output (char *buf, size_t len, int pktmode_on break; } - Sleep (10); + low_priority_sleep (10); } if (ReadFile (handle, outbuf, rlen, &n, NULL) == FALSE) diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc index fd7ae8edf..36a3d9332 100644 --- a/winsup/cygwin/miscfuncs.cc +++ b/winsup/cygwin/miscfuncs.cc @@ -291,3 +291,12 @@ sys_mbstowcs (WCHAR *tgt, const char *src, int len) { return MultiByteToWideChar (get_cp (), 0, src, -1, tgt, len); } + +void __stdcall +low_priority_sleep (DWORD secs) +{ + DWORD prio = GetThreadPriority (GetCurrentThread ()); + SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_IDLE); + Sleep (secs); + SetThreadPriority (GetCurrentThread (), prio); +} diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index d4764bced..6feea6444 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -212,7 +212,7 @@ pinfo::init (pid_t n, DWORD flag, HANDLE in_h) this way at some point. */ if (i < 9 && !created && createit && (procinfo->process_state & PID_EXITED)) { - Sleep (5); + low_priority_sleep (5); release (); continue; } @@ -368,12 +368,7 @@ _pinfo::commune_send (DWORD code) if (myself->hello_pid <= 0) break; else - { - DWORD prio = GetThreadPriority (GetCurrentThread ()); - SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_IDLE); - Sleep (0); - SetThreadPriority (GetCurrentThread (), prio); - } + low_priority_sleep (0); CloseHandle (tome); tome = NULL; diff --git a/winsup/cygwin/sched.cc b/winsup/cygwin/sched.cc index 185530210..99c73914d 100644 --- a/winsup/cygwin/sched.cc +++ b/winsup/cygwin/sched.cc @@ -438,7 +438,7 @@ sched_setscheduler (pid_t pid, int policy, int sched_yield (void) { - Sleep (0); + low_priority_sleep (0); return 0; } } diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 8af76e138..af59a67ff 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -886,7 +886,7 @@ getsem (_pinfo *p, const char *str, int init, int max) sigproc_printf ("pid %d, ppid %d, wait %d, initializing %x", p->pid, p->ppid, wait, ISSTATE (p, PID_INITIALIZING)); for (int i = 0; ISSTATE (p, PID_INITIALIZING) && i < wait; i++) - Sleep (1); + low_priority_sleep (1); } SetLastError (0); diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 115df453e..e2fc0affd 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -862,7 +862,7 @@ pthread_cond::Signal () { InterlockedIncrement (&ExitingWait); /* give up the cpu to force a context switch. */ - Sleep (0); + low_priority_sleep (0); if (spins == 5) /* we've had 5 timeslices, and the woken thread still hasn't done it's * thing - maybe we raced it with the event? */ diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc index 9a295244f..0e3e14a52 100644 --- a/winsup/cygwin/tty.cc +++ b/winsup/cygwin/tty.cc @@ -138,7 +138,7 @@ tty_list::terminate (void) i = 0; } - Sleep (200); + low_priority_sleep (200); } termios_printf ("tty %d master about to finish", ttynum); @@ -218,12 +218,12 @@ tty_list::allocate_tty (int with_console) SetConsoleTitle (buf); for (int times = 0; times < 25; times++) { - Sleep (10); + low_priority_sleep (10); if ((console = FindWindow (NULL, buf))) break; } SetConsoleTitle (oldtitle); - Sleep (40); + low_priority_sleep (40); ReleaseMutex (title_mutex); if (console == NULL) {