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:
authorConrad Scott <conrad.scott@dsl.pipex.com>2002-08-29 23:19:28 +0400
committerConrad Scott <conrad.scott@dsl.pipex.com>2002-08-29 23:19:28 +0400
commitc02adb60c39cca42cb7cf3eae0eb903cd57369d1 (patch)
tree0d1573c685a3c5da8132ac0d0cd310e0fe0df2d2
parent7b78cbef17c7b45f2a4282c657e08c1b2cc1137d (diff)
Merged changes from HEAD
-rw-r--r--winsup/cygwin/ChangeLog19
-rw-r--r--winsup/cygwin/cygthread.cc68
-rw-r--r--winsup/cygwin/cygthread.h5
-rw-r--r--winsup/cygwin/include/wchar.h29
-rw-r--r--winsup/cygwin/newlib.h0
-rw-r--r--winsup/cygwin/poll.cc23
6 files changed, 100 insertions, 44 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index e6ea6f1f6..67d6eaa91 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -4,6 +4,25 @@
definition of the placement new operator.
(safe_delete): Remove unnecessary ## operator.
+2002-08-29 Boris Schaeling <boriss@web.de>
+ Corinna Vinschen <corinna@vinschen.de>
+
+ * poll.cc (poll): Peek sockets ready for read to see if there's
+ actually data.
+
+2002-08-28 Christopher Faylor <cgf@redhat.com>
+
+ * cygthread.cc (hthreads): Remove unneeded global.
+ (cygthread::simplestub): New static member function.
+ (cygthread::runner): Don't set hthreads.
+ (cygthread::freerange): New member function.
+ (cygthread::operator new): Call freerange if all cygwin slots are used
+ up.
+ (cygthread::exit_thread): Don't mess with event if freerange thread.
+ (cygthread::detach): Ditto.
+ * cygthread.h (class cygthread): Declare new member functions and
+ variables.
+
2002-08-28 Christopher Faylor <cgf@redhat.com>
* malloc.cc: Protect some definitions to avoid a compile time warning.
diff --git a/winsup/cygwin/cygthread.cc b/winsup/cygwin/cygthread.cc
index d1d93375c..e5dfcc575 100644
--- a/winsup/cygwin/cygthread.cc
+++ b/winsup/cygwin/cygthread.cc
@@ -8,18 +8,36 @@ details. */
#include "winsup.h"
#include <windows.h>
+#include <stdlib.h>
#include "exceptions.h"
#include "security.h"
#include "cygthread.h"
#undef CloseHandle
-static cygthread NO_COPY threads[8];
+static cygthread NO_COPY threads[6];
#define NTHREADS (sizeof (threads) / sizeof (threads[0]))
-static HANDLE NO_COPY hthreads[NTHREADS];
-
DWORD NO_COPY cygthread::main_thread_id;
+bool cygthread::initialized;
+
+/* Initial stub called by cygthread constructor. Performs initial
+ per-thread initialization and loops waiting for new thread functions
+ to execute. */
+DWORD WINAPI
+cygthread::simplestub (VOID *arg)
+{
+ DECLARE_TLS_STORAGE;
+ exception_list except_entry;
+
+ /* Initialize this thread's ability to respond to things like
+ SIGSEGV or SIGFPE. */
+ init_exceptions (&except_entry);
+
+ cygthread *info = (cygthread *) arg;
+ info->func (info->arg == cygself ? info : info->arg);
+ ExitThread (0);
+}
/* Initial stub called by cygthread constructor. Performs initial
per-thread initialization and loops waiting for new thread functions
@@ -60,9 +78,9 @@ DWORD WINAPI
cygthread::runner (VOID *arg)
{
for (unsigned i = 0; i < NTHREADS; i++)
- hthreads[i] = threads[i].h =
- CreateThread (&sec_none_nih, 0, cygthread::stub, &threads[i],
- CREATE_SUSPENDED, &threads[i].avail);
+ threads[i].h = CreateThread (&sec_none_nih, 0, cygthread::stub, &threads[i],
+ CREATE_SUSPENDED, &threads[i].avail);
+ cygthread::initialized = true;
return 0;
}
@@ -90,6 +108,17 @@ cygthread::is ()
return 0;
}
+void *
+cygthread::freerange ()
+{
+ cygthread *self = (cygthread *) calloc (1, sizeof (*self));
+ self->is_freerange = true;
+ self->h = CreateThread (&sec_none_nih, 0, cygthread::simplestub, self,
+ CREATE_SUSPENDED, &self->id);
+ self->ev = self->h;
+ return self;
+}
+
void * cygthread::operator
new (size_t)
{
@@ -110,8 +139,10 @@ new (size_t)
return info;
}
- /* thread_runner may not be finished yet. */
- Sleep (0);
+ if (!initialized)
+ Sleep (0); /* thread_runner is not be finished yet. */
+ else
+ return freerange ();
}
}
@@ -179,7 +210,8 @@ HANDLE ()
void
cygthread::exit_thread ()
{
- SetEvent (*this);
+ if (!is_freerange)
+ SetEvent (*this);
ExitThread (0);
}
@@ -204,10 +236,18 @@ cygthread::detach ()
DWORD res = WaitForSingleObject (*this, INFINITE);
thread_printf ("WFSO returns %d, id %p", res, id);
}
- ResetEvent (*this);
- id = 0;
- __name = NULL;
- /* Mark the thread as available by setting avail to non-zero */
- (void) InterlockedExchange ((LPLONG) &this->avail, avail);
+ if (is_freerange)
+ {
+ CloseHandle (h);
+ free (this);
+ }
+ else
+ {
+ ResetEvent (*this);
+ id = 0;
+ __name = NULL;
+ /* Mark the thread as available by setting avail to non-zero */
+ (void) InterlockedExchange ((LPLONG) &this->avail, avail);
+ }
}
}
diff --git a/winsup/cygwin/cygthread.h b/winsup/cygwin/cygthread.h
index 7f5a59455..37f7c6537 100644
--- a/winsup/cygwin/cygthread.h
+++ b/winsup/cygwin/cygthread.h
@@ -15,9 +15,13 @@ class cygthread
const char *__name;
LPTHREAD_START_ROUTINE func;
VOID *arg;
+ bool is_freerange;
static DWORD main_thread_id;
+ static bool initialized;
static DWORD WINAPI runner (VOID *);
+ static DWORD WINAPI free_runner (VOID *);
static DWORD WINAPI stub (VOID *);
+ static DWORD WINAPI simplestub (VOID *);
public:
static const char * name (DWORD = 0);
cygthread (LPTHREAD_START_ROUTINE, LPVOID, const char *);
@@ -27,6 +31,7 @@ class cygthread
operator HANDLE ();
static bool is ();
void * operator new (size_t);
+ static void * freerange ();
void exit_thread ();
};
diff --git a/winsup/cygwin/include/wchar.h b/winsup/cygwin/include/wchar.h
deleted file mode 100644
index bf3f017a2..000000000
--- a/winsup/cygwin/include/wchar.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/* wchar.h
-
- Copyright 1998, 1999, 2000, 2001 Red Hat, Inc.
-
-This file is part of Cygwin.
-
-This software is a copyrighted work licensed under the terms of the
-Cygwin license. Please consult the file "CYGWIN_LICENSE" for
-details. */
-
-#ifndef _WCHAR_H
-#define _WCHAR_H
-
-#include <sys/cdefs.h>
-
-/* Get wchar_t and wint_t from <stddef.h>. */
-#define __need_wchar_t
-#define __need_wint_t
-#define __need_size_t
-#include <stddef.h>
-
-__BEGIN_DECLS
-
-int wcscmp (const wchar_t *__s1, const wchar_t *__s2);
-size_t wcslen (const wchar_t *__s1);
-
-__END_DECLS
-
-#endif /* _WCHAR_H */
diff --git a/winsup/cygwin/newlib.h b/winsup/cygwin/newlib.h
deleted file mode 100644
index e69de29bb..000000000
--- a/winsup/cygwin/newlib.h
+++ /dev/null
diff --git a/winsup/cygwin/poll.cc b/winsup/cygwin/poll.cc
index 89a3124d1..36c61cfcc 100644
--- a/winsup/cygwin/poll.cc
+++ b/winsup/cygwin/poll.cc
@@ -11,6 +11,7 @@
#include "winsup.h"
#include <sys/time.h>
#include <sys/poll.h>
+#include <sys/socket.h>
#include <errno.h>
#include <stdlib.h>
#include "security.h"
@@ -85,7 +86,27 @@ poll (struct pollfd *fds, unsigned int nfds, int timeout)
else
{
if (FD_ISSET(fds[i].fd, read_fds))
- fds[i].revents |= POLLIN;
+ {
+ char peek[1];
+ fhandler_socket *sock =
+ cygheap->fdtab[fds[i].fd]->is_socket ();
+ if (!sock)
+ fds[i].revents |= POLLIN;
+ else
+ switch (sock->recvfrom (peek, sizeof(peek), MSG_PEEK,
+ NULL, NULL))
+ {
+ case -1: /* Something weird happened */
+ fds[i].revents |= POLLERR;
+ break;
+ case 0: /* Closed on the read side. */
+ fds[i].revents |= POLLHUP;
+ break;
+ default:
+ fds[i].revents |= POLLIN;
+ break;
+ }
+ }
if (FD_ISSET(fds[i].fd, write_fds))
fds[i].revents |= POLLOUT;
if (FD_ISSET(fds[i].fd, except_fds))