The FSF has a new address.
[bpt/guile.git] / libguile / coop-threads.h
1 /* classes: h_files */
2
3 #ifndef SCM_COOP_THREADS_H
4 #define SCM_COOP_THREADS_H
5
6 /* Copyright (C) 1996,1997,1998,2000, 2002 Free Software Foundation, Inc.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 \f
24
25 /* This file is only included by coop-threads.c while coop-defs.h is
26 included by threads.h, which, in turn, is included by
27 libguile.h. */
28
29 /* The coop_t struct is declared in coop-defs.h. */
30
31 #include "libguile/__scm.h"
32
33 #include <time.h>
34
35 #include "libguile/coop-defs.h"
36 #include "qt/qt.h"
37
38 /* This code is based on a sample thread libraru by David Keppel.
39 Portions of this file fall under the following copyright: */
40
41 /*
42 * QuickThreads -- Threads-building toolkit.
43 * Copyright (c) 1993 by David Keppel
44 *
45 * Permission to use, copy, modify and distribute this software and
46 * its documentation for any purpose and without fee is hereby
47 * granted, provided that the above copyright notice and this notice
48 * appear in all copies. This software is provided as a
49 * proof-of-concept and for demonstration purposes; there is no
50 * representation about the suitability of this software for any
51 * purpose.
52 */
53
54 /* Each thread starts by calling a user-supplied function of this
55 type. */
56
57 typedef void (coop_userf_t)(void *p0);
58
59 /* Call this before any other primitives. */
60 SCM_API void coop_init (void);
61
62 /* When one or more threads are created by the main thread,
63 the system goes multithread when this is called. It is done
64 (no more runable threads) when this returns. */
65
66 SCM_API void coop_start (void);
67
68 /* Create a thread and make it runable. When the thread starts
69 running it will call `f' with arguments `p0' and `p1'. */
70
71 SCM_API coop_t *coop_create (coop_userf_t *f, void *p0);
72
73 /* The current thread stops running but stays runable.
74 It is an error to call `coop_yield' before `coop_start'
75 is called or after `coop_start' returns. */
76
77 SCM_API void coop_yield (void);
78
79 /* Like `coop_yield' but the thread is discarded. Any intermediate
80 state is lost. The thread can also terminate by simply
81 returning. */
82
83 SCM_API void coop_abort (void);
84
85 /* The following are needed in iselect.c */
86
87 SCM_API coop_t *coop_qget (coop_q_t *);
88 SCM_API void coop_qput (coop_q_t *, coop_t *);
89 SCM_API void *coop_sleephelp (qt_t *, void *, void *);
90
91 SCM_API coop_t *coop_wait_for_runnable_thread ();
92
93 SCM_API coop_q_t coop_global_runq; /* A queue of runable threads. */
94 SCM_API coop_q_t coop_global_sleepq;
95 SCM_API coop_q_t coop_tmp_queue;
96 SCM_API coop_q_t coop_global_allq; /* A queue of all threads. */
97 SCM_API coop_t *coop_global_curr; /* Currently-executing thread. */
98
99 #endif /* SCM_COOP_THREADS_H */
100
101 /*
102 Local Variables:
103 c-file-style: "gnu"
104 End:
105 */