See ChangeLog from 2005-03-02.
[bpt/guile.git] / libguile / futures.h
1 /* classes: h_files */
2
3 #ifndef SCM_FUTURES_H
4 #define SCM_FUTURES_H
5
6 /* Copyright (C) 2002, 2003 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 \f
24
25 #include "libguile/__scm.h"
26 #include "libguile/threads.h"
27
28 \f
29
30 typedef struct scm_t_future {
31 SCM data;
32 scm_i_pthread_mutex_t mutex;
33 scm_i_pthread_cond_t cond;
34 int status;
35 int die_p;
36 } scm_t_future;
37
38 #define SCM_FUTURE_DEAD 0
39 #define SCM_FUTURE_SIGNAL_ME -1
40 #define SCM_FUTURE_COMPUTING 1
41 #define SCM_FUTURE_TASK_ASSIGNED 2
42
43 #define SCM_VALIDATE_FUTURE(pos, obj) \
44 SCM_ASSERT_TYPE (SCM_TYP16_PREDICATE (scm_tc16_future, obj), \
45 obj, pos, FUNC_NAME, "future");
46 #define SCM_FUTURE(future) ((scm_t_future *) SCM_SMOB_DATA_2 (future))
47 #define SCM_FUTURE_MUTEX(future) (&SCM_FUTURE (future)->mutex)
48 #define SCM_FUTURE_COND(future) (&SCM_FUTURE (future)->cond)
49 #define SCM_FUTURE_STATUS(future) (SCM_FUTURE (future)->status)
50 #define SCM_SET_FUTURE_STATUS(future, x) \
51 do { SCM_FUTURE (future)->status = (x); } while (0)
52 #define SCM_FUTURE_ALIVE_P(future) (SCM_FUTURE_STATUS (future))
53 #define SCM_FUTURE_DATA(future) (SCM_FUTURE (future)->data)
54 #define SCM_SET_FUTURE_DATA(future, x) \
55 do { SCM_FUTURE (future)->data = (x); } while (0)
56 #define SCM_FUTURE_NEXT SCM_SMOB_OBJECT
57 #define SCM_FUTURE_NEXTLOC SCM_SMOB_OBJECT_LOC
58 #define SCM_SET_FUTURE_NEXT SCM_SET_SMOB_OBJECT
59
60 SCM_API scm_t_bits scm_tc16_future;
61
62 extern SCM *scm_loc_sys_thread_handler;
63
64 SCM_API SCM scm_i_make_future (SCM thunk);
65 SCM_API SCM scm_make_future (SCM thunk);
66 SCM_API SCM scm_future_ref (SCM future);
67
68 void scm_init_futures (void);
69
70 #endif /* SCM_FUTURES_H */
71
72 /*
73 Local Variables:
74 c-file-style: "gnu"
75 End:
76 */