diff options
Diffstat (limited to 'src/tools.h')
-rw-r--r-- | src/tools.h | 85 |
1 files changed, 67 insertions, 18 deletions
diff --git a/src/tools.h b/src/tools.h index 5bd4b69..1d80309 100644 --- a/src/tools.h +++ b/src/tools.h | |||
@@ -55,9 +55,8 @@ void luaL_requiref (lua_State* L, const char* modname, lua_CFunction openf, int | |||
55 | #define USE_DEBUG_SPEW 0 | 55 | #define USE_DEBUG_SPEW 0 |
56 | #if USE_DEBUG_SPEW | 56 | #if USE_DEBUG_SPEW |
57 | extern char const* debugspew_indent; | 57 | extern char const* debugspew_indent; |
58 | extern int debugspew_indent_depth; | ||
59 | #define INDENT_BEGIN "%.*s " | 58 | #define INDENT_BEGIN "%.*s " |
60 | #define INDENT_END , debugspew_indent_depth, debugspew_indent | 59 | #define INDENT_END , (U ? U->debugspew_indent_depth : 0), debugspew_indent |
61 | #define DEBUGSPEW_CODE(_code) _code | 60 | #define DEBUGSPEW_CODE(_code) _code |
62 | #else // USE_DEBUG_SPEW | 61 | #else // USE_DEBUG_SPEW |
63 | #define DEBUGSPEW_CODE(_code) | 62 | #define DEBUGSPEW_CODE(_code) |
@@ -98,8 +97,10 @@ extern int debugspew_indent_depth; | |||
98 | 97 | ||
99 | void luaG_dump( lua_State* L ); | 98 | void luaG_dump( lua_State* L ); |
100 | 99 | ||
101 | lua_State* luaG_newstate( lua_State* _from, char const* libs); | 100 | lua_State* luaG_newstate( struct s_Universe* U, lua_State* _from, char const* libs); |
102 | void luaG_copy_one_time_settings( lua_State* L, lua_State* L2); | 101 | void luaG_copy_one_time_settings( struct s_Universe* U, lua_State* L, lua_State* L2); |
102 | |||
103 | // ################################################################################################ | ||
103 | 104 | ||
104 | // this is pointed to by full userdata proxies, and allocated with malloc() to survive any lua_State lifetime | 105 | // this is pointed to by full userdata proxies, and allocated with malloc() to survive any lua_State lifetime |
105 | typedef struct | 106 | typedef struct |
@@ -117,29 +118,77 @@ enum eLookupMode | |||
117 | eLM_FromKeeper // send a function from a keeper state to a lane | 118 | eLM_FromKeeper // send a function from a keeper state to a lane |
118 | }; | 119 | }; |
119 | 120 | ||
120 | char const* push_deep_proxy( lua_State* L, DEEP_PRELUDE* prelude, enum eLookupMode mode_); | 121 | char const* push_deep_proxy( struct s_Universe* U, lua_State* L, DEEP_PRELUDE* prelude, enum eLookupMode mode_); |
121 | int luaG_inter_copy_package( lua_State* L, lua_State* L2, int package_idx_, enum eLookupMode mode_); | 122 | void free_deep_prelude( lua_State* L, DEEP_PRELUDE* prelude_); |
123 | |||
124 | int luaG_inter_copy_package( struct s_Universe* U, lua_State* L, lua_State* L2, int package_idx_, enum eLookupMode mode_); | ||
122 | 125 | ||
123 | int luaG_inter_copy( lua_State *L, lua_State *L2, uint_t n, enum eLookupMode mode_); | 126 | int luaG_inter_copy( struct s_Universe* U, lua_State* L, lua_State* L2, uint_t n, enum eLookupMode mode_); |
124 | int luaG_inter_move( lua_State *L, lua_State *L2, uint_t n, enum eLookupMode mode_); | 127 | int luaG_inter_move( struct s_Universe* U, lua_State* L, lua_State* L2, uint_t n, enum eLookupMode mode_); |
125 | 128 | ||
126 | int luaG_nameof( lua_State* L); | 129 | int luaG_nameof( lua_State* L); |
127 | int luaG_new_require( lua_State* L); | 130 | int luaG_new_require( lua_State* L); |
128 | 131 | ||
129 | // Lock for reference counter inc/dec locks (to be initialized by outside code) | ||
130 | // | ||
131 | extern MUTEX_T deep_lock; | ||
132 | extern MUTEX_T mtid_lock; | ||
133 | |||
134 | void populate_func_lookup_table( lua_State* L, int _i, char const* _name); | 132 | void populate_func_lookup_table( lua_State* L, int _i, char const* _name); |
135 | void serialize_require( lua_State *L); | 133 | void serialize_require( lua_State *L); |
136 | int initialize_on_state_create( lua_State *L); | 134 | void initialize_on_state_create( struct s_Universe* U, lua_State* L); |
137 | int call_on_state_create( lua_State* L, lua_State* from_, enum eLookupMode mode_); | 135 | void call_on_state_create( struct s_Universe* U, lua_State* L, lua_State* from_, enum eLookupMode mode_); |
136 | |||
137 | // ################################################################################################ | ||
138 | |||
139 | /* | ||
140 | * Do we want to activate full lane tracking feature? (EXPERIMENTAL) | ||
141 | */ | ||
142 | #define HAVE_LANE_TRACKING 1 | ||
143 | |||
144 | // ################################################################################################ | ||
145 | |||
146 | // everything regarding the a Lanes universe is stored in that global structure | ||
147 | // held as a full userdata in the master Lua state that required it for the first time | ||
148 | // don't forget to initialize all members in LG_configure() | ||
149 | struct s_Universe | ||
150 | { | ||
151 | // for verbose errors | ||
152 | bool_t verboseErrors; | ||
153 | |||
154 | lua_CFunction on_state_create_func; | ||
155 | |||
156 | struct s_Keepers* keepers; | ||
157 | |||
158 | // Initialized by 'init_once_LOCKED()': the deep userdata Linda object | ||
159 | // used for timers (each lane will get a proxy to this) | ||
160 | volatile DEEP_PRELUDE* timer_deep; // = NULL | ||
161 | |||
162 | #if HAVE_LANE_TRACKING | ||
163 | MUTEX_T tracking_cs; | ||
164 | struct s_lane* volatile tracking_first; // will change to TRACKING_END if we want to activate tracking | ||
165 | #endif // HAVE_LANE_TRACKING | ||
166 | |||
167 | MUTEX_T selfdestruct_cs; | ||
168 | |||
169 | // require() serialization | ||
170 | MUTEX_T require_cs; | ||
171 | |||
172 | // Lock for reference counter inc/dec locks (to be initialized by outside code) TODO: get rid of this and use atomics instead! | ||
173 | MUTEX_T deep_lock; | ||
174 | MUTEX_T mtid_lock; | ||
175 | |||
176 | int last_mt_id; | ||
177 | |||
178 | #if USE_DEBUG_SPEW | ||
179 | int debugspew_indent_depth; | ||
180 | #endif // USE_DEBUG_SPEW | ||
181 | |||
182 | struct s_lane* volatile selfdestruct_first; | ||
183 | // After a lane has removed itself from the chain, it still performs some processing. | ||
184 | // The terminal desinit sequence should wait for all such processing to terminate before force-killing threads | ||
185 | int volatile selfdestructing_count; | ||
186 | }; | ||
138 | 187 | ||
139 | extern MUTEX_T require_cs; | 188 | struct s_Universe* get_universe( lua_State* L); |
189 | extern void* const UNIVERSE_REGKEY; | ||
140 | 190 | ||
141 | // for verbose errors | 191 | // ################################################################################################ |
142 | extern bool_t GVerboseErrors; | ||
143 | 192 | ||
144 | extern char const* const CONFIG_REGKEY; | 193 | extern char const* const CONFIG_REGKEY; |
145 | extern char const* const LOOKUP_REGKEY; | 194 | extern char const* const LOOKUP_REGKEY; |