Commit | Line | Data |
---|---|---|
9482a297 MV |
1 | /* classes: h_files */ |
2 | ||
dee01b01 DH |
3 | #ifndef SCM_FLUIDS_H |
4 | #define SCM_FLUIDS_H | |
9482a297 | 5 | |
dee01b01 DH |
6 | /* Copyright (C) 1996,2000,2001 Free Software Foundation, Inc. |
7 | * | |
73be1d9e MV |
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. | |
dee01b01 | 12 | * |
73be1d9e | 13 | * This library is distributed in the hope that it will be useful, |
9482a297 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
73be1d9e MV |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Lesser General Public License for more details. | |
dee01b01 | 17 | * |
73be1d9e MV |
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 | */ | |
9482a297 | 22 | |
dee01b01 | 23 | \f |
d3a6bc94 | 24 | |
9482a297 MV |
25 | #include "libguile/__scm.h" |
26 | #include "libguile/root.h" | |
27 | #include "libguile/vectors.h" | |
28 | ||
29 | /* Fluids. | |
30 | ||
31 | Fluids are objects of a certain type (a smob) that can hold one SCM | |
32 | value per dynamic root. That is, modifications to this value are | |
33 | only visible to code that executes within the same dynamic root as | |
34 | the modifying code. When a new dynamic root is constructed, it | |
35 | inherits the values from its parent. Because each thread executes | |
36 | in its own dynamic root, you can use fluids for thread local | |
37 | storage. | |
38 | ||
39 | Each fluid is identified by a small integer. This integer is used | |
40 | to index a vector that holds the values of all fluids. Each root | |
41 | has its own vector. | |
42 | ||
b3460a50 MV |
43 | Currently, you can't get rid a certain fluid if you don't use it |
44 | any longer. The slot that has been allocated for it in the fluid | |
9482a297 | 45 | vector will not be reused for other fluids. Therefore, only use |
b3460a50 | 46 | SCM_MAKE_FLUID or its Scheme variant `make-fluid' in initialization |
9482a297 MV |
47 | code that is only run once. Nevertheless, it should be possible to |
48 | implement a more lightweight version of fluids on top of this basic | |
49 | mechanism. */ | |
50 | ||
33b001fd | 51 | SCM_API scm_t_bits scm_tc16_fluid; |
9482a297 | 52 | |
47457e8a DH |
53 | #define SCM_FLUIDP(x) (!SCM_IMP (x) && (SCM_CELL_TYPE (x) == scm_tc16_fluid)) |
54 | #define SCM_FLUID_NUM(x) (SCM_CELL_WORD_1 (x)) | |
9482a297 MV |
55 | |
56 | /* The fastest way to acces/modify the value of a fluid. These macros | |
b3460a50 | 57 | do no error checking at all. You should only use them when you know |
9482a297 MV |
58 | that the relevant fluid already exists in the current dynamic root. |
59 | The easiest way to ensure this is to execute a SCM_FLUID_SET_X in the | |
60 | topmost root, for example right after SCM_MAKE_FLUID in your | |
61 | SCM_INIT_MUMBLE routine that gets called from SCM_BOOT_GUILE_1. The | |
62 | first argument is the index number of the fluid, obtained via | |
63 | SCM_FLUID_NUM, not the fluid itself. */ | |
64 | ||
65 | #define SCM_FAST_FLUID_REF(n) (SCM_VELTS(scm_root->fluids)[n]) | |
66 | #define SCM_FAST_FLUID_SET_X(n, val) (SCM_VELTS(scm_root->fluids)[n] = val) | |
67 | ||
33b001fd MV |
68 | SCM_API SCM scm_make_fluid (void); |
69 | SCM_API SCM scm_fluid_p (SCM fl); | |
70 | SCM_API SCM scm_fluid_ref (SCM fluid); | |
71 | SCM_API SCM scm_fluid_set_x (SCM fluid, SCM value); | |
9482a297 | 72 | |
33b001fd MV |
73 | SCM_API SCM scm_c_with_fluids (SCM fluids, SCM vals, |
74 | SCM (*cproc)(void *), void *cdata); | |
75 | SCM_API SCM scm_c_with_fluid (SCM fluid, SCM val, | |
76 | SCM (*cproc)(void *), void *cdata); | |
77 | SCM_API SCM scm_with_fluids (SCM fluids, SCM vals, SCM thunk); | |
b3460a50 | 78 | |
a52dbe01 MV |
79 | SCM_API SCM scm_i_make_initial_fluids (void); |
80 | SCM_API void scm_i_copy_fluids (scm_root_state *); | |
81 | SCM_API void scm_i_swap_fluids (SCM fluids, SCM vals); | |
82 | SCM_API void scm_i_swap_fluids_reverse (SCM fluids, SCM vals); | |
9482a297 | 83 | |
33b001fd | 84 | SCM_API void scm_init_fluids (void); |
9482a297 | 85 | |
dee01b01 | 86 | #endif /* SCM_FLUIDS_H */ |
89e00824 ML |
87 | |
88 | /* | |
89 | Local Variables: | |
90 | c-file-style: "gnu" | |
91 | End: | |
92 | */ |