mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-28 03:27:46 +08:00
* 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.
This commit is contained in:
parent
64508b36f9
commit
d4d59223ed
@ -1,3 +1,16 @@
|
|||||||
|
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>
|
2002-08-28 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
* malloc.cc: Protect some definitions to avoid a compile time warning.
|
* malloc.cc: Protect some definitions to avoid a compile time warning.
|
||||||
|
@ -8,18 +8,36 @@ details. */
|
|||||||
|
|
||||||
#include "winsup.h"
|
#include "winsup.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
#include "security.h"
|
#include "security.h"
|
||||||
#include "cygthread.h"
|
#include "cygthread.h"
|
||||||
|
|
||||||
#undef CloseHandle
|
#undef CloseHandle
|
||||||
|
|
||||||
static cygthread NO_COPY threads[8];
|
static cygthread NO_COPY threads[6];
|
||||||
#define NTHREADS (sizeof (threads) / sizeof (threads[0]))
|
#define NTHREADS (sizeof (threads) / sizeof (threads[0]))
|
||||||
|
|
||||||
static HANDLE NO_COPY hthreads[NTHREADS];
|
|
||||||
|
|
||||||
DWORD NO_COPY cygthread::main_thread_id;
|
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
|
/* Initial stub called by cygthread constructor. Performs initial
|
||||||
per-thread initialization and loops waiting for new thread functions
|
per-thread initialization and loops waiting for new thread functions
|
||||||
@ -60,9 +78,9 @@ DWORD WINAPI
|
|||||||
cygthread::runner (VOID *arg)
|
cygthread::runner (VOID *arg)
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < NTHREADS; i++)
|
for (unsigned i = 0; i < NTHREADS; i++)
|
||||||
hthreads[i] = threads[i].h =
|
threads[i].h = CreateThread (&sec_none_nih, 0, cygthread::stub, &threads[i],
|
||||||
CreateThread (&sec_none_nih, 0, cygthread::stub, &threads[i],
|
CREATE_SUSPENDED, &threads[i].avail);
|
||||||
CREATE_SUSPENDED, &threads[i].avail);
|
cygthread::initialized = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +108,17 @@ cygthread::is ()
|
|||||||
return 0;
|
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
|
void * cygthread::operator
|
||||||
new (size_t)
|
new (size_t)
|
||||||
{
|
{
|
||||||
@ -110,8 +139,10 @@ new (size_t)
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* thread_runner may not be finished yet. */
|
if (!initialized)
|
||||||
Sleep (0);
|
Sleep (0); /* thread_runner is not be finished yet. */
|
||||||
|
else
|
||||||
|
return freerange ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +210,8 @@ HANDLE ()
|
|||||||
void
|
void
|
||||||
cygthread::exit_thread ()
|
cygthread::exit_thread ()
|
||||||
{
|
{
|
||||||
SetEvent (*this);
|
if (!is_freerange)
|
||||||
|
SetEvent (*this);
|
||||||
ExitThread (0);
|
ExitThread (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,10 +236,18 @@ cygthread::detach ()
|
|||||||
DWORD res = WaitForSingleObject (*this, INFINITE);
|
DWORD res = WaitForSingleObject (*this, INFINITE);
|
||||||
thread_printf ("WFSO returns %d, id %p", res, id);
|
thread_printf ("WFSO returns %d, id %p", res, id);
|
||||||
}
|
}
|
||||||
ResetEvent (*this);
|
if (is_freerange)
|
||||||
id = 0;
|
{
|
||||||
__name = NULL;
|
CloseHandle (h);
|
||||||
/* Mark the thread as available by setting avail to non-zero */
|
free (this);
|
||||||
(void) InterlockedExchange ((LPLONG) &this->avail, avail);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ResetEvent (*this);
|
||||||
|
id = 0;
|
||||||
|
__name = NULL;
|
||||||
|
/* Mark the thread as available by setting avail to non-zero */
|
||||||
|
(void) InterlockedExchange ((LPLONG) &this->avail, avail);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,13 @@ class cygthread
|
|||||||
const char *__name;
|
const char *__name;
|
||||||
LPTHREAD_START_ROUTINE func;
|
LPTHREAD_START_ROUTINE func;
|
||||||
VOID *arg;
|
VOID *arg;
|
||||||
|
bool is_freerange;
|
||||||
static DWORD main_thread_id;
|
static DWORD main_thread_id;
|
||||||
|
static bool initialized;
|
||||||
static DWORD WINAPI runner (VOID *);
|
static DWORD WINAPI runner (VOID *);
|
||||||
|
static DWORD WINAPI free_runner (VOID *);
|
||||||
static DWORD WINAPI stub (VOID *);
|
static DWORD WINAPI stub (VOID *);
|
||||||
|
static DWORD WINAPI simplestub (VOID *);
|
||||||
public:
|
public:
|
||||||
static const char * name (DWORD = 0);
|
static const char * name (DWORD = 0);
|
||||||
cygthread (LPTHREAD_START_ROUTINE, LPVOID, const char *);
|
cygthread (LPTHREAD_START_ROUTINE, LPVOID, const char *);
|
||||||
@ -27,6 +31,7 @@ class cygthread
|
|||||||
operator HANDLE ();
|
operator HANDLE ();
|
||||||
static bool is ();
|
static bool is ();
|
||||||
void * operator new (size_t);
|
void * operator new (size_t);
|
||||||
|
static void * freerange ();
|
||||||
void exit_thread ();
|
void exit_thread ();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user