Throughout change all calls of low_priority_sleep (0) to yield ().

* miscfuncs.cc (yield): Rename from low_priority_sleep.  Remove all of the
logic which called Sleep() and just use SwitchToThread.
* miscfuncs.h (yield): Rename from low_priority_sleep.
(SLEEP_0_STAY_LOW): Delete unused define.
* shared.cc (memory_init): Move heap_init() call directly after shared memory
initialization to more closely mimic long-standing program flow.
* tty.cc (tty_list::terminate): Replace call to low_priority_sleep with Sleep.
This commit is contained in:
Christopher Faylor 2010-03-12 23:13:48 +00:00
parent 36960dec37
commit 084ea5108e
18 changed files with 48 additions and 74 deletions

View File

@ -1,3 +1,15 @@
2010-03-12 Christopher Faylor <me+cygwin@cgf.cx>
Throughout change all calls of low_priority_sleep (0) to yield ().
* miscfuncs.cc (yield): Rename from low_priority_sleep. Remove all of
the logic which called Sleep() and just use SwitchToThread.
* miscfuncs.h (yield): Rename from low_priority_sleep.
(SLEEP_0_STAY_LOW): Delete unused define.
* shared.cc (memory_init): Move heap_init() call directly after shared
memory initialization to more closely mimic long-standing program flow.
* tty.cc (tty_list::terminate): Replace call to low_priority_sleep with
Sleep.
2010-03-10 Christopher Faylor <me.cygwin@cgf.cx>
* shared.cc (memory_init): Fix comment. Fix indentation.

View File

@ -216,7 +216,7 @@ std_dll_init ()
do
{
InterlockedDecrement (&dll->here);
low_priority_sleep (0);
yield ();
}
while (InterlockedIncrement (&dll->here));
else if (!dll->handle)
@ -259,7 +259,7 @@ wsock_init ()
while (InterlockedIncrement (&here))
{
InterlockedDecrement (&here);
low_priority_sleep (0);
yield ();
}
if (!wsock_started)

View File

@ -41,7 +41,7 @@ cygthread::callfunc (bool issimplestub)
{
/* Wait for main thread to assign 'h' */
while (!h)
low_priority_sleep (0);
yield ();
if (ev)
CloseHandle (ev);
ev = h;
@ -196,7 +196,7 @@ cygthread::cygthread (LPTHREAD_START_ROUTINE start, size_t n, void *param,
if (ev)
ResetEvent (ev);
while (!thread_sync)
low_priority_sleep (0);
yield ();
SetEvent (thread_sync);
thread_printf ("activated name '%s', thread_sync %p for thread %p", name, thread_sync, id);
htobe = h;
@ -217,7 +217,7 @@ cygthread::cygthread (LPTHREAD_START_ROUTINE start, size_t n, void *param,
if (n)
{
while (!ev)
low_priority_sleep (0);
yield ();
WaitForSingleObject (ev, INFINITE);
ResetEvent (ev);
}
@ -256,7 +256,7 @@ cygthread::operator
HANDLE ()
{
while (!ev)
low_priority_sleep (0);
yield ();
return ev;
}
@ -287,7 +287,7 @@ cygthread::terminate_thread ()
bool terminated = true;
debug_printf ("thread '%s', id %p, inuse %d, stack_ptr %p", __name, id, inuse, stack_ptr);
while (inuse && !stack_ptr)
low_priority_sleep (0);
yield ();
if (!inuse)
goto force_notterminated;

View File

@ -557,7 +557,7 @@ get_cygwin_startup_info ()
{
res->ready (false);
for (unsigned i = 0; !being_debugged () && i < 10000; i++)
low_priority_sleep (0);
yield ();
strace.hello ();
}
break;

View File

@ -440,7 +440,7 @@ try_to_debug (bool waitloop)
return dbg;
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_IDLE);
while (!being_debugged ())
low_priority_sleep (0);
yield ();
Sleep (2000);
}
@ -901,7 +901,7 @@ setup_handler (int sig, void *handler, struct sigaction& siga, _cygtls *tls)
break;
sigproc_printf ("couldn't interrupt. trying again.");
low_priority_sleep (0);
yield ();
}
out:

View File

