Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2010-03-13 02:13:48 +0300
committerChristopher Faylor <me@cgf.cx>2010-03-13 02:13:48 +0300
commit084ea5108e86738a09288268b186541b0c23920a (patch)
tree93ad21c3c750fe12e7792ff8679b87888992dc3d
parent36960dec3721fccc8eb931787a2656cf715bfc39 (diff)
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.
-rw-r--r--winsup/cygwin/ChangeLog12
-rw-r--r--winsup/cygwin/autoload.cc4
-rw-r--r--winsup/cygwin/cygthread.cc10
-rw-r--r--winsup/cygwin/dcrt0.cc2
-rw-r--r--winsup/cygwin/exceptions.cc4
-rw-r--r--winsup/cygwin/fhandler_fifo.cc2
-rw-r--r--winsup/cygwin/fhandler_proc.cc2
-rwxr-xr-xwinsup/cygwin/gendef15
-rw-r--r--winsup/cygwin/miscfuncs.cc40
-rw-r--r--winsup/cygwin/miscfuncs.h3
-rw-r--r--winsup/cygwin/net.cc2
-rw-r--r--winsup/cygwin/pinfo.cc6
-rw-r--r--winsup/cygwin/sched.cc2
-rw-r--r--winsup/cygwin/shared.cc8
-rw-r--r--winsup/cygwin/sigproc.cc4
-rw-r--r--winsup/cygwin/sync.cc2
-rw-r--r--winsup/cygwin/thread.cc2
-rw-r--r--winsup/cygwin/tty.cc2
18 files changed, 48 insertions, 74 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index f7f1f507c..e476c7e4f 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -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.
diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc
index eb16961c9..f5bdadeee 100644
--- a/winsup/cygwin/autoload.cc
+++ b/winsup/cygwin/autoload.cc
@@ -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)
diff --git a/winsup/cygwin/cygthread.cc b/winsup/cygwin/cygthread.cc
index b0aea3619..e747a2d87 100644
--- a/winsup/cygwin/cygthread.cc
+++ b/winsup/cygwin/cygthread.cc
@@ -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;
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index f85f297bf..5cee9f886 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -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;
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index c416edc98..39b56eac5 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -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:
diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc
index d24c73143..b4a78d422 100644
--- a/winsup/cygwin/fhandler_fifo.cc
+++ b/winsup/cygwin/fhandler_fifo.cc
@@ -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);
diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc
index bfbf64ddf..de55797d6 100644
--- a/winsup/cygwin/fhandler_proc.cc
+++ b/winsup/cygwin/fhandler_proc.cc
@@ -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;
diff --git a/winsup/cygwin/gendef b/winsup/cygwin/gendef
index 9c17010b4..8899e8576 100755
--- a/winsup/cygwin/gendef
+++ b/winsup/cygwin/gendef
@@ -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
diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc
index 29b8159ad..c7099dc9b 100644
--- a/winsup/cygwin/miscfuncs.cc
+++ b/winsup/cygwin/miscfuncs.cc
@@ -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,
diff --git a/winsup/cygwin/miscfuncs.h b/winsup/cygwin/miscfuncs.h
index 489f8b745..1dcb924db 100644
--- a/winsup/cygwin/miscfuncs.h
+++ b/winsup/cygwin/miscfuncs.h
@@ -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);
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index ac83d4e53..ad1735f13 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -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);
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index af081bafa..cdc801d56 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -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
diff --git a/winsup/cygwin/sched.cc b/winsup/cygwin/sched.cc
index 08f96833b..eae493b3a 100644
--- a/winsup/cygwin/sched.cc
+++ b/winsup/cygwin/sched.cc
@@ -483,7 +483,7 @@ sched_setscheduler (pid_t pid, int policy,
int
sched_yield ()
{
- low_priority_sleep (0);
+ yield ();
return 0;
}
}
diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc
index 4a2489222..fcca6f40f 100644
--- a/winsup/cygwin/shared.cc
+++ b/winsup/cygwin/shared.cc
@@ -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);
}
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index e940ebe6c..9408b0c6d 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -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;
diff --git a/winsup/cygwin/sync.cc b/winsup/cygwin/sync.cc
index 8fa0d93f0..b62c6bcb7 100644
--- a/winsup/cygwin/sync.cc
+++ b/winsup/cygwin/sync.cc
@@ -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;
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index 20eb95dfa..5681aadef 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -456,7 +456,7 @@ pthread::create (void *(*func) (void *), pthread_attr *newattr,
{
postcreate ();
while (!cygtls)
- low_priority_sleep (0);
+ yield ();
}
retval = magic;
mutex.unlock ();
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index 624805f20..e7018106d 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -160,7 +160,7 @@ tty_list::terminate ()
i = 0;
}
- low_priority_sleep (200);
+ Sleep (200);
}
lock_ttys here ();