95916f33bf09785a5b3faab161431d302871eb26
[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, 2006, 2008 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 #if 0
26
27 /* Futures have the following known bugs, which should be fixed before
28 including them in Guile:
29
30 - The implementation of the thread cache needs to be better so that
31 it behaves reasonable under heavy use.
32
33 - The dynamic state of a thread needs to be properly initialized
34 when it is retrieved from the cache.
35 */
36
37 #include "libguile/__scm.h"
38 #include "libguile/threads.h"
39
40 \f
41
42 typedef struct scm_t_future {
43 SCM data;
44 scm_i_pthread_mutex_t mutex;
45 scm_i_pthread_cond_t cond;
46 int status;
47 int die_p;
48 } scm_t_future;
49
50 #define SCM_FUTURE_DEAD 0
51 #define SCM_FUTURE_SIGNAL_ME -1
52 #define SCM_FUTURE_COMPUTING 1
53 #define SCM_FUTURE_TASK_ASSIGNED 2
54
55 #define SCM_VALIDATE_FUTURE(pos, obj) \
56 SCM_ASSERT_TYPE (SCM_TYP16_PREDICATE (scm_tc16_future, obj), \
57 obj, pos, FUNC_NAME, "future");
58 #define SCM_FUTURE(future) ((scm_t_future *) SCM_SMOB_DATA_2 (future))
59 #define SCM_FUTURE_MUTEX(future) (&SCM_FUTURE (future)->mutex)
60 #define SCM_FUTURE_COND(future) (&SCM_FUTURE (future)->cond)
61 #define SCM_FUTURE_STATUS(future) (SCM_FUTURE (future)->status)
62 #define SCM_SET_FUTURE_STATUS(future, x) \
63 do { SCM_FUTURE (future)->status = (x); } while (0)
64 #define SCM_FUTURE_ALIVE_P(future) (SCM_FUTURE_STATUS (future))
65 #define SCM_FUTURE_DATA(future) (SCM_FUTURE (future)->data)
66 #define SCM_SET_FUTURE_DATA(future, x) \
67 do { SCM_FUTURE (future)->data = (x); } while (0)
68 #define SCM_FUTURE_NEXT SCM_SMOB_OBJECT
69 #define SCM_FUTURE_NEXTLOC SCM_SMOB_OBJECT_LOC
70 #define SCM_SET_FUTURE_NEXT SCM_SET_SMOB_OBJECT
71
72 SCM_API scm_t_bits scm_tc16_future;
73
74 extern SCM *scm_loc_sys_thread_handler;
75
76 SCM_INTERNAL SCM scm_i_make_future (SCM thunk);
77 SCM_API SCM scm_make_future (SCM thunk);
78 SCM_API SCM scm_future_ref (SCM future);
79
80 void scm_init_futures (void);
81
82 #endif /* Futures are disabled for now. */
83
84 #endif /* SCM_FUTURES_H */
85
86 /*
87 Local Variables:
88 c-file-style: "gnu"
89 End:
90 */