@ -46,7 +46,7 @@ fhandler_fifo::open_nonserver (const char *npname, unsigned low_flags,
if (h != INVALID_HANDLE_VALUE || GetLastError () != ERROR_PIPE_NOT_CONNECTED)
return h;
if (&_my_tls != _main_tls)
low_priority_sleep (0);
yield ();
else if (WaitForSingleObject (signal_arrived, 0) == WAIT_OBJECT_0)
{
set_errno (EINTR);

View File

@ -616,7 +616,7 @@ format_proc_cpuinfo (void *, char *&destbuf)
debug_printf ("SetThreadAffinityMask failed %E");
// I'm not sure whether the thread changes processor immediately
// and I'm not sure whether this function will cause the thread to be rescheduled
low_priority_sleep (0);
yield ();
bool has_cpuid = false;

View File

@ -126,8 +126,7 @@ __sigfe:
movl %eax,$tls::spinning(%ebx) # flag if we are waiting for lock
testl %eax,%eax # it will be zero
jz 2f # if so
xorl %eax,%eax # nope. It was not zero
call _low_priority_sleep # should be a short-time thing, so
call _yield # should be a short-time thing, so
jmp 1b # sleep and loop
2: movl \$4,%eax # have the lock, now increment the
xadd %eax,$tls::stackptr(%ebx) # stack pointer and get pointer
@ -151,8 +150,7 @@ __sigbe: # return here after cygwin syscall
movl %eax,$tls::spinning(%ebx) # flag if we are waiting for lock
testl %eax,%eax # it will be zero
jz 2f # if so
xorl %eax,%eax # nope. not zero
call _low_priority_sleep # sleep
call _yield # sleep
jmp 1b # and loop
2: movl \$-4,%eax # now decrement aux stack
xadd %eax,$tls::stackptr(%ebx) # and get pointer
@ -177,8 +175,7 @@ _sigreturn:
movl %eax,$tls::spinning(%ebx) # flag if we are waiting for lock
testl %eax,%eax # it will be zero
jz 2f # if so
xorl %eax,%eax # nope. not zero
call _low_priority_sleep # sleep
call _yield # sleep
jmp 1b # and loop
2: popl %edx # saved errno
testl %edx,%edx # Is it < 0
@ -258,8 +255,7 @@ __ZN7_cygtls4lockEv:
lock xchgl %eax,$tls::pstacklock(%ebx)
testl %eax,%eax
jz 2f
xorl %eax,%eax
call _low_priority_sleep
call _yield
jmp 1b
2: popl %ebx
ret
@ -283,8 +279,7 @@ stabilize_sig_stack:
movl %eax,$tls::spinning(%ebx) # flag if we are waiting for lock
testl %eax,%eax
jz 2f
xorl %eax,%eax
call _low_priority_sleep
call _yield
jmp 1b
2: cmpl \$0,$tls::sig(%ebx)
jz 3f

View File

@ -228,43 +228,11 @@ check_iovec (const struct iovec *iov, int iovcnt, bool forwrite)
return (ssize_t) tot;
}
extern "C" int
low_priority_sleep (DWORD secs)
void
yield ()
{
HANDLE thisthread = GetCurrentThread ();
int curr_prio = GetThreadPriority (thisthread);
bool staylow;
if (secs != INFINITE)
staylow = false;
else
{
secs = 0;
staylow = true;
}
if (!secs)
{
for (int i = 0; i < 3; i++)
SwitchToThread ();
}
else
{
int new_prio;
if (GetCurrentThreadId () == cygthread::main_thread_id)
new_prio = THREAD_PRIORITY_LOWEST;
else
new_prio = GetThreadPriority (hMainThread);
if (curr_prio != new_prio)
/* Force any threads in normal priority to be scheduled */
SetThreadPriority (thisthread, new_prio);
Sleep (secs);
if (!staylow && curr_prio != new_prio)
SetThreadPriority (thisthread, curr_prio);
}
return curr_prio;
for (int i = 0; i < 3; i++)
SwitchToThread ();
}
/* Get a default value for the nice factor. When changing these values,

View File

@ -18,8 +18,7 @@ bool __stdcall create_pipe (PHANDLE, PHANDLE, LPSECURITY_ATTRIBUTES, DWORD)
__attribute__ ((regparm (3)));
#define CreatePipe create_pipe
extern "C" int low_priority_sleep (DWORD) __attribute__ ((regparm (1)));
#define SLEEP_0_STAY_LOW INFINITE
extern "C" void yield ();
void backslashify (const char *, char *, bool);
void slashify (const char *, char *, bool);

View File

@ -2775,7 +2775,7 @@ cygwin_bindresvport_sa (int fd, struct sockaddr *sa)
for (int i = 0; i < NUM_PORTS; i++)
{
while ((myport = InterlockedExchange (&cygwin_shared->last_used_bindresvport, -1)) == -1)
low_priority_sleep (0);
yield ();
if (myport == 0 || --myport < PORT_LOW)
myport = PORT_HIGH;
InterlockedExchange (&cygwin_shared->last_used_bindresvport, myport);

View File

@ -258,7 +258,7 @@ pinfo::init (pid_t n, DWORD flag, HANDLE h0)
mapaddr = NULL;
}
debug_printf ("MapViewOfFileEx h0 %p, i %d failed, %E", h0, i);
low_priority_sleep (0);
yield ();
continue;
}
@ -313,7 +313,7 @@ pinfo::init (pid_t n, DWORD flag, HANDLE h0)
loop:
release ();
if (h0)
low_priority_sleep (0);
yield ();
}
if (h)
@ -978,7 +978,7 @@ _pinfo::sync_proc_pipe ()
{
if (wr_proc_pipe && wr_proc_pipe != INVALID_HANDLE_VALUE)
while (wr_proc_pipe_owner != GetCurrentProcessId ())
low_priority_sleep (0);
yield ();
}
/* function to send a "signal" to the parent when something interesting happens

View File

@ -483,7 +483,7 @@ sched_setscheduler (pid_t pid, int policy,
int
sched_yield ()
{
low_priority_sleep (0);
yield ();
return 0;
}
}

View File

@ -318,7 +318,7 @@ user_shared_initialize ()
else
{
while (!user_shared->cb)
low_priority_sleep (0); // Should be hit only very very rarely
yield (); // Should be hit only very very rarely
if (user_shared->version != sversion)
multiple_cygwin_problem ("user shared memory version", user_shared->version, sversion);
else if (user_shared->cb != sizeof (*user_shared))
@ -423,7 +423,7 @@ memory_init (bool init_cygheap)
LONG smi = InterlockedExchange (&shared_mem_inited, -1);
if (smi < 0)
{
low_priority_sleep (0);
yield ();
continue;
}
@ -431,12 +431,13 @@ memory_init (bool init_cygheap)
/* Initialize installation root dir */
init_installation_root ();
/* Installation root dir has been globally initialized */
cygwin_shared = (shared_info *) open_shared (L"shared",
CYGWIN_VERSION_SHARED_DATA,
cygwin_shared_h,
sizeof (*cygwin_shared),
SH_CYGWIN_SHARED);
heap_init ();
if (!smi)
{
cygwin_shared->initialize ();
@ -451,7 +452,6 @@ memory_init (bool init_cygheap)
InterlockedExchange (&shared_mem_inited, smi);
break;
}
heap_init ();
user_shared_create (false);
}

View File

@ -583,7 +583,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
HANDLE dupsig;
DWORD dwProcessId;
for (int i = 0; !p->sendsig && i < 10000; i++)
low_priority_sleep (0);
yield ();
if (p->sendsig)
{
dupsig = p->sendsig;
@ -1011,7 +1011,7 @@ remove_proc (int ci)
the proc_waiter thread has already done this by the time we
get here. */
while (!procs[nprocs].waiter_ready)
low_priority_sleep (0);
yield ();
procs[ci] = procs[nprocs];
}
return 0;

View File

@ -36,7 +36,7 @@ muto::init (const char *s)
char *already_exists = (char *) InterlockedExchangePointer (&name, s);
if (already_exists)
while (!bruteforce)
low_priority_sleep (0);
yield ();
else
{
waiters = -1;

View File

@ -456,7 +456,7 @@ pthread::create (void *(*func) (void *), pthread_attr *newattr,
{
postcreate ();
while (!cygtls)
low_priority_sleep (0);
yield ();
}
retval = magic;
mutex.unlock ();

View File

@ -160,7 +160,7 @@ tty_list::terminate ()
i = 0;
}
low_priority_sleep (200);
Sleep (200);
}
lock_ttys here ();