mirror of
git://git.gnupg.org/gnupg.git
synced 2024-07-01 02:42:44 +02:00
(do_pth_event_free): The events are hold in a ring
buffer. Adjust for that. (do_pth_event_body): Ditto. (pth_event_isolate): Ditto. (do_pth_wait): Ditto. (_pth_event_count): Renamed to .. (event_count): .. and adjusted as above. (pth_init): Define 3 debug levels and change all debug calls to make use of them. This makes the moule now silent.
This commit is contained in:
parent
18fd4964f6
commit
f105ceb39c
|
@ -1,3 +1,15 @@
|
||||||
|
2004-12-20 Werner Koch <wk@g10code.com>
|
||||||
|
|
||||||
|
* w32-pth.c (do_pth_event_free): The events are hold in a ring
|
||||||
|
buffer. Adjust for that.
|
||||||
|
(do_pth_event_body): Ditto.
|
||||||
|
(pth_event_isolate): Ditto.
|
||||||
|
(do_pth_wait): Ditto.
|
||||||
|
(_pth_event_count): Renamed to ..
|
||||||
|
(event_count): .. and adjusted as above.
|
||||||
|
(pth_init): Define 3 debug levels and change all debug calls to
|
||||||
|
make use of them. This makes the moule now silent.
|
||||||
|
|
||||||
2004-12-19 Werner Koch <wk@g10code.com>
|
2004-12-19 Werner Koch <wk@g10code.com>
|
||||||
|
|
||||||
* w32-pth.c (pth_init): Enable debugging depending on env var.
|
* w32-pth.c (pth_init): Enable debugging depending on env var.
|
||||||
|
|
250
jnlib/w32-pth.c
250
jnlib/w32-pth.c
|
@ -40,8 +40,6 @@
|
||||||
#define W32_PTH_HANDLE_INTERNAL HANDLE
|
#define W32_PTH_HANDLE_INTERNAL HANDLE
|
||||||
#include "w32-pth.h"
|
#include "w32-pth.h"
|
||||||
|
|
||||||
#define DEBUG_ENTER_LEAVE 1 /* Set to 1 to enable full debugging. */
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef FALSE
|
#ifndef FALSE
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
|
@ -54,11 +52,14 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* States whether trhis module has been initialized. */
|
/* States whether this module has been initialized. */
|
||||||
static int pth_initialized;
|
static int pth_initialized;
|
||||||
|
|
||||||
/* Controls whether debugging is enabled. */
|
/* Keeps the current debug level. Define marcos to test them. */
|
||||||
static int debug_enter_leave;
|
static int debug_level;
|
||||||
|
#define DBG_ERROR (debug_level >= 1)
|
||||||
|
#define DBG_INFO (debug_level >= 2)
|
||||||
|
#define DBG_CALLS (debug_level >= 3)
|
||||||
|
|
||||||
/* Variables to support event handling. */
|
/* Variables to support event handling. */
|
||||||
static int pth_signo;
|
static int pth_signo;
|
||||||
|
@ -67,7 +68,7 @@ static HANDLE pth_signo_ev;
|
||||||
/* Mutex to make sure only one thread is running. */
|
/* Mutex to make sure only one thread is running. */
|
||||||
static CRITICAL_SECTION pth_shd;
|
static CRITICAL_SECTION pth_shd;
|
||||||
|
|
||||||
|
/* Events are store in a double linked event ring. */
|
||||||
struct pth_event_s
|
struct pth_event_s
|
||||||
{
|
{
|
||||||
struct pth_event_s * next;
|
struct pth_event_s * next;
|
||||||
|
@ -124,12 +125,14 @@ pth_init (void)
|
||||||
{
|
{
|
||||||
SECURITY_ATTRIBUTES sa;
|
SECURITY_ATTRIBUTES sa;
|
||||||
WSADATA wsadat;
|
WSADATA wsadat;
|
||||||
|
const char *s;
|
||||||
|
|
||||||
if (pth_initialized)
|
if (pth_initialized)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
fprintf (stderr, "%s: pth_init: called.\n", log_get_prefix (NULL));
|
debug_level = (s=getenv ("DEBUG_PTH"))? atoi (s):0;
|
||||||
debug_enter_leave = !!getenv ("DEBUG_PTH");
|
if (debug_level)
|
||||||
|
fprintf (stderr, "%s: pth_init: called.\n", log_get_prefix (NULL));
|
||||||
|
|
||||||
if (WSAStartup (0x202, &wsadat))
|
if (WSAStartup (0x202, &wsadat))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -184,7 +187,7 @@ enter_pth (const char *function)
|
||||||
{
|
{
|
||||||
/* Fixme: I am not sure whether the same thread my enter a critical
|
/* Fixme: I am not sure whether the same thread my enter a critical
|
||||||
section twice. */
|
section twice. */
|
||||||
if (debug_enter_leave)
|
if (DBG_CALLS)
|
||||||
fprintf (stderr, "%s: enter_pth (%s)\n",
|
fprintf (stderr, "%s: enter_pth (%s)\n",
|
||||||
log_get_prefix (NULL), function? function:"");
|
log_get_prefix (NULL), function? function:"");
|
||||||
LeaveCriticalSection (&pth_shd);
|
LeaveCriticalSection (&pth_shd);
|
||||||
|
@ -195,7 +198,7 @@ static void
|
||||||
leave_pth (const char *function)
|
leave_pth (const char *function)
|
||||||
{
|
{
|
||||||
EnterCriticalSection (&pth_shd);
|
EnterCriticalSection (&pth_shd);
|
||||||
if (debug_enter_leave)
|
if (DBG_CALLS)
|
||||||
fprintf (stderr, "%s: leave_pth (%s)\n",
|
fprintf (stderr, "%s: leave_pth (%s)\n",
|
||||||
log_get_prefix (NULL), function? function:"");
|
log_get_prefix (NULL), function? function:"");
|
||||||
}
|
}
|
||||||
|
@ -262,9 +265,10 @@ pth_read (int fd, void * buffer, size_t size)
|
||||||
{
|
{
|
||||||
char strerr[256];
|
char strerr[256];
|
||||||
|
|
||||||
fprintf (stderr, "%s: pth_read(%d) failed read from file: %s\n",
|
if (DBG_ERROR)
|
||||||
log_get_prefix (NULL), fd,
|
fprintf (stderr, "%s: pth_read(%d) failed read from file: %s\n",
|
||||||
w32_strerror (strerr, sizeof strerr));
|
log_get_prefix (NULL), fd,
|
||||||
|
w32_strerror (strerr, sizeof strerr));
|
||||||
n = -1;
|
n = -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -302,9 +306,10 @@ pth_write (int fd, const void * buffer, size_t size)
|
||||||
n = WriteFile ((HANDLE)fd, buffer, size, &nwrite, NULL);
|
n = WriteFile ((HANDLE)fd, buffer, size, &nwrite, NULL);
|
||||||
if (!n)
|
if (!n)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s: pth_write(%d) failed in write: %s\n",
|
if (DBG_ERROR)
|
||||||
log_get_prefix (NULL), fd,
|
fprintf (stderr, "%s: pth_write(%d) failed in write: %s\n",
|
||||||
w32_strerror (strerr, sizeof strerr));
|
log_get_prefix (NULL), fd,
|
||||||
|
w32_strerror (strerr, sizeof strerr));
|
||||||
n = -1;
|
n = -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -395,21 +400,21 @@ pth_accept_ev (int fd, struct sockaddr *addr, int *addrlen,
|
||||||
(WSAGetLastError () == WSAEINPROGRESS ||
|
(WSAGetLastError () == WSAEINPROGRESS ||
|
||||||
WSAGetLastError () == WSAEWOULDBLOCK))
|
WSAGetLastError () == WSAEWOULDBLOCK))
|
||||||
{
|
{
|
||||||
if (ev == NULL)
|
if (!ev)
|
||||||
{
|
{
|
||||||
ev = do_pth_event (PTH_EVENT_FD|PTH_UNTIL_FD_READABLE|
|
ev = do_pth_event (PTH_EVENT_FD|PTH_UNTIL_FD_READABLE|
|
||||||
PTH_MODE_STATIC, &ev_key, fd);
|
PTH_MODE_STATIC, &ev_key, fd);
|
||||||
if (ev == NULL)
|
if (!ev)
|
||||||
{
|
{
|
||||||
leave_pth (__FUNCTION__);
|
leave_pth (__FUNCTION__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (ev_extra != NULL)
|
if (ev_extra)
|
||||||
pth_event_concat (ev, 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)
|
||||||
{
|
{
|
||||||
pth_event_isolate (ev);
|
pth_event_isolate (ev);
|
||||||
if (do_pth_event_status (ev) != PTH_STATUS_OCCURRED)
|
if (do_pth_event_status (ev) != PTH_STATUS_OCCURRED)
|
||||||
|
@ -452,9 +457,10 @@ pth_mutex_release (pth_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
char strerr[256];
|
char strerr[256];
|
||||||
|
|
||||||
fprintf (stderr, "%s: pth_release_mutex %p failed: %s\n",
|
if (DBG_ERROR)
|
||||||
log_get_prefix (NULL), *mutex,
|
fprintf (stderr, "%s: pth_release_mutex %p failed: %s\n",
|
||||||
w32_strerror (strerr, sizeof strerr));
|
log_get_prefix (NULL), *mutex,
|
||||||
|
w32_strerror (strerr, sizeof strerr));
|
||||||
rc = FALSE;
|
rc = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -483,9 +489,10 @@ pth_mutex_acquire (pth_mutex_t *mutex, int tryonly, pth_event_t ev_extra)
|
||||||
{
|
{
|
||||||
char strerr[256];
|
char strerr[256];
|
||||||
|
|
||||||
fprintf (stderr, "%s: pth_mutex_acquire for %p failed: %s\n",
|
if (DBG_ERROR)
|
||||||
log_get_prefix (NULL), *mutex,
|
fprintf (stderr, "%s: pth_mutex_acquire for %p failed: %s\n",
|
||||||
w32_strerror (strerr, sizeof strerr));
|
log_get_prefix (NULL), *mutex,
|
||||||
|
w32_strerror (strerr, sizeof strerr));
|
||||||
}
|
}
|
||||||
rc = FALSE;
|
rc = FALSE;
|
||||||
break;
|
break;
|
||||||
|
@ -495,9 +502,10 @@ pth_mutex_acquire (pth_mutex_t *mutex, int tryonly, pth_event_t ev_extra)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf (stderr, "%s: WaitForSingleObject returned unexpected "
|
if (DBG_ERROR)
|
||||||
"code %d for mutex %p\n",
|
fprintf (stderr, "%s: WaitForSingleObject returned unexpected "
|
||||||
log_get_prefix (NULL), code, *mutex);
|
"code %d for mutex %p\n",
|
||||||
|
log_get_prefix (NULL), code, *mutex);
|
||||||
rc = FALSE;
|
rc = FALSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -576,8 +584,9 @@ pth_attr_set (pth_attr_t hd, int field, ...)
|
||||||
if (val)
|
if (val)
|
||||||
{
|
{
|
||||||
hd->flags |= PTH_ATTR_JOINABLE;
|
hd->flags |= PTH_ATTR_JOINABLE;
|
||||||
fprintf (stderr, "%s: pth_attr_set: PTH_ATTR_JOINABLE\n",
|
if (DBG_INFO)
|
||||||
log_get_prefix (NULL));
|
fprintf (stderr, "%s: pth_attr_set: PTH_ATTR_JOINABLE\n",
|
||||||
|
log_get_prefix (NULL));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -587,8 +596,9 @@ pth_attr_set (pth_attr_t hd, int field, ...)
|
||||||
{
|
{
|
||||||
hd->flags |= PTH_ATTR_STACK_SIZE;
|
hd->flags |= PTH_ATTR_STACK_SIZE;
|
||||||
hd->stack_size = val;
|
hd->stack_size = val;
|
||||||
fprintf (stderr, "%s: pth_attr_set: PTH_ATTR_STACK_SIZE %d\n",
|
if (DBG_INFO)
|
||||||
log_get_prefix (NULL), val);
|
fprintf (stderr, "%s: pth_attr_set: PTH_ATTR_STACK_SIZE %d\n",
|
||||||
|
log_get_prefix (NULL), val);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -602,8 +612,9 @@ pth_attr_set (pth_attr_t hd, int field, ...)
|
||||||
if (!hd->name)
|
if (!hd->name)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
hd->flags |= PTH_ATTR_NAME;
|
hd->flags |= PTH_ATTR_NAME;
|
||||||
fprintf (stderr, "%s: pth_attr_set: PTH_ATTR_NAME %s\n",
|
if (DBG_INFO)
|
||||||
log_get_prefix (NULL), hd->name);
|
fprintf (stderr, "%s: pth_attr_set: PTH_ATTR_NAME %s\n",
|
||||||
|
log_get_prefix (NULL), hd->name);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -647,14 +658,16 @@ do_pth_spawn (pth_attr_t hd, void *(*func)(void *), void *arg)
|
||||||
|
|
||||||
FIXME: We should no use th W32's Thread handle directly but keep
|
FIXME: We should no use th W32's Thread handle directly but keep
|
||||||
our own thread control structure. CTX may be used for that. */
|
our own thread control structure. CTX may be used for that. */
|
||||||
fprintf (stderr, "%s: do_pth_spawn creating thread ...\n",
|
if (DBG_INFO)
|
||||||
log_get_prefix (NULL));
|
fprintf (stderr, "%s: do_pth_spawn creating thread ...\n",
|
||||||
|
log_get_prefix (NULL));
|
||||||
th = CreateThread (&sa, hd->stack_size,
|
th = CreateThread (&sa, hd->stack_size,
|
||||||
(LPTHREAD_START_ROUTINE)launch_thread,
|
(LPTHREAD_START_ROUTINE)launch_thread,
|
||||||
ctx, CREATE_SUSPENDED, &tid);
|
ctx, CREATE_SUSPENDED, &tid);
|
||||||
ctx->th = th;
|
ctx->th = th;
|
||||||
fprintf (stderr, "%s: do_pth_spawn created thread %p\n",
|
if (DBG_INFO)
|
||||||
log_get_prefix (NULL),th);
|
fprintf (stderr, "%s: do_pth_spawn created thread %p\n",
|
||||||
|
log_get_prefix (NULL),th);
|
||||||
if (!th)
|
if (!th)
|
||||||
free (ctx);
|
free (ctx);
|
||||||
else
|
else
|
||||||
|
@ -787,7 +800,8 @@ sig_handler (DWORD signo)
|
||||||
case CTRL_BREAK_EVENT: pth_signo = SIGTERM; break;
|
case CTRL_BREAK_EVENT: pth_signo = SIGTERM; break;
|
||||||
}
|
}
|
||||||
SetEvent (pth_signo_ev);
|
SetEvent (pth_signo_ev);
|
||||||
fprintf (stderr, "%s: sig_handler=%d\n", log_get_prefix (NULL), pth_signo);
|
if (DBG_INFO)
|
||||||
|
fprintf (stderr, "%s: sig_handler=%d\n", log_get_prefix (NULL), pth_signo);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -799,7 +813,8 @@ do_pth_event_body (unsigned long spec, va_list arg)
|
||||||
pth_event_t ev;
|
pth_event_t ev;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
fprintf (stderr, "%s: pth_event spec=%lu\n", log_get_prefix (NULL), spec);
|
if (DBG_INFO)
|
||||||
|
fprintf (stderr, "%s: pth_event spec=%lu\n", log_get_prefix (NULL), spec);
|
||||||
ev = calloc (1, sizeof *ev);
|
ev = calloc (1, sizeof *ev);
|
||||||
if (!ev)
|
if (!ev)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -811,8 +826,9 @@ do_pth_event_body (unsigned long spec, va_list arg)
|
||||||
ev->u_type = PTH_EVENT_SIGS;
|
ev->u_type = PTH_EVENT_SIGS;
|
||||||
ev->val = va_arg (arg, int *);
|
ev->val = va_arg (arg, int *);
|
||||||
rc = SetConsoleCtrlHandler (sig_handler, TRUE);
|
rc = SetConsoleCtrlHandler (sig_handler, TRUE);
|
||||||
fprintf (stderr, "%s: pth_event: sigs rc=%d\n",
|
if (DBG_INFO)
|
||||||
log_get_prefix (NULL), rc);
|
fprintf (stderr, "%s: pth_event: sigs rc=%d\n",
|
||||||
|
log_get_prefix (NULL), rc);
|
||||||
}
|
}
|
||||||
else if (spec & PTH_EVENT_FD)
|
else if (spec & PTH_EVENT_FD)
|
||||||
{
|
{
|
||||||
|
@ -823,8 +839,9 @@ do_pth_event_body (unsigned long spec, va_list arg)
|
||||||
ev->u_type = PTH_EVENT_FD;
|
ev->u_type = PTH_EVENT_FD;
|
||||||
va_arg (arg, pth_key_t);
|
va_arg (arg, pth_key_t);
|
||||||
ev->u.fd = va_arg (arg, int);
|
ev->u.fd = va_arg (arg, int);
|
||||||
fprintf (stderr, "%s: pth_event: fd=%d\n",
|
if (DBG_INFO)
|
||||||
log_get_prefix (NULL), ev->u.fd);
|
fprintf (stderr, "%s: pth_event: fd=%d\n",
|
||||||
|
log_get_prefix (NULL), ev->u.fd);
|
||||||
}
|
}
|
||||||
else if (spec & PTH_EVENT_TIME)
|
else if (spec & PTH_EVENT_TIME)
|
||||||
{
|
{
|
||||||
|
@ -854,6 +871,8 @@ do_pth_event_body (unsigned long spec, va_list arg)
|
||||||
free (ev);
|
free (ev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
ev->next = ev;
|
||||||
|
ev->prev = ev;
|
||||||
|
|
||||||
return ev;
|
return ev;
|
||||||
}
|
}
|
||||||
|
@ -938,8 +957,9 @@ wait_for_fd (int fd, int is_read, int nwait)
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
n = select (fd+1, &r, &w, NULL, &tv);
|
n = select (fd+1, &r, &w, NULL, &tv);
|
||||||
fprintf (stderr, "%s: wait_for_fd=%d fd %d (ec=%d)\n",
|
if (DBG_INFO)
|
||||||
log_get_prefix (NULL), n, fd,(int)WSAGetLastError ());
|
fprintf (stderr, "%s: wait_for_fd=%d fd %d (ec=%d)\n",
|
||||||
|
log_get_prefix (NULL), n, fd,(int)WSAGetLastError ());
|
||||||
if (n == -1)
|
if (n == -1)
|
||||||
break;
|
break;
|
||||||
if (!n)
|
if (!n)
|
||||||
|
@ -1036,8 +1056,9 @@ do_pth_event_occurred (pth_event_t ev)
|
||||||
if (sigpresent (ev->u.sig, pth_signo) &&
|
if (sigpresent (ev->u.sig, pth_signo) &&
|
||||||
WaitForSingleObject (pth_signo_ev, 0) == WAIT_OBJECT_0)
|
WaitForSingleObject (pth_signo_ev, 0) == WAIT_OBJECT_0)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s: pth_event_occurred: sig signaled.\n",
|
if (DBG_INFO)
|
||||||
log_get_prefix (NULL));
|
fprintf (stderr, "%s: pth_event_occurred: sig signaled.\n",
|
||||||
|
log_get_prefix (NULL));
|
||||||
(*ev->val) = pth_signo;
|
(*ev->val) = pth_signo;
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
@ -1090,18 +1111,21 @@ pth_event_status (pth_event_t ev)
|
||||||
static int
|
static int
|
||||||
do_pth_event_free (pth_event_t ev, int mode)
|
do_pth_event_free (pth_event_t ev, int mode)
|
||||||
{
|
{
|
||||||
pth_event_t n;
|
if (!ev)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
if (mode == PTH_FREE_ALL)
|
if (mode == PTH_FREE_ALL)
|
||||||
{
|
{
|
||||||
while (ev)
|
pth_event_t cur = ev;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
n = ev->next;
|
pth_event_t next = cur->next;
|
||||||
CloseHandle (ev->hd);
|
CloseHandle (cur->hd);
|
||||||
ev->hd = NULL;
|
cur->hd = NULL;
|
||||||
free (ev);
|
free (cur);
|
||||||
ev = n;
|
cur = next;
|
||||||
}
|
}
|
||||||
|
while (cur != ev);
|
||||||
}
|
}
|
||||||
else if (mode == PTH_FREE_THIS)
|
else if (mode == PTH_FREE_THIS)
|
||||||
{
|
{
|
||||||
|
@ -1111,6 +1135,8 @@ do_pth_event_free (pth_event_t ev, int mode)
|
||||||
ev->hd = NULL;
|
ev->hd = NULL;
|
||||||
free (ev);
|
free (ev);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -1131,24 +1157,39 @@ pth_event_free (pth_event_t ev, int mode)
|
||||||
pth_event_t
|
pth_event_t
|
||||||
pth_event_isolate (pth_event_t ev)
|
pth_event_isolate (pth_event_t ev)
|
||||||
{
|
{
|
||||||
pth_event_t ring = NULL;
|
pth_event_t ring;
|
||||||
|
|
||||||
if (!ev)
|
if (!ev)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (ev->next == ev && ev->prev == ev)
|
||||||
|
return NULL; /* Only one event. */
|
||||||
|
|
||||||
|
ring = ev->next;
|
||||||
|
ev->prev->next = ev->next;
|
||||||
|
ev->next->prev = ev->prev;
|
||||||
|
ev->prev = ev;
|
||||||
|
ev->next = ev;
|
||||||
return ring;
|
return ring;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_pth_event_count (pth_event_t ev)
|
event_count (pth_event_t ev)
|
||||||
{
|
{
|
||||||
pth_event_t p;
|
pth_event_t r;
|
||||||
int cnt=0;
|
int cnt = 0;
|
||||||
|
|
||||||
|
if (ev)
|
||||||
|
{
|
||||||
|
r = ev;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
cnt++;
|
||||||
|
r = r->next;
|
||||||
|
}
|
||||||
|
while (r != ev);
|
||||||
|
}
|
||||||
|
|
||||||
if (!ev)
|
|
||||||
return 0;
|
|
||||||
for (p = ev; p; p = p->next)
|
|
||||||
cnt++;
|
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1166,13 +1207,15 @@ spawn_helper_thread (void *(*func)(void *), void *arg)
|
||||||
sa.lpSecurityDescriptor = NULL;
|
sa.lpSecurityDescriptor = NULL;
|
||||||
sa.nLength = sizeof sa;
|
sa.nLength = sizeof sa;
|
||||||
|
|
||||||
fprintf (stderr, "%s: spawn_helper_thread creating thread ...\n",
|
if (DBG_INFO)
|
||||||
log_get_prefix (NULL));
|
fprintf (stderr, "%s: spawn_helper_thread creating thread ...\n",
|
||||||
|
log_get_prefix (NULL));
|
||||||
th = CreateThread (&sa, 32*1024,
|
th = CreateThread (&sa, 32*1024,
|
||||||
(LPTHREAD_START_ROUTINE)func,
|
(LPTHREAD_START_ROUTINE)func,
|
||||||
arg, 0, &tid);
|
arg, 0, &tid);
|
||||||
fprintf (stderr, "%s: spawn_helper_thread created thread %p\n",
|
if (DBG_INFO)
|
||||||
log_get_prefix (NULL), th);
|
fprintf (stderr, "%s: spawn_helper_thread created thread %p\n",
|
||||||
|
log_get_prefix (NULL), th);
|
||||||
|
|
||||||
return th;
|
return th;
|
||||||
}
|
}
|
||||||
|
@ -1197,7 +1240,8 @@ wait_fd_thread (void * ctx)
|
||||||
pth_event_t ev = ctx;
|
pth_event_t ev = ctx;
|
||||||
|
|
||||||
wait_for_fd (ev->u.fd, ev->flags & PTH_UNTIL_FD_READABLE, 3600);
|
wait_for_fd (ev->u.fd, ev->flags & PTH_UNTIL_FD_READABLE, 3600);
|
||||||
fprintf (stderr, "%s: wait_fd_thread: exit.\n", log_get_prefix (NULL));
|
if (DBG_INFO)
|
||||||
|
fprintf (stderr, "%s: wait_fd_thread: exit.\n", log_get_prefix (NULL));
|
||||||
SetEvent (ev->hd);
|
SetEvent (ev->hd);
|
||||||
ExitThread (0);
|
ExitThread (0);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1211,7 +1255,8 @@ wait_timer_thread (void * ctx)
|
||||||
int n = ev->u.tv.tv_sec*1000;
|
int n = ev->u.tv.tv_sec*1000;
|
||||||
Sleep (n);
|
Sleep (n);
|
||||||
SetEvent (ev->hd);
|
SetEvent (ev->hd);
|
||||||
fprintf (stderr, "%s: wait_timer_thread: exit.\n", log_get_prefix (NULL));
|
if (DBG_INFO)
|
||||||
|
fprintf (stderr, "%s: wait_timer_thread: exit.\n", log_get_prefix (NULL));
|
||||||
ExitThread (0);
|
ExitThread (0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1223,51 +1268,62 @@ do_pth_wait (pth_event_t ev)
|
||||||
HANDLE waitbuf[MAXIMUM_WAIT_OBJECTS/2];
|
HANDLE waitbuf[MAXIMUM_WAIT_OBJECTS/2];
|
||||||
int hdidx[MAXIMUM_WAIT_OBJECTS/2];
|
int hdidx[MAXIMUM_WAIT_OBJECTS/2];
|
||||||
DWORD n = 0;
|
DWORD n = 0;
|
||||||
pth_event_t tmp;
|
|
||||||
int pos=0, i=0;
|
int pos=0, i=0;
|
||||||
|
|
||||||
if (!ev)
|
if (!ev)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
n =_pth_event_count (ev);
|
n = event_count (ev);
|
||||||
if (n > MAXIMUM_WAIT_OBJECTS/2)
|
if (n > MAXIMUM_WAIT_OBJECTS/2)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
fprintf (stderr, "%s: pth_wait: cnt %lu\n", log_get_prefix (NULL), n);
|
if (DBG_INFO)
|
||||||
for (tmp = ev; tmp; tmp = tmp->next)
|
fprintf (stderr, "%s: pth_wait: cnt %lu\n", log_get_prefix (NULL), n);
|
||||||
|
if (ev)
|
||||||
{
|
{
|
||||||
switch (tmp->u_type)
|
pth_event_t r = ev;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
case 0:
|
switch (r->u_type)
|
||||||
waitbuf[pos++] = tmp->hd;
|
{
|
||||||
break;
|
case 0:
|
||||||
|
waitbuf[pos++] = r->hd;
|
||||||
|
break;
|
||||||
|
|
||||||
case PTH_EVENT_SIGS:
|
case PTH_EVENT_SIGS:
|
||||||
waitbuf[pos++] = pth_signo_ev;
|
waitbuf[pos++] = pth_signo_ev;
|
||||||
fprintf (stderr, "pth_wait: add signal event.\n");
|
if (DBG_INFO)
|
||||||
break;
|
fprintf (stderr, "pth_wait: add signal event.\n");
|
||||||
|
break;
|
||||||
|
|
||||||
case PTH_EVENT_FD:
|
case PTH_EVENT_FD:
|
||||||
fprintf (stderr, "pth_wait: spawn event wait thread.\n");
|
if (DBG_INFO)
|
||||||
hdidx[i++] = pos;
|
fprintf (stderr, "pth_wait: spawn event wait thread.\n");
|
||||||
waitbuf[pos++] = spawn_helper_thread (wait_fd_thread, tmp);
|
hdidx[i++] = pos;
|
||||||
break;
|
waitbuf[pos++] = spawn_helper_thread (wait_fd_thread, r);
|
||||||
|
break;
|
||||||
|
|
||||||
case PTH_EVENT_TIME:
|
case PTH_EVENT_TIME:
|
||||||
fprintf (stderr, "pth_wait: spawn event timer thread.\n");
|
if (DBG_INFO)
|
||||||
hdidx[i++] = pos;
|
fprintf (stderr, "pth_wait: spawn event timer thread.\n");
|
||||||
waitbuf[pos++] = spawn_helper_thread (wait_timer_thread, tmp);
|
hdidx[i++] = pos;
|
||||||
break;
|
waitbuf[pos++] = spawn_helper_thread (wait_timer_thread, r);
|
||||||
|
break;
|
||||||
|
|
||||||
case PTH_EVENT_MUTEX:
|
case PTH_EVENT_MUTEX:
|
||||||
fprintf (stderr, "pth_wait: add mutex event.\n");
|
if (DBG_INFO)
|
||||||
break;
|
fprintf (stderr, "pth_wait: ignoring mutex event.\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
while ( r != ev );
|
||||||
}
|
}
|
||||||
fprintf (stderr, "%s: pth_wait: set %d\n", log_get_prefix (NULL), pos);
|
if (DBG_INFO)
|
||||||
|
fprintf (stderr, "%s: pth_wait: set %d\n", log_get_prefix (NULL), pos);
|
||||||
n = WaitForMultipleObjects (pos, waitbuf, FALSE, INFINITE);
|
n = WaitForMultipleObjects (pos, waitbuf, FALSE, INFINITE);
|
||||||
free_helper_threads (waitbuf, hdidx, i);
|
free_helper_threads (waitbuf, hdidx, i);
|
||||||
fprintf (stderr, "%s: pth_wait: n %ld\n", log_get_prefix (NULL), n);
|
if (DBG_INFO)
|
||||||
|
fprintf (stderr, "%s: pth_wait: n %ld\n", log_get_prefix (NULL), n);
|
||||||
|
|
||||||
if (n != WAIT_TIMEOUT)
|
if (n != WAIT_TIMEOUT)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user