mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-17 15:44:34 +02:00
2004-12-14 Timo Schulz <twoaday@g10code.com>
* w32-pth.c (pth_kill): Just release the crit section if pth_init was really called. And set all handles to NULL. (_pth_strerror): New. (do_pth_wait): Before we enter the loop we check if there are too much events in the ring.
This commit is contained in:
parent
2946819dfc
commit
4becd8ddcc
@ -1,3 +1,11 @@
|
|||||||
|
2004-12-14 Timo Schulz <twoaday@g10code.com>
|
||||||
|
|
||||||
|
* w32-pth.c (pth_kill): Just release the crit section if
|
||||||
|
pth_init was really called. And set all handles to NULL.
|
||||||
|
(_pth_strerror): New.
|
||||||
|
(do_pth_wait): Before we enter the loop we check if there
|
||||||
|
are too much events in the ring.
|
||||||
|
|
||||||
2004-12-14 Werner Koch <wk@g10code.com>
|
2004-12-14 Werner Koch <wk@g10code.com>
|
||||||
|
|
||||||
* w32-pth.h (pth_event_occured): Removed macro.
|
* w32-pth.h (pth_event_occured): Removed macro.
|
||||||
|
125
jnlib/w32-pth.c
125
jnlib/w32-pth.c
@ -127,14 +127,30 @@ pth_kill (void)
|
|||||||
{
|
{
|
||||||
pth_signo = 0;
|
pth_signo = 0;
|
||||||
if (pth_signo_ev)
|
if (pth_signo_ev)
|
||||||
CloseHandle (pth_signo_ev);
|
{
|
||||||
DeleteCriticalSection (&pth_shd);
|
CloseHandle (pth_signo_ev);
|
||||||
|
pth_signo_ev = NULL;
|
||||||
|
}
|
||||||
|
if (pth_initialized)
|
||||||
|
DeleteCriticalSection (&pth_shd);
|
||||||
WSACleanup ();
|
WSACleanup ();
|
||||||
pth_initialized = 0;
|
pth_initialized = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
_pth_strerror (void)
|
||||||
|
{
|
||||||
|
static char strerr[256];
|
||||||
|
|
||||||
|
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, (int)GetLastError (),
|
||||||
|
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
strerr, sizeof (strerr)-1, NULL);
|
||||||
|
return strerr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
enter_pth (const char *function)
|
enter_pth (const char *function)
|
||||||
{
|
{
|
||||||
@ -211,7 +227,11 @@ pth_read (int fd, void * buffer, size_t size)
|
|||||||
DWORD nread = 0;
|
DWORD nread = 0;
|
||||||
n = ReadFile ((HANDLE)fd, buffer, size, &nread, NULL);
|
n = ReadFile ((HANDLE)fd, buffer, size, &nread, NULL);
|
||||||
if (!n)
|
if (!n)
|
||||||
n = -1;
|
{
|
||||||
|
fprintf (stderr, "pth_read(%d) failed read from: %s.\n", fd,
|
||||||
|
_pth_strerror ());
|
||||||
|
n = -1;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
n = (int)nread;
|
n = (int)nread;
|
||||||
}
|
}
|
||||||
@ -238,22 +258,18 @@ pth_write (int fd, const void * buffer, size_t size)
|
|||||||
n = send (fd, buffer, size, 0);
|
n = send (fd, buffer, size, 0);
|
||||||
if (n == -1 && WSAGetLastError () == WSAENOTSOCK)
|
if (n == -1 && WSAGetLastError () == WSAENOTSOCK)
|
||||||
{
|
{
|
||||||
char strerr[256];
|
|
||||||
|
|
||||||
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, (int)GetLastError (),
|
|
||||||
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
||||||
strerr, sizeof (strerr)-1, NULL);
|
|
||||||
fprintf (stderr, "pth_write(%d) failed in send: %s\n", fd, strerr);
|
|
||||||
|
|
||||||
|
|
||||||
DWORD nwrite;
|
DWORD nwrite;
|
||||||
|
|
||||||
|
/* this is no real error because we first need to figure out if
|
||||||
|
we have a handle or a socket. */
|
||||||
|
/*fprintf (stderr, "pth_write(%d) failed in send: %s\n", fd,
|
||||||
|
_pth_strerror ());*/
|
||||||
|
|
||||||
n = WriteFile ((HANDLE)fd, buffer, size, &nwrite, NULL);
|
n = WriteFile ((HANDLE)fd, buffer, size, &nwrite, NULL);
|
||||||
if (!n)
|
if (!n)
|
||||||
{
|
{
|
||||||
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL,(int)GetLastError (),
|
fprintf (stderr, "pth_write(%d) failed in write: %s\n", fd,
|
||||||
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
|
_pth_strerror ());
|
||||||
strerr, sizeof (strerr)-1, NULL);
|
|
||||||
fprintf (stderr, "pth_write(%d) failed in write: %s\n", fd, strerr);
|
|
||||||
n = -1;
|
n = -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -344,17 +360,18 @@ pth_accept_ev (int fd, struct sockaddr *addr, int *addrlen,
|
|||||||
(WSAGetLastError () == WSAEINPROGRESS ||
|
(WSAGetLastError () == WSAEINPROGRESS ||
|
||||||
WSAGetLastError () == WSAEWOULDBLOCK))
|
WSAGetLastError () == WSAEWOULDBLOCK))
|
||||||
{
|
{
|
||||||
if (ev == NULL) {
|
if (ev == NULL)
|
||||||
ev = do_pth_event (PTH_EVENT_FD|PTH_UNTIL_FD_READABLE|PTH_MODE_STATIC,
|
{
|
||||||
&ev_key, fd);
|
ev = do_pth_event (PTH_EVENT_FD|PTH_UNTIL_FD_READABLE|
|
||||||
if (ev == NULL)
|
PTH_MODE_STATIC, &ev_key, fd);
|
||||||
{
|
if (ev == NULL)
|
||||||
leave_pth (__FUNCTION__);
|
{
|
||||||
return -1;
|
leave_pth (__FUNCTION__);
|
||||||
}
|
return -1;
|
||||||
if (ev_extra != NULL)
|
}
|
||||||
pth_event_concat (ev, ev_extra, NULL);
|
if (ev_extra != NULL)
|
||||||
}
|
pth_event_concat (ev, ev_extra, NULL);
|
||||||
|
}
|
||||||
/* Wait until accept has a chance. */
|
/* Wait until accept has a chance. */
|
||||||
do_pth_wait (ev);
|
do_pth_wait (ev);
|
||||||
if (ev_extra != NULL)
|
if (ev_extra != NULL)
|
||||||
@ -450,14 +467,15 @@ pth_mutex_acquire (pth_mutex_t *hd, int tryonly, pth_event_t ev_extra)
|
|||||||
if (ev_extra != NULL)
|
if (ev_extra != NULL)
|
||||||
pth_event_concat (ev, ev_extra, NULL);
|
pth_event_concat (ev, ev_extra, NULL);
|
||||||
pth_wait (ev);
|
pth_wait (ev);
|
||||||
if (ev_extra != NULL) {
|
if (ev_extra != NULL)
|
||||||
pth_event_isolate (ev);
|
{
|
||||||
if (do_pth_event_status(ev) == PTH_STATUS_PENDING)
|
pth_event_isolate (ev);
|
||||||
{
|
if (do_pth_event_status(ev) == PTH_STATUS_PENDING)
|
||||||
leave_pth (__FUNCTION__);
|
{
|
||||||
return -1;
|
leave_pth (__FUNCTION__);
|
||||||
}
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!(mutex->mx_state & PTH_MUTEX_LOCKED))
|
if (!(mutex->mx_state & PTH_MUTEX_LOCKED))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -895,10 +913,13 @@ helper_thread (void * ctx)
|
|||||||
{
|
{
|
||||||
struct _pth_priv_hd_s * c = ctx;
|
struct _pth_priv_hd_s * c = ctx;
|
||||||
|
|
||||||
leave_pth (__FUNCTION__);
|
if (c)
|
||||||
c->thread (c->arg);
|
{
|
||||||
enter_pth (__FUNCTION__);
|
leave_pth (__FUNCTION__);
|
||||||
free (c);
|
c->thread (c->arg);
|
||||||
|
enter_pth (__FUNCTION__);
|
||||||
|
free (c);
|
||||||
|
}
|
||||||
ExitThread (0);
|
ExitThread (0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1019,7 +1040,8 @@ do_pth_event_free (pth_event_t ev, int mode)
|
|||||||
while (ev)
|
while (ev)
|
||||||
{
|
{
|
||||||
n = ev->next;
|
n = ev->next;
|
||||||
CloseHandle (ev->hd); ev->hd = NULL;
|
CloseHandle (ev->hd);
|
||||||
|
ev->hd = NULL;
|
||||||
free (ev);
|
free (ev);
|
||||||
ev = n;
|
ev = n;
|
||||||
}
|
}
|
||||||
@ -1028,9 +1050,9 @@ do_pth_event_free (pth_event_t ev, int mode)
|
|||||||
{
|
{
|
||||||
ev->prev->next = ev->next;
|
ev->prev->next = ev->next;
|
||||||
ev->next->prev = ev->prev;
|
ev->next->prev = ev->prev;
|
||||||
CloseHandle (ev->hd); ev->hd = NULL;
|
CloseHandle (ev->hd);
|
||||||
|
ev->hd = NULL;
|
||||||
free (ev);
|
free (ev);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1061,14 +1083,14 @@ pth_event_isolate (pth_event_t ev)
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pth_event_count (pth_event_t ev)
|
_pth_event_count (pth_event_t ev)
|
||||||
{
|
{
|
||||||
pth_event_t p;
|
pth_event_t p;
|
||||||
int cnt=0;
|
int cnt=0;
|
||||||
|
|
||||||
if (!ev)
|
if (!ev)
|
||||||
return 0;
|
return 0;
|
||||||
for (p=ev; p; p = p->next)
|
for (p = ev; p; p = p->next)
|
||||||
cnt++;
|
cnt++;
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
@ -1103,7 +1125,10 @@ free_helper_threads (HANDLE *waitbuf, int *hdidx, int n)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i=0; i < n; i++)
|
for (i=0; i < n; i++)
|
||||||
CloseHandle (waitbuf[hdidx[i]]);
|
{
|
||||||
|
CloseHandle (waitbuf[hdidx[i]]);
|
||||||
|
waitbuf[hdidx[i]] = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1146,19 +1171,17 @@ do_pth_wait (pth_event_t ev)
|
|||||||
if (!ev)
|
if (!ev)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
n =_pth_event_count (ev);
|
||||||
|
if (n > MAXIMUM_WAIT_OBJECTS/2)
|
||||||
|
return -1;
|
||||||
|
|
||||||
attr = pth_attr_new ();
|
attr = pth_attr_new ();
|
||||||
pth_attr_set (attr, PTH_ATTR_JOINABLE, 1);
|
pth_attr_set (attr, PTH_ATTR_JOINABLE, 1);
|
||||||
pth_attr_set (attr, PTH_ATTR_STACK_SIZE, 4096);
|
pth_attr_set (attr, PTH_ATTR_STACK_SIZE, 4096);
|
||||||
|
|
||||||
fprintf (stderr, "pth_wait: cnt %d\n", pth_event_count (ev));
|
fprintf (stderr, "pth_wait: cnt %lu\n", n);
|
||||||
for (tmp = ev; tmp; tmp = tmp->next)
|
for (tmp = ev; tmp; tmp = tmp->next)
|
||||||
{
|
{
|
||||||
if (pos+1 > MAXIMUM_WAIT_OBJECTS/2)
|
|
||||||
{
|
|
||||||
free_helper_threads (waitbuf, hdidx, i);
|
|
||||||
pth_attr_destroy (attr);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
switch (tmp->u_type)
|
switch (tmp->u_type)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user