-/* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* If you do not wish that, delete this exception notice. */
\f
-/* $Id: coop.c,v 1.25 2000-04-21 14:16:30 mdj Exp $ */
+/* $Id: coop.c,v 1.29 2001-11-04 15:52:29 ela Exp $ */
/* Cooperative thread library, based on QuickThreads */
+#include <stdio.h>
+
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
static pthread_cond_t coop_cond_create;
static pthread_mutex_t coop_mutex_create;
static pthread_t coop_mother;
+static int mother_awake_p = 0;
static coop_t *coop_child;
#endif
const struct timespec *abstime)
{
coop_t *old, *t;
+#ifdef ETIMEDOUT
int res = ETIMEDOUT;
+#elif defined (WSAETIMEDOUT)
+ int res = WSAETIMEDOUT;
+#else
+ int res = 0;
+#endif
/* coop_mutex_unlock (m); */
t = coop_qget (&(m->waiting));
NULL,
dummy_start,
coop_child);
+ mother_awake_p = 0;
do
res = pthread_cond_wait (&coop_cond_create, &coop_mutex_create);
while (res == EINTR);
t->n_keys = 0;
#ifdef GUILE_PTHREAD_COMPAT
coop_child = t;
+ mother_awake_p = 1;
if (coop_quitting_p < 0)
{
coop_quitting_p = 0;
* condition variable because they are not safe against
* pre-emptive switching.
*/
- while (coop_child)
+ while (coop_child || mother_awake_p)
usleep (0);
#else
t->sto = malloc (COOP_STKSIZE);
{
coop_t *oldthread = (coop_t *) old;
-#if 0
- /* Marking old->base NULL indicates that this thread is dead */
- oldthread->base = NULL;
-#endif
-
if (oldthread->specific)
free (oldthread->specific);
#ifndef GUILE_PTHREAD_COMPAT
{
coop_t *old, *newthread;
- /* Check if t is already finished */
- if (t->base == NULL)
- return;
-
/* Create a join list if necessary */
if (t->joining == NULL)
{
{
/* We're so cheap. */
scm_thread_sleep (usec / 1000000);
- struct timeval timeout;
return 0; /* Maybe we should calculate actual time slept,
but this is faster... :) */
}