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:
parent
36960dec37
commit
084ea5108e
@ -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>
|
2010-03-10 Christopher Faylor <me.cygwin@cgf.cx>
|
||||||
|
|
||||||
* shared.cc (memory_init): Fix comment. Fix indentation.
|
* shared.cc (memory_init): Fix comment. Fix indentation.
|
||||||
|
@ -216,7 +216,7 @@ std_dll_init ()
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
InterlockedDecrement (&dll->here);
|
InterlockedDecrement (&dll->here);
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
}
|
}
|
||||||
while (InterlockedIncrement (&dll->here));
|
while (InterlockedIncrement (&dll->here));
|
||||||
else if (!dll->handle)
|
else if (!dll->handle)
|
||||||
@ -259,7 +259,7 @@ wsock_init ()
|
|||||||
while (InterlockedIncrement (&here))
|
while (InterlockedIncrement (&here))
|
||||||
{
|
{
|
||||||
InterlockedDecrement (&here);
|
InterlockedDecrement (&here);
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!wsock_started)
|
if (!wsock_started)
|
||||||
|
@ -41,7 +41,7 @@ cygthread::callfunc (bool issimplestub)
|
|||||||
{
|
{
|
||||||
/* Wait for main thread to assign 'h' */
|
/* Wait for main thread to assign 'h' */
|
||||||
while (!h)
|
while (!h)
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
if (ev)
|
if (ev)
|
||||||
CloseHandle (ev);
|
CloseHandle (ev);
|
||||||
ev = h;
|
ev = h;
|
||||||
@ -196,7 +196,7 @@ cygthread::cygthread (LPTHREAD_START_ROUTINE start, size_t n, void *param,
|
|||||||
if (ev)
|
if (ev)
|
||||||
ResetEvent (ev);
|
ResetEvent (ev);
|
||||||
while (!thread_sync)
|
while (!thread_sync)
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
SetEvent (thread_sync);
|
SetEvent (thread_sync);
|
||||||
thread_printf ("activated name '%s', thread_sync %p for thread %p", name, thread_sync, id);
|
thread_printf ("activated name '%s', thread_sync %p for thread %p", name, thread_sync, id);
|
||||||
htobe = h;
|
htobe = h;
|
||||||
@ -217,7 +217,7 @@ cygthread::cygthread (LPTHREAD_START_ROUTINE start, size_t n, void *param,
|
|||||||
if (n)
|
if (n)
|
||||||
{
|
{
|
||||||
while (!ev)
|
while (!ev)
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
WaitForSingleObject (ev, INFINITE);
|
WaitForSingleObject (ev, INFINITE);
|
||||||
ResetEvent (ev);
|
ResetEvent (ev);
|
||||||
}
|
}
|
||||||
@ -256,7 +256,7 @@ cygthread::operator
|
|||||||
HANDLE ()
|
HANDLE ()
|
||||||
{
|
{
|
||||||
while (!ev)
|
while (!ev)
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
return ev;
|
return ev;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +287,7 @@ cygthread::terminate_thread ()
|
|||||||
bool terminated = true;
|
bool terminated = true;
|
||||||
debug_printf ("thread '%s', id %p, inuse %d, stack_ptr %p", __name, id, inuse, stack_ptr);
|
debug_printf ("thread '%s', id %p, inuse %d, stack_ptr %p", __name, id, inuse, stack_ptr);
|
||||||
while (inuse && !stack_ptr)
|
while (inuse && !stack_ptr)
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
|
|
||||||
if (!inuse)
|
if (!inuse)
|
||||||
goto force_notterminated;
|
goto force_notterminated;
|
||||||
|
@ -557,7 +557,7 @@ get_cygwin_startup_info ()
|
|||||||
{
|
{
|
||||||
res->ready (false);
|
res->ready (false);
|
||||||
for (unsigned i = 0; !being_debugged () && i < 10000; i++)
|
for (unsigned i = 0; !being_debugged () && i < 10000; i++)
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
strace.hello ();
|
strace.hello ();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -440,7 +440,7 @@ try_to_debug (bool waitloop)
|
|||||||
return dbg;
|
return dbg;
|
||||||
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_IDLE);
|
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_IDLE);
|
||||||
while (!being_debugged ())
|
while (!being_debugged ())
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
Sleep (2000);
|
Sleep (2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -901,7 +901,7 @@ setup_handler (int sig, void *handler, struct sigaction& siga, _cygtls *tls)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
sigproc_printf ("couldn't interrupt. trying again.");
|
sigproc_printf ("couldn't interrupt. trying again.");
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
@ -46,7 +46,7 @@ fhandler_fifo::open_nonserver (const char *npname, unsigned low_flags,
|
|||||||
if (h != INVALID_HANDLE_VALUE || GetLastError () != ERROR_PIPE_NOT_CONNECTED)
|
if (h != INVALID_HANDLE_VALUE || GetLastError () != ERROR_PIPE_NOT_CONNECTED)
|
||||||
return h;
|
return h;
|
||||||
if (&_my_tls != _main_tls)
|
if (&_my_tls != _main_tls)
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
else if (WaitForSingleObject (signal_arrived, 0) == WAIT_OBJECT_0)
|
else if (WaitForSingleObject (signal_arrived, 0) == WAIT_OBJECT_0)
|
||||||
{
|
{
|
||||||
set_errno (EINTR);
|
set_errno (EINTR);
|
||||||
|
@ -616,7 +616,7 @@ format_proc_cpuinfo (void *, char *&destbuf)
|
|||||||
debug_printf ("SetThreadAffinityMask failed %E");
|
debug_printf ("SetThreadAffinityMask failed %E");
|
||||||
// I'm not sure whether the thread changes processor immediately
|
// 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
|
// and I'm not sure whether this function will cause the thread to be rescheduled
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
|
|
||||||
bool has_cpuid = false;
|
bool has_cpuid = false;
|
||||||
|
|
||||||
|
@ -126,8 +126,7 @@ __sigfe:
|
|||||||
movl %eax,$tls::spinning(%ebx) # flag if we are waiting for lock
|
movl %eax,$tls::spinning(%ebx) # flag if we are waiting for lock
|
||||||
testl %eax,%eax # it will be zero
|
testl %eax,%eax # it will be zero
|
||||||
jz 2f # if so
|
jz 2f # if so
|
||||||
xorl %eax,%eax # nope. It was not zero
|
call _yield # should be a short-time thing, so
|
||||||
call _low_priority_sleep # should be a short-time thing, so
|
|
||||||
jmp 1b # sleep and loop
|
jmp 1b # sleep and loop
|
||||||
2: movl \$4,%eax # have the lock, now increment the
|
2: movl \$4,%eax # have the lock, now increment the
|
||||||
xadd %eax,$tls::stackptr(%ebx) # stack pointer and get pointer
|
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
|
movl %eax,$tls::spinning(%ebx) # flag if we are waiting for lock
|
||||||
testl %eax,%eax # it will be zero
|
testl %eax,%eax # it will be zero
|
||||||
jz 2f # if so
|
jz 2f # if so
|
||||||
xorl %eax,%eax # nope. not zero
|
call _yield # sleep
|
||||||
call _low_priority_sleep # sleep
|
|
||||||
jmp 1b # and loop
|
jmp 1b # and loop
|
||||||
2: movl \$-4,%eax # now decrement aux stack
|
2: movl \$-4,%eax # now decrement aux stack
|
||||||
xadd %eax,$tls::stackptr(%ebx) # and get pointer
|
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
|
movl %eax,$tls::spinning(%ebx) # flag if we are waiting for lock
|
||||||
testl %eax,%eax # it will be zero
|
testl %eax,%eax # it will be zero
|
||||||
jz 2f # if so
|
jz 2f # if so
|
||||||
xorl %eax,%eax # nope. not zero
|
call _yield # sleep
|
||||||
call _low_priority_sleep # sleep
|
|
||||||
jmp 1b # and loop
|
jmp 1b # and loop
|
||||||
2: popl %edx # saved errno
|
2: popl %edx # saved errno
|
||||||
testl %edx,%edx # Is it < 0
|
testl %edx,%edx # Is it < 0
|
||||||
@ -258,8 +255,7 @@ __ZN7_cygtls4lockEv:
|
|||||||
lock xchgl %eax,$tls::pstacklock(%ebx)
|
lock xchgl %eax,$tls::pstacklock(%ebx)
|
||||||
testl %eax,%eax
|
testl %eax,%eax
|
||||||
jz 2f
|
jz 2f
|
||||||
xorl %eax,%eax
|
call _yield
|
||||||
call _low_priority_sleep
|
|
||||||
jmp 1b
|
jmp 1b
|
||||||
2: popl %ebx
|
2: popl %ebx
|
||||||
ret
|
ret
|
||||||
@ -283,8 +279,7 @@ stabilize_sig_stack:
|
|||||||
movl %eax,$tls::spinning(%ebx) # flag if we are waiting for lock
|
movl %eax,$tls::spinning(%ebx) # flag if we are waiting for lock
|
||||||
testl %eax,%eax
|
testl %eax,%eax
|
||||||
jz 2f
|
jz 2f
|
||||||
xorl %eax,%eax
|
call _yield
|
||||||
call _low_priority_sleep
|
|
||||||
jmp 1b
|
jmp 1b
|
||||||
2: cmpl \$0,$tls::sig(%ebx)
|
2: cmpl \$0,$tls::sig(%ebx)
|
||||||
jz 3f
|
jz 3f
|
||||||
|
@ -228,44 +228,12 @@ check_iovec (const struct iovec *iov, int iovcnt, bool forwrite)
|
|||||||
return (ssize_t) tot;
|
return (ssize_t) tot;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int
|
void
|
||||||
low_priority_sleep (DWORD secs)
|
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++)
|
for (int i = 0; i < 3; i++)
|
||||||
SwitchToThread ();
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get a default value for the nice factor. When changing these values,
|
/* Get a default value for the nice factor. When changing these values,
|
||||||
have a look into the below function nice_to_winprio. The values must
|
have a look into the below function nice_to_winprio. The values must
|
||||||
|
@ -18,8 +18,7 @@ bool __stdcall create_pipe (PHANDLE, PHANDLE, LPSECURITY_ATTRIBUTES, DWORD)
|
|||||||
__attribute__ ((regparm (3)));
|
__attribute__ ((regparm (3)));
|
||||||
#define CreatePipe create_pipe
|
#define CreatePipe create_pipe
|
||||||
|
|
||||||
extern "C" int low_priority_sleep (DWORD) __attribute__ ((regparm (1)));
|
extern "C" void yield ();
|
||||||
#define SLEEP_0_STAY_LOW INFINITE
|
|
||||||
|
|
||||||
void backslashify (const char *, char *, bool);
|
void backslashify (const char *, char *, bool);
|
||||||
void slashify (const char *, char *, bool);
|
void slashify (const char *, char *, bool);
|
||||||
|
@ -2775,7 +2775,7 @@ cygwin_bindresvport_sa (int fd, struct sockaddr *sa)
|
|||||||
for (int i = 0; i < NUM_PORTS; i++)
|
for (int i = 0; i < NUM_PORTS; i++)
|
||||||
{
|
{
|
||||||
while ((myport = InterlockedExchange (&cygwin_shared->last_used_bindresvport, -1)) == -1)
|
while ((myport = InterlockedExchange (&cygwin_shared->last_used_bindresvport, -1)) == -1)
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
if (myport == 0 || --myport < PORT_LOW)
|
if (myport == 0 || --myport < PORT_LOW)
|
||||||
myport = PORT_HIGH;
|
myport = PORT_HIGH;
|
||||||
InterlockedExchange (&cygwin_shared->last_used_bindresvport, myport);
|
InterlockedExchange (&cygwin_shared->last_used_bindresvport, myport);
|
||||||
|
@ -258,7 +258,7 @@ pinfo::init (pid_t n, DWORD flag, HANDLE h0)
|
|||||||
mapaddr = NULL;
|
mapaddr = NULL;
|
||||||
}
|
}
|
||||||
debug_printf ("MapViewOfFileEx h0 %p, i %d failed, %E", h0, i);
|
debug_printf ("MapViewOfFileEx h0 %p, i %d failed, %E", h0, i);
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,7 +313,7 @@ pinfo::init (pid_t n, DWORD flag, HANDLE h0)
|
|||||||
loop:
|
loop:
|
||||||
release ();
|
release ();
|
||||||
if (h0)
|
if (h0)
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (h)
|
if (h)
|
||||||
@ -978,7 +978,7 @@ _pinfo::sync_proc_pipe ()
|
|||||||
{
|
{
|
||||||
if (wr_proc_pipe && wr_proc_pipe != INVALID_HANDLE_VALUE)
|
if (wr_proc_pipe && wr_proc_pipe != INVALID_HANDLE_VALUE)
|
||||||
while (wr_proc_pipe_owner != GetCurrentProcessId ())
|
while (wr_proc_pipe_owner != GetCurrentProcessId ())
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* function to send a "signal" to the parent when something interesting happens
|
/* function to send a "signal" to the parent when something interesting happens
|
||||||
|
@ -483,7 +483,7 @@ sched_setscheduler (pid_t pid, int policy,
|
|||||||
int
|
int
|
||||||
sched_yield ()
|
sched_yield ()
|
||||||
{
|
{
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -318,7 +318,7 @@ user_shared_initialize ()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
while (!user_shared->cb)
|
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)
|
if (user_shared->version != sversion)
|
||||||
multiple_cygwin_problem ("user shared memory version", user_shared->version, sversion);
|
multiple_cygwin_problem ("user shared memory version", user_shared->version, sversion);
|
||||||
else if (user_shared->cb != sizeof (*user_shared))
|
else if (user_shared->cb != sizeof (*user_shared))
|
||||||
@ -423,7 +423,7 @@ memory_init (bool init_cygheap)
|
|||||||
LONG smi = InterlockedExchange (&shared_mem_inited, -1);
|
LONG smi = InterlockedExchange (&shared_mem_inited, -1);
|
||||||
if (smi < 0)
|
if (smi < 0)
|
||||||
{
|
{
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,12 +431,13 @@ memory_init (bool init_cygheap)
|
|||||||
/* Initialize installation root dir */
|
/* Initialize installation root dir */
|
||||||
init_installation_root ();
|
init_installation_root ();
|
||||||
|
|
||||||
/* Installation root dir has been globally initialized */
|
|
||||||
cygwin_shared = (shared_info *) open_shared (L"shared",
|
cygwin_shared = (shared_info *) open_shared (L"shared",
|
||||||
CYGWIN_VERSION_SHARED_DATA,
|
CYGWIN_VERSION_SHARED_DATA,
|
||||||
cygwin_shared_h,
|
cygwin_shared_h,
|
||||||
sizeof (*cygwin_shared),
|
sizeof (*cygwin_shared),
|
||||||
SH_CYGWIN_SHARED);
|
SH_CYGWIN_SHARED);
|
||||||
|
heap_init ();
|
||||||
|
|
||||||
if (!smi)
|
if (!smi)
|
||||||
{
|
{
|
||||||
cygwin_shared->initialize ();
|
cygwin_shared->initialize ();
|
||||||
@ -451,7 +452,6 @@ memory_init (bool init_cygheap)
|
|||||||
InterlockedExchange (&shared_mem_inited, smi);
|
InterlockedExchange (&shared_mem_inited, smi);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
heap_init ();
|
|
||||||
user_shared_create (false);
|
user_shared_create (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -583,7 +583,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
|
|||||||
HANDLE dupsig;
|
HANDLE dupsig;
|
||||||
DWORD dwProcessId;
|
DWORD dwProcessId;
|
||||||
for (int i = 0; !p->sendsig && i < 10000; i++)
|
for (int i = 0; !p->sendsig && i < 10000; i++)
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
if (p->sendsig)
|
if (p->sendsig)
|
||||||
{
|
{
|
||||||
dupsig = 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
|
the proc_waiter thread has already done this by the time we
|
||||||
get here. */
|
get here. */
|
||||||
while (!procs[nprocs].waiter_ready)
|
while (!procs[nprocs].waiter_ready)
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
procs[ci] = procs[nprocs];
|
procs[ci] = procs[nprocs];
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -36,7 +36,7 @@ muto::init (const char *s)
|
|||||||
char *already_exists = (char *) InterlockedExchangePointer (&name, s);
|
char *already_exists = (char *) InterlockedExchangePointer (&name, s);
|
||||||
if (already_exists)
|
if (already_exists)
|
||||||
while (!bruteforce)
|
while (!bruteforce)
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
waiters = -1;
|
waiters = -1;
|
||||||
|
@ -456,7 +456,7 @@ pthread::create (void *(*func) (void *), pthread_attr *newattr,
|
|||||||
{
|
{
|
||||||
postcreate ();
|
postcreate ();
|
||||||
while (!cygtls)
|
while (!cygtls)
|
||||||
low_priority_sleep (0);
|
yield ();
|
||||||
}
|
}
|
||||||
retval = magic;
|
retval = magic;
|
||||||
mutex.unlock ();
|
mutex.unlock ();
|
||||||
|
@ -160,7 +160,7 @@ tty_list::terminate ()
|
|||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
low_priority_sleep (200);
|
Sleep (200);
|
||||||
}
|
}
|
||||||
|
|
||||||
lock_ttys here ();
|
lock_ttys here ();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user