2000-03-12 00:33:56 +00:00
|
|
|
|
/* Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
*
|
|
|
|
|
|
* 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
|
|
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
|
* any later version.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
|
* along with this software; see the file COPYING. If not, write to
|
1997-05-26 22:34:48 +00:00
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
|
|
|
|
* Boston, MA 02111-1307 USA
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
*
|
|
|
|
|
|
* As a special exception, the Free Software Foundation gives permission
|
|
|
|
|
|
* for additional uses of the text contained in its release of GUILE.
|
|
|
|
|
|
*
|
|
|
|
|
|
* The exception is that, if you link the GUILE library with other files
|
|
|
|
|
|
* to produce an executable, this does not by itself cause the
|
|
|
|
|
|
* resulting executable to be covered by the GNU General Public License.
|
|
|
|
|
|
* Your use of that executable is in no way restricted on account of
|
|
|
|
|
|
* linking the GUILE library code into it.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This exception does not however invalidate any other reasons why
|
|
|
|
|
|
* the executable file might be covered by the GNU General Public License.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This exception applies only to the code released by the
|
|
|
|
|
|
* Free Software Foundation under the name GUILE. If you copy
|
|
|
|
|
|
* code from other Free Software Foundation releases into a copy of
|
|
|
|
|
|
* GUILE, as the General Public License permits, the exception does
|
|
|
|
|
|
* not apply to the code that you add in this way. To avoid misleading
|
|
|
|
|
|
* anyone as to the status of such modified files, you must delete
|
|
|
|
|
|
* this exception notice from them.
|
|
|
|
|
|
*
|
|
|
|
|
|
* If you write modifications of your own for GUILE, it is your choice
|
|
|
|
|
|
* whether to permit this exception to apply to your modifications.
|
1997-05-26 22:34:48 +00:00
|
|
|
|
* If you do not wish that, delete this exception notice. */
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
2000-03-12 00:33:56 +00:00
|
|
|
|
/* $Id: coop.c,v 1.17 2000-03-12 00:33:56 mdj Exp $ */
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
|
|
|
|
|
|
/* Cooperative thread library, based on QuickThreads */
|
|
|
|
|
|
|
Get rid of warnings from the cooperative threading system.
* threads.h (scm_single_thread_p, scm_yield,
scm_call_with_new_thread, scm_join_thread, scm_make_mutex,
scm_lock_mutex, scm_unlock_mutex, scm_make_condition_variable,
scm_wait_condition_variable, scm_signal_condition_variable): Add
prototypes for these Scheme-visible functions.
* coop-defs.h (coop_next_runnable_thread,
coop_wait_for_runnable_thread_now, coop_wait_for_runnable_thread):
Prototypes for these here, even though they're from iselect.c.
(coop_condition_variable_wait, coop_join): Add prototypes.
* coop-threads.c (scm_threads_free_thread, scm_threads_free_mutex,
scm_threads_free_condvar): Make these smob functions static.
* coop-threads.h (coop_init): Give this a real prototype.
* coop.c: #include <unistd.h>, if we have it, for `usleep' and `sleep'.
(coop_next_runnable_thread): No need to provide prototype; it's in
coop-defs.h.
1998-10-03 13:33:53 +00:00
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2000-03-12 00:33:56 +00:00
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
#include <qt.h>
|
1998-03-30 21:02:31 +00:00
|
|
|
|
#include "eval.h"
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
|
Get rid of warnings from the cooperative threading system.
* threads.h (scm_single_thread_p, scm_yield,
scm_call_with_new_thread, scm_join_thread, scm_make_mutex,
scm_lock_mutex, scm_unlock_mutex, scm_make_condition_variable,
scm_wait_condition_variable, scm_signal_condition_variable): Add
prototypes for these Scheme-visible functions.
* coop-defs.h (coop_next_runnable_thread,
coop_wait_for_runnable_thread_now, coop_wait_for_runnable_thread):
Prototypes for these here, even though they're from iselect.c.
(coop_condition_variable_wait, coop_join): Add prototypes.
* coop-threads.c (scm_threads_free_thread, scm_threads_free_mutex,
scm_threads_free_condvar): Make these smob functions static.
* coop-threads.h (coop_init): Give this a real prototype.
* coop.c: #include <unistd.h>, if we have it, for `usleep' and `sleep'.
(coop_next_runnable_thread): No need to provide prototype; it's in
coop-defs.h.
1998-10-03 13:33:53 +00:00
|
|
|
|
/* #define COOP_STKSIZE (0x10000) */
|
1998-04-12 23:34:43 +00:00
|
|
|
|
#define COOP_STKSIZE (scm_eval_stack)
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
|
|
|
|
|
|
/* `alignment' must be a power of 2. */
|
|
|
|
|
|
#define COOP_STKALIGN(sp, alignment) \
|
|
|
|
|
|
((void *)((((qt_word_t)(sp)) + (alignment) - 1) & ~((alignment)-1)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Queue access functions. */
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
coop_qinit (coop_q_t *q)
|
|
|
|
|
|
{
|
|
|
|
|
|
q->t.next = q->tail = &q->t;
|
|
|
|
|
|
|
|
|
|
|
|
q->t.all_prev = NULL;
|
|
|
|
|
|
q->t.all_next = NULL;
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#ifdef GUILE_ISELECT
|
|
|
|
|
|
q->t.nfds = 0;
|
|
|
|
|
|
q->t.readfds = NULL;
|
|
|
|
|
|
q->t.writefds = NULL;
|
|
|
|
|
|
q->t.exceptfds = NULL;
|
|
|
|
|
|
q->t.timeoutp = 0;
|
|
|
|
|
|
#endif
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-11-27 18:04:56 +00:00
|
|
|
|
coop_t *
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
coop_qget (coop_q_t *q)
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_t *t;
|
|
|
|
|
|
|
|
|
|
|
|
t = q->t.next;
|
|
|
|
|
|
q->t.next = t->next;
|
|
|
|
|
|
if (t->next == &q->t) {
|
|
|
|
|
|
if (t == &q->t) { /* If it was already empty .. */
|
|
|
|
|
|
return (NULL); /* .. say so. */
|
|
|
|
|
|
}
|
|
|
|
|
|
q->tail = &q->t; /* Else now it is empty. */
|
|
|
|
|
|
}
|
|
|
|
|
|
return (t);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-11-27 18:04:56 +00:00
|
|
|
|
void
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
coop_qput (coop_q_t *q, coop_t *t)
|
|
|
|
|
|
{
|
|
|
|
|
|
q->tail->next = t;
|
|
|
|
|
|
t->next = &q->t;
|
|
|
|
|
|
q->tail = t;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
coop_all_qput (coop_q_t *q, coop_t *t)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (q->t.all_next)
|
|
|
|
|
|
q->t.all_next->all_prev = t;
|
|
|
|
|
|
t->all_prev = NULL;
|
|
|
|
|
|
t->all_next = q->t.all_next;
|
|
|
|
|
|
q->t.all_next = t;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
coop_all_qremove (coop_q_t *q, coop_t *t)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (t->all_prev)
|
|
|
|
|
|
t->all_prev->all_next = t->all_next;
|
|
|
|
|
|
else
|
|
|
|
|
|
q->t.all_next = t->all_next;
|
|
|
|
|
|
if (t->all_next)
|
|
|
|
|
|
t->all_next->all_prev = t->all_prev;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2000-03-12 00:33:56 +00:00
|
|
|
|
#ifdef GUILE_ISELECT
|
|
|
|
|
|
/* Insert thread t into the ordered queue q.
|
|
|
|
|
|
q is ordered after wakeup_time. Threads which aren't sleeping but
|
|
|
|
|
|
waiting for I/O go last into the queue. */
|
|
|
|
|
|
void
|
|
|
|
|
|
coop_timeout_qinsert (coop_q_t *q, coop_t *t)
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_t *pred = &q->t;
|
|
|
|
|
|
int sec = t->wakeup_time.tv_sec;
|
|
|
|
|
|
int usec = t->wakeup_time.tv_usec;
|
|
|
|
|
|
while (pred->next != &q->t
|
|
|
|
|
|
&& pred->next->timeoutp
|
|
|
|
|
|
&& (pred->next->wakeup_time.tv_sec < sec
|
|
|
|
|
|
|| (pred->next->wakeup_time.tv_sec == sec
|
|
|
|
|
|
&& pred->next->wakeup_time.tv_usec < usec)))
|
|
|
|
|
|
pred = pred->next;
|
|
|
|
|
|
t->next = pred->next;
|
|
|
|
|
|
pred->next = t;
|
|
|
|
|
|
if (t->next == &q->t)
|
|
|
|
|
|
q->tail = t;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
|
|
|
|
|
|
/* Thread routines. */
|
|
|
|
|
|
|
1997-11-27 18:04:56 +00:00
|
|
|
|
coop_q_t coop_global_runq; /* A queue of runable threads. */
|
|
|
|
|
|
coop_q_t coop_global_sleepq; /* A queue of sleeping threads. */
|
|
|
|
|
|
coop_q_t coop_tmp_queue; /* A temp working queue */
|
|
|
|
|
|
coop_q_t coop_global_allq; /* A queue of all threads. */
|
|
|
|
|
|
static coop_t coop_global_main; /* Thread for the process. */
|
|
|
|
|
|
coop_t *coop_global_curr; /* Currently-executing thread. */
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
|
|
|
|
|
|
static void *coop_starthelp (qt_t *old, void *ignore0, void *ignore1);
|
|
|
|
|
|
static void coop_only (void *pu, void *pt, qt_userf_t *f);
|
|
|
|
|
|
static void *coop_aborthelp (qt_t *sp, void *old, void *null);
|
|
|
|
|
|
static void *coop_yieldhelp (qt_t *sp, void *old, void *blockq);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
coop_init()
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_qinit (&coop_global_runq);
|
|
|
|
|
|
coop_qinit (&coop_global_sleepq);
|
1997-11-27 18:04:56 +00:00
|
|
|
|
coop_qinit (&coop_tmp_queue);
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
coop_qinit (&coop_global_allq);
|
|
|
|
|
|
coop_global_curr = &coop_global_main;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Return the next runnable thread. If no threads are currently runnable,
|
|
|
|
|
|
and there are sleeping threads - wait until one wakes up. Otherwise,
|
|
|
|
|
|
return NULL. */
|
|
|
|
|
|
|
Get rid of warnings from the cooperative threading system.
* threads.h (scm_single_thread_p, scm_yield,
scm_call_with_new_thread, scm_join_thread, scm_make_mutex,
scm_lock_mutex, scm_unlock_mutex, scm_make_condition_variable,
scm_wait_condition_variable, scm_signal_condition_variable): Add
prototypes for these Scheme-visible functions.
* coop-defs.h (coop_next_runnable_thread,
coop_wait_for_runnable_thread_now, coop_wait_for_runnable_thread):
Prototypes for these here, even though they're from iselect.c.
(coop_condition_variable_wait, coop_join): Add prototypes.
* coop-threads.c (scm_threads_free_thread, scm_threads_free_mutex,
scm_threads_free_condvar): Make these smob functions static.
* coop-threads.h (coop_init): Give this a real prototype.
* coop.c: #include <unistd.h>, if we have it, for `usleep' and `sleep'.
(coop_next_runnable_thread): No need to provide prototype; it's in
coop-defs.h.
1998-10-03 13:33:53 +00:00
|
|
|
|
#ifndef GUILE_ISELECT
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
coop_t *
|
|
|
|
|
|
coop_next_runnable_thread()
|
|
|
|
|
|
{
|
|
|
|
|
|
int sleepers;
|
|
|
|
|
|
coop_t *t;
|
|
|
|
|
|
time_t now;
|
|
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
sleepers = 0;
|
|
|
|
|
|
now = time(NULL);
|
|
|
|
|
|
|
|
|
|
|
|
/* Check the sleeping queue */
|
|
|
|
|
|
while ((t = coop_qget(&coop_global_sleepq)) != NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
sleepers++;
|
|
|
|
|
|
if (t->wakeup_time <= now)
|
|
|
|
|
|
coop_qput(&coop_global_runq, t);
|
|
|
|
|
|
else
|
1997-11-27 18:04:56 +00:00
|
|
|
|
coop_qput(&coop_tmp_queue, t);
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
}
|
1997-11-27 18:04:56 +00:00
|
|
|
|
while ((t = coop_qget(&coop_tmp_queue)) != NULL)
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
coop_qput(&coop_global_sleepq, t);
|
|
|
|
|
|
|
|
|
|
|
|
t = coop_qget (&coop_global_runq);
|
|
|
|
|
|
|
|
|
|
|
|
} while ((t == NULL) && (sleepers > 0));
|
|
|
|
|
|
|
|
|
|
|
|
return t;
|
|
|
|
|
|
}
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#endif
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
coop_start()
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_t *next;
|
|
|
|
|
|
|
|
|
|
|
|
while ((next = coop_qget (&coop_global_runq)) != NULL) {
|
|
|
|
|
|
coop_global_curr = next;
|
|
|
|
|
|
QT_BLOCK (coop_starthelp, 0, 0, next->sp);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void *
|
|
|
|
|
|
coop_starthelp (qt_t *old, void *ignore0, void *ignore1)
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_global_main.sp = old;
|
|
|
|
|
|
coop_global_main.joining = NULL;
|
|
|
|
|
|
coop_qput (&coop_global_runq, &coop_global_main);
|
|
|
|
|
|
return NULL; /* not used, but keeps compiler happy */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
* coop-threads.c (scm_wait_condition_variable): Use
coop_condition_variable_wait_mutex.
* coop-threads.h, coop-defs.h (coop_q_t, coop_m, coop_c):
Definitions moved to coop-defs.h.
* coop-defs.h (scm_mutex_init, scm_mutex_lock, scm_mutex_unlock,
scm_mutex_destroy, scm_cond_init, scm_cond_wait, scm_cond_signal,
scm_cond_destroy): New C interface to mutecis and cond vars.
1998-01-26 01:43:16 +00:00
|
|
|
|
int
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
coop_mutex_init (coop_m *m)
|
2000-03-12 00:33:56 +00:00
|
|
|
|
{
|
|
|
|
|
|
return coop_new_mutex_init (m, NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
|
coop_new_mutex_init (coop_m *m, coop_mattr *attr)
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
m->owner = NULL;
|
|
|
|
|
|
coop_qinit(&(m->waiting));
|
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
* coop-threads.c (scm_wait_condition_variable): Use
coop_condition_variable_wait_mutex.
* coop-threads.h, coop-defs.h (coop_q_t, coop_m, coop_c):
Definitions moved to coop-defs.h.
* coop-defs.h (scm_mutex_init, scm_mutex_lock, scm_mutex_unlock,
scm_mutex_destroy, scm_cond_init, scm_cond_wait, scm_cond_signal,
scm_cond_destroy): New C interface to mutecis and cond vars.
1998-01-26 01:43:16 +00:00
|
|
|
|
return 0;
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2000-03-12 00:33:56 +00:00
|
|
|
|
int
|
|
|
|
|
|
coop_mutex_trylock (coop_m *m)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m->owner == NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
m->owner = coop_global_curr;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
return EBUSY;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
* coop-threads.c (scm_wait_condition_variable): Use
coop_condition_variable_wait_mutex.
* coop-threads.h, coop-defs.h (coop_q_t, coop_m, coop_c):
Definitions moved to coop-defs.h.
* coop-defs.h (scm_mutex_init, scm_mutex_lock, scm_mutex_unlock,
scm_mutex_destroy, scm_cond_init, scm_cond_wait, scm_cond_signal,
scm_cond_destroy): New C interface to mutecis and cond vars.
1998-01-26 01:43:16 +00:00
|
|
|
|
int
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
coop_mutex_lock (coop_m *m)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m->owner == NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
m->owner = coop_global_curr;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_t *old, *newthread;
|
|
|
|
|
|
|
|
|
|
|
|
/* Record the current top-of-stack before going to sleep */
|
|
|
|
|
|
coop_global_curr->top = &old;
|
|
|
|
|
|
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#ifdef GUILE_ISELECT
|
|
|
|
|
|
newthread = coop_wait_for_runnable_thread();
|
* coop.c, iselect.c: Since thread switches are now performed with
interrupts masked, we can't use the old mechanism of delivering
signals immediately when they arrive. Signals must instead be
delivered when the asyncs run *after* the end of the critical
section in scm_internal_select. But this also means after context
switch so that the signal will be delivered to a different thread.
To avoid this, I have changed the protocol of
coop_wait_for_runnable_thread and friends so that they are allowed
to return the original thread. So, if a signal arrives during
scm_internal_select, we won't any longer be forced do a context
switch, but can remain in the same thread and deliver the signal
to it.
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
1998-01-30 21:07:00 +00:00
|
|
|
|
if (newthread == coop_global_curr)
|
|
|
|
|
|
coop_abort ();
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#else
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
newthread = coop_next_runnable_thread();
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#endif
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
old = coop_global_curr;
|
|
|
|
|
|
coop_global_curr = newthread;
|
|
|
|
|
|
QT_BLOCK (coop_yieldhelp, old, &(m->waiting), newthread->sp);
|
|
|
|
|
|
}
|
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
* coop-threads.c (scm_wait_condition_variable): Use
coop_condition_variable_wait_mutex.
* coop-threads.h, coop-defs.h (coop_q_t, coop_m, coop_c):
Definitions moved to coop-defs.h.
* coop-defs.h (scm_mutex_init, scm_mutex_lock, scm_mutex_unlock,
scm_mutex_destroy, scm_cond_init, scm_cond_wait, scm_cond_signal,
scm_cond_destroy): New C interface to mutecis and cond vars.
1998-01-26 01:43:16 +00:00
|
|
|
|
return 0;
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
* coop-threads.c (scm_wait_condition_variable): Use
coop_condition_variable_wait_mutex.
* coop-threads.h, coop-defs.h (coop_q_t, coop_m, coop_c):
Definitions moved to coop-defs.h.
* coop-defs.h (scm_mutex_init, scm_mutex_lock, scm_mutex_unlock,
scm_mutex_destroy, scm_cond_init, scm_cond_wait, scm_cond_signal,
scm_cond_destroy): New C interface to mutecis and cond vars.
1998-01-26 01:43:16 +00:00
|
|
|
|
int
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
coop_mutex_unlock (coop_m *m)
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_t *old, *newthread;
|
|
|
|
|
|
|
|
|
|
|
|
newthread = coop_qget (&(m->waiting));
|
|
|
|
|
|
if (newthread != NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Record the current top-of-stack before going to sleep */
|
|
|
|
|
|
coop_global_curr->top = &old;
|
|
|
|
|
|
|
|
|
|
|
|
old = coop_global_curr;
|
|
|
|
|
|
coop_global_curr = newthread;
|
1998-11-19 08:15:22 +00:00
|
|
|
|
/* The new thread came into m->waiting through a lock operation.
|
|
|
|
|
|
It now owns this mutex. */
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
m->owner = coop_global_curr;
|
|
|
|
|
|
QT_BLOCK (coop_yieldhelp, old, &coop_global_runq, newthread->sp);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
m->owner = NULL;
|
|
|
|
|
|
}
|
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
* coop-threads.c (scm_wait_condition_variable): Use
coop_condition_variable_wait_mutex.
* coop-threads.h, coop-defs.h (coop_q_t, coop_m, coop_c):
Definitions moved to coop-defs.h.
* coop-defs.h (scm_mutex_init, scm_mutex_lock, scm_mutex_unlock,
scm_mutex_destroy, scm_cond_init, scm_cond_wait, scm_cond_signal,
scm_cond_destroy): New C interface to mutecis and cond vars.
1998-01-26 01:43:16 +00:00
|
|
|
|
return 0;
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
* coop-threads.c (scm_wait_condition_variable): Use
coop_condition_variable_wait_mutex.
* coop-threads.h, coop-defs.h (coop_q_t, coop_m, coop_c):
Definitions moved to coop-defs.h.
* coop-defs.h (scm_mutex_init, scm_mutex_lock, scm_mutex_unlock,
scm_mutex_destroy, scm_cond_init, scm_cond_wait, scm_cond_signal,
scm_cond_destroy): New C interface to mutecis and cond vars.
1998-01-26 01:43:16 +00:00
|
|
|
|
int
|
|
|
|
|
|
coop_mutex_destroy (coop_m *m)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
coop_condition_variable_init (coop_c *c)
|
2000-03-12 00:33:56 +00:00
|
|
|
|
{
|
|
|
|
|
|
return coop_new_condition_variable_init (c, NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
|
coop_new_condition_variable_init (coop_c *c, coop_cattr *a)
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
coop_qinit(&(c->waiting));
|
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
* coop-threads.c (scm_wait_condition_variable): Use
coop_condition_variable_wait_mutex.
* coop-threads.h, coop-defs.h (coop_q_t, coop_m, coop_c):
Definitions moved to coop-defs.h.
* coop-defs.h (scm_mutex_init, scm_mutex_lock, scm_mutex_unlock,
scm_mutex_destroy, scm_cond_init, scm_cond_wait, scm_cond_signal,
scm_cond_destroy): New C interface to mutecis and cond vars.
1998-01-26 01:43:16 +00:00
|
|
|
|
return 0;
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
1998-11-19 08:15:22 +00:00
|
|
|
|
int
|
|
|
|
|
|
coop_condition_variable_wait_mutex (coop_c *c, coop_m *m)
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
coop_t *old, *newthread;
|
|
|
|
|
|
|
1998-11-19 08:15:22 +00:00
|
|
|
|
/* coop_mutex_unlock (m); */
|
|
|
|
|
|
newthread = coop_qget (&(m->waiting));
|
|
|
|
|
|
if (newthread != NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
m->owner = newthread;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
m->owner = NULL;
|
2000-03-12 00:33:56 +00:00
|
|
|
|
/*fixme* Should we really wait here? Isn't it OK just to proceed? */
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#ifdef GUILE_ISELECT
|
1998-11-19 08:15:22 +00:00
|
|
|
|
newthread = coop_wait_for_runnable_thread();
|
|
|
|
|
|
if (newthread == coop_global_curr)
|
|
|
|
|
|
coop_abort ();
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#else
|
1998-11-19 08:15:22 +00:00
|
|
|
|
newthread = coop_next_runnable_thread();
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#endif
|
1998-11-19 08:15:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
coop_global_curr->top = &old;
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
old = coop_global_curr;
|
|
|
|
|
|
coop_global_curr = newthread;
|
|
|
|
|
|
QT_BLOCK (coop_yieldhelp, old, &(c->waiting), newthread->sp);
|
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
* coop-threads.c (scm_wait_condition_variable): Use
coop_condition_variable_wait_mutex.
* coop-threads.h, coop-defs.h (coop_q_t, coop_m, coop_c):
Definitions moved to coop-defs.h.
* coop-defs.h (scm_mutex_init, scm_mutex_lock, scm_mutex_unlock,
scm_mutex_destroy, scm_cond_init, scm_cond_wait, scm_cond_signal,
scm_cond_destroy): New C interface to mutecis and cond vars.
1998-01-26 01:43:16 +00:00
|
|
|
|
|
|
|
|
|
|
coop_mutex_lock (m);
|
|
|
|
|
|
return 0;
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2000-03-12 00:33:56 +00:00
|
|
|
|
int
|
|
|
|
|
|
coop_condition_variable_timed_wait_mutex (coop_c *c,
|
|
|
|
|
|
coop_m *m,
|
|
|
|
|
|
const struct timespec *abstime)
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_t *old, *t;
|
|
|
|
|
|
int res = ETIME;
|
|
|
|
|
|
|
|
|
|
|
|
/* coop_mutex_unlock (m); */
|
|
|
|
|
|
t = coop_qget (&(m->waiting));
|
|
|
|
|
|
if (t != NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
m->owner = t;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
m->owner = NULL;
|
|
|
|
|
|
#ifdef GUILE_ISELECT
|
|
|
|
|
|
coop_global_curr->timeoutp = 1;
|
|
|
|
|
|
coop_global_curr->wakeup_time.tv_sec = abstime->tv_sec;
|
|
|
|
|
|
coop_global_curr->wakeup_time.tv_usec = abstime->tv_nsec / 1000;
|
|
|
|
|
|
coop_timeout_qinsert (&coop_global_sleepq, coop_global_curr);
|
|
|
|
|
|
t = coop_wait_for_runnable_thread();
|
|
|
|
|
|
#else
|
|
|
|
|
|
/*fixme* Implement!*/
|
|
|
|
|
|
t = coop_next_runnable_thread();
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
if (t != coop_global_curr)
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_global_curr->top = &old;
|
|
|
|
|
|
old = coop_global_curr;
|
|
|
|
|
|
coop_global_curr = t;
|
|
|
|
|
|
QT_BLOCK (coop_yieldhelp, old, &(c->waiting), t->sp);
|
|
|
|
|
|
|
|
|
|
|
|
/* Are we still in the sleep queue? */
|
|
|
|
|
|
old = &coop_global_sleepq.t;
|
|
|
|
|
|
for (t = old->next; t != &coop_global_sleepq.t; old = t, t = t->next)
|
|
|
|
|
|
if (t == coop_global_curr)
|
|
|
|
|
|
{
|
|
|
|
|
|
old->next = t->next; /* unlink */
|
|
|
|
|
|
res = 0;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
coop_mutex_lock (m);
|
|
|
|
|
|
return res;
|
|
|
|
|
|
}
|
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
* coop-threads.c (scm_wait_condition_variable): Use
coop_condition_variable_wait_mutex.
* coop-threads.h, coop-defs.h (coop_q_t, coop_m, coop_c):
Definitions moved to coop-defs.h.
* coop-defs.h (scm_mutex_init, scm_mutex_lock, scm_mutex_unlock,
scm_mutex_destroy, scm_cond_init, scm_cond_wait, scm_cond_signal,
scm_cond_destroy): New C interface to mutecis and cond vars.
1998-01-26 01:43:16 +00:00
|
|
|
|
|
|
|
|
|
|
int
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
coop_condition_variable_signal (coop_c *c)
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_t *newthread;
|
|
|
|
|
|
|
|
|
|
|
|
while ((newthread = coop_qget (&(c->waiting))) != NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_qput (&coop_global_runq, newthread);
|
|
|
|
|
|
}
|
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
* coop-threads.c (scm_wait_condition_variable): Use
coop_condition_variable_wait_mutex.
* coop-threads.h, coop-defs.h (coop_q_t, coop_m, coop_c):
Definitions moved to coop-defs.h.
* coop-defs.h (scm_mutex_init, scm_mutex_lock, scm_mutex_unlock,
scm_mutex_destroy, scm_cond_init, scm_cond_wait, scm_cond_signal,
scm_cond_destroy): New C interface to mutecis and cond vars.
1998-01-26 01:43:16 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2000-03-12 00:33:56 +00:00
|
|
|
|
/* {Keys}
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
static int n_keys = 0;
|
|
|
|
|
|
static int max_keys = 0;
|
|
|
|
|
|
static void (**destructors) (void *) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
|
coop_key_create (coop_k *keyp, void (*destructor) (void *value))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (n_keys >= max_keys)
|
|
|
|
|
|
{
|
|
|
|
|
|
int i;
|
|
|
|
|
|
max_keys = max_keys ? max_keys * 3 / 2 : 10;
|
|
|
|
|
|
destructors = realloc (destructors, sizeof (void *) * max_keys);
|
|
|
|
|
|
if (destructors == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
fprintf (stderr, "Virtual memory exceeded in coop_key_create\n");
|
|
|
|
|
|
exit (1);
|
|
|
|
|
|
}
|
|
|
|
|
|
for (i = n_keys; i < max_keys; ++i)
|
|
|
|
|
|
destructors[i] = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
destructors[n_keys] = destructor;
|
|
|
|
|
|
*keyp = n_keys++;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
|
coop_setspecific (coop_k key, const void *value)
|
|
|
|
|
|
{
|
|
|
|
|
|
int n_keys = coop_global_curr->n_keys;
|
|
|
|
|
|
if (key >= n_keys)
|
|
|
|
|
|
{
|
|
|
|
|
|
int i;
|
|
|
|
|
|
coop_global_curr->n_keys = max_keys;
|
|
|
|
|
|
coop_global_curr->specific = realloc (n_keys
|
|
|
|
|
|
? coop_global_curr->specific
|
|
|
|
|
|
: NULL,
|
|
|
|
|
|
sizeof (void *) * max_keys);
|
|
|
|
|
|
if (coop_global_curr->specific == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
fprintf (stderr, "Virtual memory exceeded in coop_setspecific\n");
|
|
|
|
|
|
exit (1);
|
|
|
|
|
|
}
|
|
|
|
|
|
for (i = n_keys; i < max_keys; ++i)
|
|
|
|
|
|
coop_global_curr->specific[i] = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
coop_global_curr->specific[key] = (void *) value;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void *
|
|
|
|
|
|
coop_getspecific (coop_k key)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (key < coop_global_curr->n_keys
|
|
|
|
|
|
? coop_global_curr->specific[key]
|
|
|
|
|
|
: NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
|
coop_key_delete (coop_k key)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
* coop-threads.c (scm_wait_condition_variable): Use
coop_condition_variable_wait_mutex.
* coop-threads.h, coop-defs.h (coop_q_t, coop_m, coop_c):
Definitions moved to coop-defs.h.
* coop-defs.h (scm_mutex_init, scm_mutex_lock, scm_mutex_unlock,
scm_mutex_destroy, scm_cond_init, scm_cond_wait, scm_cond_signal,
scm_cond_destroy): New C interface to mutecis and cond vars.
1998-01-26 01:43:16 +00:00
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
|
coop_condition_variable_destroy (coop_c *c)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2000-03-12 00:33:56 +00:00
|
|
|
|
#ifdef GUILE_PTHREAD_COMPAT
|
|
|
|
|
|
static void *
|
|
|
|
|
|
dummy_start (void *coop_thread)
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_t *t = (coop_t *) coop_thread;
|
|
|
|
|
|
t->sto = &t + 1;
|
|
|
|
|
|
pthread_mutex_init (&t->dummy_mutex, NULL);
|
|
|
|
|
|
pthread_mutex_lock (&t->dummy_mutex);
|
|
|
|
|
|
pthread_cond_init (&t->dummy_cond, NULL);
|
|
|
|
|
|
pthread_cond_wait (&t->dummy_cond, &t->dummy_mutex);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
|
|
|
|
|
|
coop_t *
|
|
|
|
|
|
coop_create (coop_userf_t *f, void *pu)
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_t *t;
|
|
|
|
|
|
void *sto;
|
|
|
|
|
|
|
|
|
|
|
|
t = malloc (sizeof(coop_t));
|
|
|
|
|
|
|
|
|
|
|
|
t->data = NULL;
|
2000-03-12 00:33:56 +00:00
|
|
|
|
t->n_keys = 0;
|
|
|
|
|
|
#ifdef GUILE_PTHREAD_COMPAT
|
|
|
|
|
|
pthread_create (&t->dummy_thread, NULL, dummy_start, t);
|
|
|
|
|
|
#else
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
t->sto = malloc (COOP_STKSIZE);
|
2000-03-12 00:33:56 +00:00
|
|
|
|
#endif
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
sto = COOP_STKALIGN (t->sto, QT_STKALIGN);
|
|
|
|
|
|
t->sp = QT_SP (sto, COOP_STKSIZE - QT_STKALIGN);
|
|
|
|
|
|
t->base = t->sp;
|
|
|
|
|
|
t->sp = QT_ARGS (t->sp, pu, t, (qt_userf_t *)f, coop_only);
|
|
|
|
|
|
t->joining = NULL;
|
|
|
|
|
|
coop_qput (&coop_global_runq, t);
|
|
|
|
|
|
coop_all_qput (&coop_global_allq, t);
|
|
|
|
|
|
|
|
|
|
|
|
return t;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
coop_only (void *pu, void *pt, qt_userf_t *f)
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_global_curr = (coop_t *)pt;
|
|
|
|
|
|
(*(coop_userf_t *)f)(pu);
|
|
|
|
|
|
coop_abort();
|
|
|
|
|
|
/* NOTREACHED */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
coop_abort ()
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_t *old, *newthread;
|
|
|
|
|
|
|
|
|
|
|
|
/* Wake up any threads that are waiting to join this one */
|
|
|
|
|
|
if (coop_global_curr->joining)
|
|
|
|
|
|
{
|
|
|
|
|
|
while ((newthread = coop_qget ((coop_q_t *)(coop_global_curr->joining)))
|
|
|
|
|
|
!= NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_qput (&coop_global_runq, newthread);
|
|
|
|
|
|
}
|
|
|
|
|
|
free(coop_global_curr->joining);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#ifdef GUILE_ISELECT
|
* coop.c, iselect.c: Since thread switches are now performed with
interrupts masked, we can't use the old mechanism of delivering
signals immediately when they arrive. Signals must instead be
delivered when the asyncs run *after* the end of the critical
section in scm_internal_select. But this also means after context
switch so that the signal will be delivered to a different thread.
To avoid this, I have changed the protocol of
coop_wait_for_runnable_thread and friends so that they are allowed
to return the original thread. So, if a signal arrives during
scm_internal_select, we won't any longer be forced do a context
switch, but can remain in the same thread and deliver the signal
to it.
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
1998-01-30 21:07:00 +00:00
|
|
|
|
scm_I_am_dead = 1;
|
|
|
|
|
|
do {
|
|
|
|
|
|
newthread = coop_wait_for_runnable_thread();
|
|
|
|
|
|
} while (newthread == coop_global_curr);
|
|
|
|
|
|
scm_I_am_dead = 0;
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#else
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
newthread = coop_next_runnable_thread();
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#endif
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
coop_all_qremove(&coop_global_allq, coop_global_curr);
|
|
|
|
|
|
old = coop_global_curr;
|
|
|
|
|
|
coop_global_curr = newthread;
|
2000-03-12 00:33:56 +00:00
|
|
|
|
#ifdef GUILE_PTHREAD_COMPAT
|
|
|
|
|
|
pthread_cond_signal (&old->dummy_cond);
|
|
|
|
|
|
#endif
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
QT_ABORT (coop_aborthelp, old, (void *)NULL, newthread->sp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void *
|
|
|
|
|
|
coop_aborthelp (qt_t *sp, void *old, void *null)
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_t *oldthread = (coop_t *) old;
|
|
|
|
|
|
|
|
|
|
|
|
free (oldthread->sto);
|
|
|
|
|
|
|
|
|
|
|
|
/* "old" is freed in scm_threads_thread_die().
|
|
|
|
|
|
Marking old->base NULL indicates that this thread is dead */
|
|
|
|
|
|
|
|
|
|
|
|
oldthread->base = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
coop_join(coop_t *t)
|
|
|
|
|
|
{
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
t->joining = malloc(sizeof(coop_q_t));
|
|
|
|
|
|
coop_qinit((coop_q_t *) t->joining);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#ifdef GUILE_ISELECT
|
|
|
|
|
|
newthread = coop_wait_for_runnable_thread();
|
* coop.c, iselect.c: Since thread switches are now performed with
interrupts masked, we can't use the old mechanism of delivering
signals immediately when they arrive. Signals must instead be
delivered when the asyncs run *after* the end of the critical
section in scm_internal_select. But this also means after context
switch so that the signal will be delivered to a different thread.
To avoid this, I have changed the protocol of
coop_wait_for_runnable_thread and friends so that they are allowed
to return the original thread. So, if a signal arrives during
scm_internal_select, we won't any longer be forced do a context
switch, but can remain in the same thread and deliver the signal
to it.
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
1998-01-30 21:07:00 +00:00
|
|
|
|
if (newthread == coop_global_curr)
|
|
|
|
|
|
return;
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#else
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
newthread = coop_next_runnable_thread();
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#endif
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
old = coop_global_curr;
|
|
|
|
|
|
coop_global_curr = newthread;
|
|
|
|
|
|
QT_BLOCK (coop_yieldhelp, old, (coop_q_t *) t->joining, newthread->sp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
coop_yield()
|
|
|
|
|
|
{
|
|
|
|
|
|
coop_t *old = NULL;
|
|
|
|
|
|
coop_t *newthread;
|
|
|
|
|
|
|
|
|
|
|
|
newthread = coop_next_runnable_thread();
|
|
|
|
|
|
|
|
|
|
|
|
/* There may be no other runnable threads. Return if this is the
|
|
|
|
|
|
case. */
|
* coop.c, iselect.c: Since thread switches are now performed with
interrupts masked, we can't use the old mechanism of delivering
signals immediately when they arrive. Signals must instead be
delivered when the asyncs run *after* the end of the critical
section in scm_internal_select. But this also means after context
switch so that the signal will be delivered to a different thread.
To avoid this, I have changed the protocol of
coop_wait_for_runnable_thread and friends so that they are allowed
to return the original thread. So, if a signal arrives during
scm_internal_select, we won't any longer be forced do a context
switch, but can remain in the same thread and deliver the signal
to it.
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
1998-01-30 21:07:00 +00:00
|
|
|
|
#if GUILE_ISELECT
|
|
|
|
|
|
if (newthread == coop_global_curr)
|
|
|
|
|
|
return;
|
|
|
|
|
|
#else
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
if (newthread == NULL)
|
|
|
|
|
|
return;
|
* coop.c, iselect.c: Since thread switches are now performed with
interrupts masked, we can't use the old mechanism of delivering
signals immediately when they arrive. Signals must instead be
delivered when the asyncs run *after* the end of the critical
section in scm_internal_select. But this also means after context
switch so that the signal will be delivered to a different thread.
To avoid this, I have changed the protocol of
coop_wait_for_runnable_thread and friends so that they are allowed
to return the original thread. So, if a signal arrives during
scm_internal_select, we won't any longer be forced do a context
switch, but can remain in the same thread and deliver the signal
to it.
* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,
coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'. This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.
* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.
1998-01-30 21:07:00 +00:00
|
|
|
|
#endif
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
|
|
|
|
|
|
old = coop_global_curr;
|
|
|
|
|
|
|
|
|
|
|
|
coop_global_curr = newthread;
|
|
|
|
|
|
QT_BLOCK (coop_yieldhelp, old, &coop_global_runq, newthread->sp);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void *
|
|
|
|
|
|
coop_yieldhelp (qt_t *sp, void *old, void *blockq)
|
|
|
|
|
|
{
|
|
|
|
|
|
((coop_t *)old)->sp = sp;
|
|
|
|
|
|
coop_qput ((coop_q_t *)blockq, (coop_t *)old);
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Replacement for the system's sleep() function. Does the right thing
|
|
|
|
|
|
for the process - but not for the system (it busy-waits) */
|
|
|
|
|
|
|
1997-11-27 18:04:56 +00:00
|
|
|
|
void *
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
coop_sleephelp (qt_t *sp, void *old, void *blockq)
|
|
|
|
|
|
{
|
|
|
|
|
|
((coop_t *)old)->sp = sp;
|
|
|
|
|
|
/* old is already on the sleep queue - so there's no need to
|
|
|
|
|
|
do anything extra here */
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#ifdef GUILE_ISELECT
|
|
|
|
|
|
|
1998-10-13 23:17:09 +00:00
|
|
|
|
unsigned long
|
|
|
|
|
|
scm_thread_usleep (unsigned long usec)
|
1997-11-27 18:04:56 +00:00
|
|
|
|
{
|
|
|
|
|
|
struct timeval timeout;
|
|
|
|
|
|
timeout.tv_sec = 0;
|
|
|
|
|
|
timeout.tv_usec = usec;
|
|
|
|
|
|
scm_internal_select (0, NULL, NULL, NULL, &timeout);
|
1998-04-20 00:39:15 +00:00
|
|
|
|
return 0; /* Maybe we should calculate actual time slept,
|
|
|
|
|
|
but this is faster... :) */
|
1997-11-27 18:04:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
1998-10-13 23:17:09 +00:00
|
|
|
|
unsigned long
|
|
|
|
|
|
scm_thread_sleep (unsigned long sec)
|
1997-11-27 18:04:56 +00:00
|
|
|
|
{
|
|
|
|
|
|
time_t now = time (NULL);
|
|
|
|
|
|
struct timeval timeout;
|
1998-10-13 23:17:09 +00:00
|
|
|
|
unsigned long slept;
|
1997-11-27 18:04:56 +00:00
|
|
|
|
timeout.tv_sec = sec;
|
|
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
|
|
scm_internal_select (0, NULL, NULL, NULL, &timeout);
|
|
|
|
|
|
slept = time (NULL) - now;
|
|
|
|
|
|
return slept > sec ? 0 : sec - slept;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else /* GUILE_ISELECT */
|
|
|
|
|
|
|
1998-10-13 23:17:09 +00:00
|
|
|
|
unsigned long
|
|
|
|
|
|
scm_thread_sleep (unsigned long s)
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
{
|
|
|
|
|
|
coop_t *newthread, *old;
|
1997-11-27 18:04:56 +00:00
|
|
|
|
time_t now = time (NULL);
|
Merge threads directory into libguile.
* coop-defs.h, coop-threads.c, coop-threads.h, coop.c, threads.c,
threads.h: New source files.
* Makefile.am (EXTRA_libguile_la_SOURCES): Add threads.c.
(noinst_HEADERS): Add coop-threads.c, coop-threads.h, coop.c
here; see comment.
(modinclude_HEADERS): Add threads.h, coop-defs.h.
(EXTRA_DIST): Add fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus.
* configure.in: If we're using threads, include threads.o in
LIBOBJS.
* _scm.h, libguile.h: threads.h lives in this directory now.
* fsu-pthreads.h, mit-pthreads.c, mit-pthreads.h,
coop-threads.c.cygnus, coop-threads.h.cygnus: New files, not
currently used, but brought along for information's sake.
* ChangeLog-threads: log from old 'threads' directory.
* Makefile.in, configure: Rebuilt.
1997-04-15 01:34:36 +00:00
|
|
|
|
coop_global_curr->wakeup_time = now + s;
|
|
|
|
|
|
|
|
|
|
|
|
/* Put the current thread on the sleep queue */
|
|
|
|
|
|
coop_qput (&coop_global_sleepq, coop_global_curr);
|
|
|
|
|
|
|
|
|
|
|
|
newthread = coop_next_runnable_thread();
|
|
|
|
|
|
|
|
|
|
|
|
/* If newthread is the same as the sleeping thread, do nothing */
|
|
|
|
|
|
if (newthread == coop_global_curr)
|
|
|
|
|
|
return s;
|
|
|
|
|
|
|
|
|
|
|
|
old = coop_global_curr;
|
|
|
|
|
|
|
|
|
|
|
|
coop_global_curr = newthread;
|
|
|
|
|
|
QT_BLOCK (coop_sleephelp, old, NULL, newthread->sp);
|
|
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
|
}
|
1997-11-27 18:04:56 +00:00
|
|
|
|
|
1998-10-13 23:17:09 +00:00
|
|
|
|
unsigned long
|
|
|
|
|
|
scm_thread_usleep (unsigned long usec)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* 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... :) */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
1997-11-27 18:04:56 +00:00
|
|
|
|
#endif /* GUILE_ISELECT */
|