diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2012-02-18 14:08:52 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2012-02-18 14:08:52 +0100 |
commit | 076344633e7b2525cf48005f84f3935f324b60bf (patch) | |
tree | 2a013da0ba2cd4a9f7eaf073a5ba128723f13154 | |
parent | b4582dd0bb65a916de7fa9612880b75a17c7ae7f (diff) | |
download | lanes-076344633e7b2525cf48005f84f3935f324b60bf.tar.gz lanes-076344633e7b2525cf48005f84f3935f324b60bf.tar.bz2 lanes-076344633e7b2525cf48005f84f3935f324b60bf.zip |
* changed lanes.configure signature to receive a table instead of individual parameters
* added support for an on_state_create callback called to load custom functions in a state in addition to the base libraries
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | docs/index.html | 104 | ||||
-rw-r--r-- | src/keeper.c | 18 | ||||
-rw-r--r-- | src/keeper.h | 2 | ||||
-rw-r--r-- | src/lanes.c | 66 | ||||
-rw-r--r-- | src/lanes.lua | 32 | ||||
-rw-r--r-- | src/tools.c | 81 | ||||
-rw-r--r-- | src/tools.h | 4 | ||||
-rw-r--r-- | tests/appendud.lua | 2 | ||||
-rw-r--r-- | tests/atexit.lua | 2 | ||||
-rw-r--r-- | tests/atomic.lua | 2 | ||||
-rw-r--r-- | tests/basic.lua | 2 | ||||
-rw-r--r-- | tests/cyclic.lua | 2 | ||||
-rw-r--r-- | tests/ehynes.lua | 2 | ||||
-rw-r--r-- | tests/errhangtest.lua | 2 | ||||
-rw-r--r-- | tests/error.lua | 2 | ||||
-rw-r--r-- | tests/fibonacci.lua | 2 | ||||
-rw-r--r-- | tests/fifo.lua | 2 | ||||
-rw-r--r-- | tests/finalizer.lua | 2 | ||||
-rw-r--r-- | tests/func_is_string.lua | 2 | ||||
-rw-r--r-- | tests/hangtest.lua | 2 | ||||
-rw-r--r-- | tests/irayo_closure.lua | 2 | ||||
-rw-r--r-- | tests/irayo_recursive.lua | 2 | ||||
-rw-r--r-- | tests/keeper.lua | 2 | ||||
-rw-r--r-- | tests/launchtest.lua | 2 | ||||
-rw-r--r-- | tests/linda_perf.lua | 2 | ||||
-rw-r--r-- | tests/objects.lua | 2 | ||||
-rw-r--r-- | tests/perftest.lua | 2 | ||||
-rw-r--r-- | tests/recursive.lua | 2 | ||||
-rw-r--r-- | tests/require.lua | 2 | ||||
-rw-r--r-- | tests/timer.lua | 2 |
31 files changed, 199 insertions, 158 deletions
@@ -3,6 +3,10 @@ CHANGES: | |||
3 | 3 | ||
4 | CHANGE X: | 4 | CHANGE X: |
5 | 5 | ||
6 | CHANGE 35 BGe 17-Feb-2012 | ||
7 | * changed lanes.configure signature to receive a table instead of individual parameters | ||
8 | * added support for an on_state_create callback called to load custom functions in a state in addition to the base libraries | ||
9 | |||
6 | CHANGE 34 BGe 14-Nov-2011 | 10 | CHANGE 34 BGe 14-Nov-2011 |
7 | * removed packagepath and packagecpath options, replaced by a package table, whose fields path, cpath, loaders, preload are transfered | 11 | * removed packagepath and packagecpath options, replaced by a package table, whose fields path, cpath, loaders, preload are transfered |
8 | * code cleanup to facilitate transition between WIN32 and PTHREAD impleentations | 12 | * code cleanup to facilitate transition between WIN32 and PTHREAD impleentations |
diff --git a/docs/index.html b/docs/index.html index e24b172..72e91ba 100644 --- a/docs/index.html +++ b/docs/index.html | |||
@@ -56,7 +56,7 @@ | |||
56 | 56 | ||
57 | <p><br/><font size="-1"><i>Copyright © 2007-12 Asko Kauppi, Benoit Germain. All rights reserved.</i> | 57 | <p><br/><font size="-1"><i>Copyright © 2007-12 Asko Kauppi, Benoit Germain. All rights reserved.</i> |
58 | <br>Lua Lanes is published under the same <A HREF="http://en.wikipedia.org/wiki/MIT_License">MIT license</A> as Lua 5.1. | 58 | <br>Lua Lanes is published under the same <A HREF="http://en.wikipedia.org/wiki/MIT_License">MIT license</A> as Lua 5.1. |
59 | </p><p>This document was revised on 5-Nov-11, and applies to version 3.0-beta. | 59 | </p><p>This document was revised on 17-Feb-11, and applies to version 3.1.0 |
60 | </font></p> | 60 | </font></p> |
61 | 61 | ||
62 | </center> | 62 | </center> |
@@ -173,8 +173,7 @@ Or use <A HREF="http://www.luarocks.org" TARGET="_blank">Lua Rocks</A> package m | |||
173 | <tr> | 173 | <tr> |
174 | <td> | 174 | <td> |
175 | <pre> | 175 | <pre> |
176 | local lanes = require "lanes" | 176 | local lanes = require "lanes".configure() |
177 | lanes.configure( 1) | ||
178 | </pre> | 177 | </pre> |
179 | </table> | 178 | </table> |
180 | 179 | ||
@@ -182,11 +181,11 @@ Or use <A HREF="http://www.luarocks.org" TARGET="_blank">Lua Rocks</A> package m | |||
182 | Starting with version 3.0-beta, requiring the module follows Lua 5.2 rules: | 181 | Starting with version 3.0-beta, requiring the module follows Lua 5.2 rules: |
183 | the module is not available under the global name "lanes", but has to be accessed | 182 | the module is not available under the global name "lanes", but has to be accessed |
184 | through require's return value. | 183 | through require's return value. |
185 | After lanes is required, it is necessary to call lanes.configure(), which is the | 184 | After lanes is required, it is necessary to call <tt>lanes.configure()</tt>, which is the |
186 | only function exposed by the module at this point. Calling configure() will | 185 | only function exposed by the module at this point. Calling <tt>configure()</tt> will |
187 | perform one-time initializations and make the rest of the API available. | 186 | perform one-time initializations and make the rest of the API available. |
188 | At the same time, configure() itself will be replaced by another function that | 187 | At the same time, <tt>configure()</tt> itself will be replaced by another function that |
189 | raises an error if called with differing arguments. | 188 | raises an error if called again with differing arguments. |
190 | </p> | 189 | </p> |
191 | 190 | ||
192 | <p> | 191 | <p> |
@@ -194,19 +193,39 @@ Or use <A HREF="http://www.luarocks.org" TARGET="_blank">Lua Rocks</A> package m | |||
194 | <tr> | 193 | <tr> |
195 | <td> | 194 | <td> |
196 | <code> | 195 | <code> |
197 | lanes.configure( [nb_keepers] [, "NO_TIMERS"]) | 196 | lanes.configure( [opt_tbl]) |
198 | </code> | 197 | </code> |
199 | </table> | 198 | </table> |
200 | </p> | 199 | </p> |
201 | <p> | 200 | <p> |
202 | <tt>lanes.configure</tt> accepts 2 arguments. The first one controls the number | 201 | <tt>lanes.configure</tt> accepts an optional options table as sole argument. |
203 | of keeper states used internally by lindas to transfer data between lanes. (see below). | 202 | <table> |
204 | Default is 1. | 203 | <tr valign=top><td width=40></td><td> |
205 | </p> | 204 | <code>.nb_keepers</code> <br/><nobr>N</nobr></td><td width=40></td> |
206 | <p>If the second argument is equal to <tt>"NO_TIMERS"</tt>, Lanes doesn't start the timer service, | 205 | <td> |
206 | Controls the number of keeper states used internally by lindas to transfer data between lanes. (see below). Default is 1. | ||
207 | </td></tr> | ||
208 | |||
209 | <tr valign=top><td/><td> | ||
210 | <code>.with_timers</code> <br/>nil/false/anything</td><td/> | ||
211 | <td> | ||
212 | If equal to <tt>false</tt>, Lanes doesn't start the timer service, | ||
207 | and the associated API will be absent from the interface (see below). | 213 | and the associated API will be absent from the interface (see below). |
208 | </p> | 214 | Any other value (including <tt>nil</tt>), starts the timer service. |
209 | <h2 id="creation">Creation</h2> | 215 | </td></tr> |
216 | |||
217 | <tr valign="top"> | ||
218 | <td/> | ||
219 | <td> | ||
220 | <code>.on_create_state</code> <br/>C function/nil | ||
221 | </td><td/> | ||
222 | <td> | ||
223 | If provided, will be called in every created Lua state (keepers and lanes) right after it is created, and *before* any library is loaded. | ||
224 | That way, all C functions it loads in the state can be added to the function lookup database. | ||
225 | </td> | ||
226 | </tr> | ||
227 | </table> | ||
228 | <h2 id="creation">Creation</h2> | ||
210 | 229 | ||
211 | <p>The following sample shows preparing a function for parallel calling, and | 230 | <p>The following sample shows preparing a function for parallel calling, and |
212 | calling it with varying arguments. Each of the two results is calculated in | 231 | calling it with varying arguments. Each of the two results is calculated in |
@@ -217,7 +236,7 @@ joins the threads, waiting for any results not already there. | |||
217 | <table border=1 bgcolor="#FFFFE0" width=500><tr><td> | 236 | <table border=1 bgcolor="#FFFFE0" width=500><tr><td> |
218 | <pre> | 237 | <pre> |
219 | local lanes = require "lanes" | 238 | local lanes = require "lanes" |
220 | lanes.configure( 1) | 239 | lanes.configure() |
221 | 240 | ||
222 | f= lanes.gen( function(n) return 2*n end ) | 241 | f= lanes.gen( function(n) return 2*n end ) |
223 | a= f(1) | 242 | a= f(1) |
@@ -240,8 +259,8 @@ joins the threads, waiting for any results not already there. | |||
240 | but the particular arguments may vary. Only calling the generator function | 259 | but the particular arguments may vary. Only calling the generator function |
241 | actually launches a lane, and provides a handle for controlling it. | 260 | actually launches a lane, and provides a handle for controlling it. |
242 | Alternatively, <tt>lane_func</tt> may be a string, in which case it will be compiled | 261 | Alternatively, <tt>lane_func</tt> may be a string, in which case it will be compiled |
243 | in the lane. This is to be able to launch lanes whith LuaJIT, | 262 | in the lane. This was to be able to launch lanes with older versions of LuaJIT, |
244 | which does not support lua_dump, used internally to transfer functions to the lane. | 263 | which didn't not support lua_dump, used internally to transfer functions to the lane. |
245 | <!-- | 264 | <!-- |
246 | </p> | 265 | </p> |
247 | <p>This prepares <tt>lane_func</tt> to be called in parallel. It does not yet start | 266 | <p>This prepares <tt>lane_func</tt> to be called in parallel. It does not yet start |
@@ -257,19 +276,21 @@ also in the new lanes. | |||
257 | <code>libs_str</code> defines the standard libraries made available to the | 276 | <code>libs_str</code> defines the standard libraries made available to the |
258 | new Lua state: | 277 | new Lua state: |
259 | <table> | 278 | <table> |
260 | <tr><td/><td>(nothing)</td><td>no standard libraries (default)</td></tr> | 279 | <tr><td width=40></td><td>(nothing)</td><td width=40></td><td>no standard libraries (default)</td></tr> |
261 | <tr><td width=40><td><tt>"base"</tt> or <tt>""</tt></td> | 280 | <tr><td/> |
262 | <td>root level names, <tt>print</tt>, <tt>assert</tt>, <tt>unpack</tt> etc.</td></tr> | 281 | <td><tt>"base"</tt> or <tt>""</tt></td><td/> |
263 | <tr><td/><td><tt>"coroutine"</tt></td><td><tt>coroutine.*</tt> namespace <font size="-1">(part of base in Lua 5.1)</font></td></tr> | 282 | <td>root level names, <tt>print</tt>, <tt>assert</tt>, <tt>unpack</tt> etc.</td> |
264 | <tr><td/><td><tt>"debug"</tt></td><td><tt>debug.*</tt> namespace</td></tr> | 283 | </tr> |
265 | <tr><td/><td><tt>"io"</tt></td><td><tt>io.*</tt> namespace</td></tr> | 284 | <tr><td/><td><tt>"coroutine"</tt></td><td/><td><tt>coroutine.*</tt> namespace <font size="-1">(part of base in Lua 5.1)</font></td></tr> |
266 | <tr><td/><td><tt>"math"</tt></td><td><tt>math.*</tt> namespace</td></tr> | 285 | <tr><td/><td><tt>"debug"</tt></td><td/><td><tt>debug.*</tt> namespace</td></tr> |
267 | <tr><td/><td><tt>"os"</tt></td><td><tt>os.*</tt> namespace</td></tr> | 286 | <tr><td/><td><tt>"io"</tt></td><td/><td><tt>io.*</tt> namespace</td></tr> |
268 | <tr><td/><td><tt>"package"</tt></td><td><tt>package.*</tt> namespace and <tt>require</tt></td></tr> | 287 | <tr><td/><td><tt>"math"</tt></td><td/><td><tt>math.*</tt> namespace</td></tr> |
269 | <tr><td/><td><tt>"string"</tt></td><td><tt>string.*</tt> namespace</td></tr> | 288 | <tr><td/><td><tt>"os"</tt></td><td/><td><tt>os.*</tt> namespace</td></tr> |
270 | <tr><td/><td><tt>"table"</tt></td><td><tt>table.*</tt> namespace</td></tr> | 289 | <tr><td/><td><tt>"package"</tt></td><td/><td><tt>package.*</tt> namespace and <tt>require</tt></td></tr> |
290 | <tr><td/><td><tt>"string"</tt></td><td/><td><tt>string.*</tt> namespace</td></tr> | ||
291 | <tr><td/><td><tt>"table"</tt></td><td/><td><tt>table.*</tt> namespace</td></tr> | ||
271 | <br/> | 292 | <br/> |
272 | <tr><td/><td><tt>"*"</tt></td><td>all standard libraries</td></tr> | 293 | <tr><td/><td><tt>"*"</tt></td><td/><td>all standard libraries</td></tr> |
273 | </table> | 294 | </table> |
274 | 295 | ||
275 | </p><p> | 296 | </p><p> |
@@ -281,9 +302,9 @@ also in the new lanes. | |||
281 | lanes are run: | 302 | lanes are run: |
282 | </p><p> | 303 | </p><p> |
283 | <table> | 304 | <table> |
284 | <tr valign=top><td/><td> | 305 | <tr valign=top><td width=40></td><td> |
285 | <code>.cancelstep</code> <br/><nobr>N / true</nobr></td> | 306 | <code>.cancelstep</code> <br/><nobr>N / true</nobr></td> |
286 | <td> | 307 | <td width=40></td><td> |
287 | By default, lanes are only cancellable when they <u>enter</u> a pending | 308 | By default, lanes are only cancellable when they <u>enter</u> a pending |
288 | <tt>:receive()</tt> or <tt>:send()</tt> call. | 309 | <tt>:receive()</tt> or <tt>:send()</tt> call. |
289 | With this option, one can set cancellation check to occur every <tt>N</tt> | 310 | With this option, one can set cancellation check to occur every <tt>N</tt> |
@@ -292,7 +313,7 @@ also in the new lanes. | |||
292 | </td></tr> | 313 | </td></tr> |
293 | 314 | ||
294 | <tr valign=top><td/><td> | 315 | <tr valign=top><td/><td> |
295 | <code>.globals</code> <br/>globals_tbl</td> | 316 | <code>.globals</code> <br/>globals_tbl</td><td/> |
296 | <td> | 317 | <td> |
297 | Sets the globals table for the launched threads. This can be used for giving | 318 | Sets the globals table for the launched threads. This can be used for giving |
298 | them constants. | 319 | them constants. |
@@ -305,21 +326,18 @@ also in the new lanes. | |||
305 | <td/> | 326 | <td/> |
306 | <td> | 327 | <td> |
307 | <code>.required</code> <br/>modules_tbl | 328 | <code>.required</code> <br/>modules_tbl |
308 | </td> | 329 | </td><td/> |
309 | <td> | 330 | <td> |
310 | Lists modules that have to be required in order to be able to trasnfer | 331 | Lists modules that have to be required in order to be able to trasnfer |
311 | functions they exposed. Starting with Lanes 3.0-beta, non-Lua functions are | 332 | functions they exposed. Starting with Lanes 3.0-beta, non-Lua functions are |
312 | no longer copied by recreating a C closure from a C pointer, but are searched | 333 | no longer copied by recreating a C closure from a C pointer, but are searched |
313 | in lookup tables. These tables are built from the modules listed here. <tt>required</tt> | 334 | in lookup tables. These tables are built from the modules listed here. <tt>required</tt> |
314 | must be a list of strings, each one being the name of a module to be required. | 335 | must be a list of strings, each one being the name of a module to be required. |
315 | <br> | ||
316 | The global values of different lanes are in no manner connected; | ||
317 | modifying one will only affect the particular lane. | ||
318 | </td> | 336 | </td> |
319 | </tr> | 337 | </tr> |
320 | 338 | ||
321 | <tr valign=top><td width=40><td> | 339 | <tr valign=top><td width=40><td> |
322 | <code>.priority</code> <br/><nobr>-2..+2</nobr></td> | 340 | <code>.priority</code> <br/><nobr>-2..+2</nobr></td><td/> |
323 | <td>The priority of lanes generated. -2 is lowest, +2 is highest. | 341 | <td>The priority of lanes generated. -2 is lowest, +2 is highest. |
324 | <br> | 342 | <br> |
325 | Implementation and dependability of priorities varies | 343 | Implementation and dependability of priorities varies |
@@ -331,7 +349,7 @@ also in the new lanes. | |||
331 | <td> | 349 | <td> |
332 | <code>.package</code><br/> | 350 | <code>.package</code><br/> |
333 | </td> | 351 | </td> |
334 | <td> | 352 | <td><td/> |
335 | <code>package</code> contents overrides, if needed. | 353 | <code>package</code> contents overrides, if needed. |
336 | Specifying it when <code>libs_str</code> doesn't cause the <code>package</code> library to be loaded will generate an error. | 354 | Specifying it when <code>libs_str</code> doesn't cause the <code>package</code> library to be loaded will generate an error. |
337 | If not specified, the created lane will receive the current values of <tt>package</tt>. Only path, cpath, preload and loaders are transfered. | 355 | If not specified, the created lane will receive the current values of <tt>package</tt>. Only path, cpath, preload and loaders are transfered. |
@@ -704,7 +722,7 @@ events to a common Linda, but... :).</font> | |||
704 | <code>= lanes.timer( linda_h, key, date_tbl|first_secs [,period_secs] )</code> | 722 | <code>= lanes.timer( linda_h, key, date_tbl|first_secs [,period_secs] )</code> |
705 | </table> | 723 | </table> |
706 | 724 | ||
707 | <p> | 725 | <p> |
708 | Timers are implemented as a lane. They can be disabled by passing <tt>"NO_TIMERS"</tt> | 726 | Timers are implemented as a lane. They can be disabled by passing <tt>"NO_TIMERS"</tt> |
709 | to <tt>lanes.configure()</tt>. | 727 | to <tt>lanes.configure()</tt>. |
710 | </p> | 728 | </p> |
@@ -1060,6 +1078,12 @@ its actual value. | |||
1060 | <h2 id="changes">Change log</h2> | 1078 | <h2 id="changes">Change log</h2> |
1061 | 1079 | ||
1062 | <p> | 1080 | <p> |
1081 | Feb-2012 | ||
1082 | <ul> | ||
1083 | <li>Added support for an on_state_create callback invoked on a pristine Lua state created by Lanes.</li> | ||
1084 | <li>This required a change in the <tt>lanes.configure()</tt> signature, hence the minor version bump.</li> | ||
1085 | </ul> | ||
1086 | |||
1063 | 1087 | ||
1064 | Nov-2011 | 1088 | Nov-2011 |
1065 | <ul> | 1089 | <ul> |
diff --git a/src/keeper.c b/src/keeper.c index 1f69d40..6f5bd95 100644 --- a/src/keeper.c +++ b/src/keeper.c | |||
@@ -78,7 +78,7 @@ static char const keeper_chunk[]= | |||
78 | * unclosed, because it does not really matter. In production code, this | 78 | * unclosed, because it does not really matter. In production code, this |
79 | * function never fails. | 79 | * function never fails. |
80 | */ | 80 | */ |
81 | char const *init_keepers( int const _nbKeepers) | 81 | char const* init_keepers( int const _nbKeepers, lua_CFunction _on_state_create) |
82 | { | 82 | { |
83 | int i; | 83 | int i; |
84 | assert( _nbKeepers >= 1); | 84 | assert( _nbKeepers >= 1); |
@@ -87,10 +87,11 @@ char const *init_keepers( int const _nbKeepers) | |||
87 | for( i = 0; i < _nbKeepers; ++ i) | 87 | for( i = 0; i < _nbKeepers; ++ i) |
88 | { | 88 | { |
89 | 89 | ||
90 | // Initialize Keeper states with bare minimum of libs (those required | 90 | // Initialize Keeper states with bare minimum of libs (those required by 'keeper.lua') |
91 | // by 'keeper.lua') | 91 | // |
92 | // | 92 | // 'io' for debugging messages, 'package' because we need to require modules exporting idfuncs |
93 | lua_State *K = luaL_newstate(); | 93 | // the others because they export functions that we may store in a keeper for transfer between lanes |
94 | lua_State* K = luaG_newstate( "*", _on_state_create); | ||
94 | if (!K) | 95 | if (!K) |
95 | return "out of memory"; | 96 | return "out of memory"; |
96 | 97 | ||
@@ -100,11 +101,6 @@ char const *init_keepers( int const _nbKeepers) | |||
100 | lua_concat( K, 2); | 101 | lua_concat( K, 2); |
101 | lua_setglobal( K, "decoda_name"); | 102 | lua_setglobal( K, "decoda_name"); |
102 | 103 | ||
103 | // 'io' for debugging messages, 'package' because we need to require modules exporting idfuncs | ||
104 | // the others because they export functions that we may store in a keeper for transfer between lanes | ||
105 | luaG_openlibs( K, "*"); | ||
106 | serialize_require( K); | ||
107 | |||
108 | // Read in the preloaded chunk (and run it) | 104 | // Read in the preloaded chunk (and run it) |
109 | // | 105 | // |
110 | if( luaL_loadbuffer( K, keeper_chunk, sizeof(keeper_chunk), "@keeper.lua")) | 106 | if( luaL_loadbuffer( K, keeper_chunk, sizeof(keeper_chunk), "@keeper.lua")) |
@@ -114,7 +110,7 @@ char const *init_keepers( int const _nbKeepers) | |||
114 | { | 110 | { |
115 | // LUA_ERRRUN / LUA_ERRMEM / LUA_ERRERR | 111 | // LUA_ERRRUN / LUA_ERRMEM / LUA_ERRERR |
116 | // | 112 | // |
117 | const char *err = lua_tostring(K, -1); | 113 | char const* err = lua_tostring( K, -1); |
118 | assert( err); | 114 | assert( err); |
119 | return err; | 115 | return err; |
120 | } | 116 | } |
diff --git a/src/keeper.h b/src/keeper.h index 1bcb36b..0990846 100644 --- a/src/keeper.h +++ b/src/keeper.h | |||
@@ -8,7 +8,7 @@ struct s_Keeper | |||
8 | //int count; | 8 | //int count; |
9 | }; | 9 | }; |
10 | 10 | ||
11 | const char *init_keepers( int const _nbKeepers); | 11 | char const* init_keepers( int const _nbKeepers, lua_CFunction _on_state_create); |
12 | void populate_keepers( lua_State *L); | 12 | void populate_keepers( lua_State *L); |
13 | struct s_Keeper *keeper_acquire( const void *ptr); | 13 | struct s_Keeper *keeper_acquire( const void *ptr); |
14 | void keeper_release( struct s_Keeper *K); | 14 | void keeper_release( struct s_Keeper *K); |
diff --git a/src/lanes.c b/src/lanes.c index 676032a..513a006 100644 --- a/src/lanes.c +++ b/src/lanes.c | |||
@@ -51,7 +51,7 @@ | |||
51 | * ... | 51 | * ... |
52 | */ | 52 | */ |
53 | 53 | ||
54 | const char *VERSION= "3.0-beta"; | 54 | char const* VERSION = "3.1.0"; |
55 | 55 | ||
56 | /* | 56 | /* |
57 | =============================================================================== | 57 | =============================================================================== |
@@ -1540,7 +1540,7 @@ static void require_one_module( lua_State *L, lua_State *L2, bool_t _fatal) | |||
1540 | { | 1540 | { |
1541 | lua_pop( L2, 1); | 1541 | lua_pop( L2, 1); |
1542 | if( _fatal) | 1542 | if( _fatal) |
1543 | luaL_error( L, "cannot pre-require modules without loading package library first"); | 1543 | luaL_error( L, "cannot pre-require modules without loading 'package' library first"); |
1544 | } | 1544 | } |
1545 | else | 1545 | else |
1546 | { | 1546 | { |
@@ -1557,14 +1557,15 @@ LUAG_FUNC( thread_new ) | |||
1557 | struct s_lane *s; | 1557 | struct s_lane *s; |
1558 | struct s_lane **ud; | 1558 | struct s_lane **ud; |
1559 | 1559 | ||
1560 | const char *libs= lua_tostring( L, 2 ); | 1560 | char const* libs = lua_tostring( L, 2); |
1561 | uint_t cs= luaG_optunsigned( L, 3,0); | 1561 | lua_CFunction on_state_create = lua_iscfunction( L, 3) ? lua_tocfunction( L, 3) : NULL; |
1562 | int prio= (int)luaL_optinteger( L, 4,0); | 1562 | uint_t cs = luaG_optunsigned( L, 4, 0); |
1563 | uint_t glob= luaG_isany(L,5) ? 5:0; | 1563 | int prio = (int) luaL_optinteger( L, 5, 0); |
1564 | uint_t package = luaG_isany(L,6) ? 6:0; | 1564 | uint_t glob = luaG_isany( L, 6) ? 6 : 0; |
1565 | uint_t required = luaG_isany(L,7) ? 7:0; | 1565 | uint_t package = luaG_isany( L,7) ? 7 : 0; |
1566 | uint_t required = luaG_isany( L, 8) ? 8 : 0; | ||
1566 | 1567 | ||
1567 | #define FIXED_ARGS (7) | 1568 | #define FIXED_ARGS 8 |
1568 | uint_t args= lua_gettop(L) - FIXED_ARGS; | 1569 | uint_t args= lua_gettop(L) - FIXED_ARGS; |
1569 | 1570 | ||
1570 | if (prio < THREAD_PRIO_MIN || prio > THREAD_PRIO_MAX) | 1571 | if (prio < THREAD_PRIO_MIN || prio > THREAD_PRIO_MAX) |
@@ -1575,23 +1576,13 @@ LUAG_FUNC( thread_new ) | |||
1575 | 1576 | ||
1576 | /* --- Create and prepare the sub state --- */ | 1577 | /* --- Create and prepare the sub state --- */ |
1577 | 1578 | ||
1578 | L2 = luaL_newstate(); // uses standard 'realloc()'-based allocator, | 1579 | // populate with selected libraries at the same time |
1579 | // sets the panic callback | 1580 | // |
1580 | 1581 | L2 = luaG_newstate( libs, on_state_create); | |
1581 | if (!L2) luaL_error( L, "'luaL_newstate()' failed; out of memory" ); | 1582 | if (!L2) luaL_error( L, "'luaL_newstate()' failed; out of memory" ); |
1582 | 1583 | ||
1583 | STACK_GROW( L, 2); | 1584 | STACK_GROW( L, 2); |
1584 | 1585 | ||
1585 | // Selected libraries | ||
1586 | // | ||
1587 | if (libs) | ||
1588 | { | ||
1589 | const char *err= luaG_openlibs( L2, libs); | ||
1590 | ASSERT_L( !err ); // bad libs should have been noticed by 'lanes.lua' | ||
1591 | |||
1592 | serialize_require( L2); | ||
1593 | } | ||
1594 | |||
1595 | ASSERT_L( lua_gettop(L2) == 0); | 1586 | ASSERT_L( lua_gettop(L2) == 0); |
1596 | 1587 | ||
1597 | // package.path | 1588 | // package.path |
@@ -1600,7 +1591,7 @@ LUAG_FUNC( thread_new ) | |||
1600 | if( package) | 1591 | if( package) |
1601 | { | 1592 | { |
1602 | if (lua_type(L,package) != LUA_TTABLE) | 1593 | if (lua_type(L,package) != LUA_TTABLE) |
1603 | luaL_error( L, "expected package as table, got %s", luaG_typename(L,package)); | 1594 | luaL_error( L, "expected package as table, got %s", luaL_typename(L,package)); |
1604 | lua_getglobal( L2, "package"); | 1595 | lua_getglobal( L2, "package"); |
1605 | if( !lua_isnil( L2, -1)) // package library not loaded: do nothing | 1596 | if( !lua_isnil( L2, -1)) // package library not loaded: do nothing |
1606 | { | 1597 | { |
@@ -1628,7 +1619,7 @@ LUAG_FUNC( thread_new ) | |||
1628 | // modules to require in the target lane *before* the function is transfered! | 1619 | // modules to require in the target lane *before* the function is transfered! |
1629 | 1620 | ||
1630 | //start by requiring lua51-lanes, since it is a bit special | 1621 | //start by requiring lua51-lanes, since it is a bit special |
1631 | // it not fatal if 'require' isn't loaded, just ignore (may cause function transfer errors later on if the lane pulls the lanes module itself) | 1622 | // it is not fatal if 'require' isn't loaded, just ignore (may cause function transfer errors later on if the lane pulls the lanes module itself) |
1632 | STACK_CHECK(L) | 1623 | STACK_CHECK(L) |
1633 | STACK_CHECK(L2) | 1624 | STACK_CHECK(L2) |
1634 | lua_pushliteral( L, "lua51-lanes"); | 1625 | lua_pushliteral( L, "lua51-lanes"); |
@@ -1644,7 +1635,7 @@ LUAG_FUNC( thread_new ) | |||
1644 | int nbRequired = 1; | 1635 | int nbRequired = 1; |
1645 | // should not happen, was checked in lanes.lua before calling thread_new() | 1636 | // should not happen, was checked in lanes.lua before calling thread_new() |
1646 | if (lua_type(L, required) != LUA_TTABLE) | 1637 | if (lua_type(L, required) != LUA_TTABLE) |
1647 | luaL_error( L, "expected required module list as a table, got %s", luaG_typename( L, required)); | 1638 | luaL_error( L, "expected required module list as a table, got %s", luaL_typename( L, required)); |
1648 | lua_pushnil( L); | 1639 | lua_pushnil( L); |
1649 | while( lua_next( L, required) != 0) | 1640 | while( lua_next( L, required) != 0) |
1650 | { | 1641 | { |
@@ -1671,7 +1662,7 @@ LUAG_FUNC( thread_new ) | |||
1671 | STACK_CHECK(L) | 1662 | STACK_CHECK(L) |
1672 | STACK_CHECK(L2) | 1663 | STACK_CHECK(L2) |
1673 | if (!lua_istable(L,glob)) | 1664 | if (!lua_istable(L,glob)) |
1674 | luaL_error( L, "Expected table, got %s", luaG_typename(L,glob)); | 1665 | luaL_error( L, "Expected table, got %s", luaL_typename(L,glob)); |
1675 | 1666 | ||
1676 | lua_pushnil( L); | 1667 | lua_pushnil( L); |
1677 | while( lua_next( L, glob)) | 1668 | while( lua_next( L, glob)) |
@@ -2240,7 +2231,7 @@ static const struct luaL_reg lanes_functions [] = { | |||
2240 | /* | 2231 | /* |
2241 | * One-time initializations | 2232 | * One-time initializations |
2242 | */ | 2233 | */ |
2243 | static void init_once_LOCKED( lua_State *L, volatile DEEP_PRELUDE ** timer_deep_ref, int const nbKeepers) | 2234 | static void init_once_LOCKED( lua_State* L, volatile DEEP_PRELUDE** timer_deep_ref, int const nbKeepers, lua_CFunction _on_state_create) |
2244 | { | 2235 | { |
2245 | const char *err; | 2236 | const char *err; |
2246 | 2237 | ||
@@ -2291,7 +2282,7 @@ static void init_once_LOCKED( lua_State *L, volatile DEEP_PRELUDE ** timer_deep_ | |||
2291 | } | 2282 | } |
2292 | #endif | 2283 | #endif |
2293 | #endif | 2284 | #endif |
2294 | err= init_keepers( nbKeepers); | 2285 | err = init_keepers( nbKeepers, _on_state_create); |
2295 | if (err) | 2286 | if (err) |
2296 | { | 2287 | { |
2297 | luaL_error( L, "Unable to initialize: %s", err ); | 2288 | luaL_error( L, "Unable to initialize: %s", err ); |
@@ -2338,9 +2329,11 @@ static volatile long s_initCount = 0; | |||
2338 | 2329 | ||
2339 | LUAG_FUNC( configure ) | 2330 | LUAG_FUNC( configure ) |
2340 | { | 2331 | { |
2341 | char const *name = luaL_checkstring( L, lua_upvalueindex( 1)); | 2332 | char const* name = luaL_checkstring( L, lua_upvalueindex( 1)); |
2342 | int const nbKeepers = luaL_optint( L, 1, 1); | 2333 | int const nbKeepers = luaL_optint( L, 1, 1); |
2343 | luaL_argcheck( L, nbKeepers > 0, 2, "Number of keeper states must be > 0"); | 2334 | lua_CFunction on_state_create = lua_iscfunction( L, 2) ? lua_tocfunction( L, 2) : NULL; |
2335 | luaL_argcheck( L, nbKeepers > 0, 1, "Number of keeper states must be > 0"); | ||
2336 | luaL_argcheck( L, lua_iscfunction( L, 2) || lua_isnil( L, 2), 2, "on_state_create should be a C function"); | ||
2344 | /* | 2337 | /* |
2345 | * Making one-time initializations. | 2338 | * Making one-time initializations. |
2346 | * | 2339 | * |
@@ -2353,7 +2346,7 @@ LUAG_FUNC( configure ) | |||
2353 | static volatile int /*bool*/ go_ahead; // = 0 | 2346 | static volatile int /*bool*/ go_ahead; // = 0 |
2354 | if( InterlockedCompareExchange( &s_initCount, 1, 0) == 0) | 2347 | if( InterlockedCompareExchange( &s_initCount, 1, 0) == 0) |
2355 | { | 2348 | { |
2356 | init_once_LOCKED(L, &timer_deep, nbKeepers); | 2349 | init_once_LOCKED( L, &timer_deep, nbKeepers, on_state_create); |
2357 | go_ahead= 1; // let others pass | 2350 | go_ahead= 1; // let others pass |
2358 | } | 2351 | } |
2359 | else | 2352 | else |
@@ -2365,13 +2358,13 @@ LUAG_FUNC( configure ) | |||
2365 | if( s_initCount == 0) | 2358 | if( s_initCount == 0) |
2366 | { | 2359 | { |
2367 | static pthread_mutex_t my_lock= PTHREAD_MUTEX_INITIALIZER; | 2360 | static pthread_mutex_t my_lock= PTHREAD_MUTEX_INITIALIZER; |
2368 | pthread_mutex_lock(&my_lock); | 2361 | pthread_mutex_lock( &my_lock); |
2369 | { | 2362 | { |
2370 | // Recheck now that we're within the lock | 2363 | // Recheck now that we're within the lock |
2371 | // | 2364 | // |
2372 | if (s_initCount == 0) | 2365 | if( s_initCount == 0) |
2373 | { | 2366 | { |
2374 | init_once_LOCKED(L, &timer_deep, nbKeepers); | 2367 | init_once_LOCKED( L, &timer_deep, nbKeepers, on_state_create); |
2375 | s_initCount = 1; | 2368 | s_initCount = 1; |
2376 | } | 2369 | } |
2377 | } | 2370 | } |
@@ -2451,10 +2444,11 @@ luaopen_lanes( lua_State *L ) | |||
2451 | { | 2444 | { |
2452 | lua_setfield( L, -2, "configure"); | 2445 | lua_setfield( L, -2, "configure"); |
2453 | } | 2446 | } |
2454 | else // already initialized: call it mmediately and be done | 2447 | else // already initialized: call it immediately and be done |
2455 | { | 2448 | { |
2456 | lua_pushinteger( L, 666); // any value will do, it will be ignored | 2449 | lua_pushinteger( L, 666); // any value will do, it will be ignored |
2457 | lua_call( L, 1, 0); | 2450 | lua_pushnil( L); // almost idem |
2451 | lua_call( L, 2, 0); | ||
2458 | } | 2452 | } |
2459 | STACK_END( L, 1) | 2453 | STACK_END( L, 1) |
2460 | return 1; | 2454 | return 1; |
diff --git a/src/lanes.lua b/src/lanes.lua index d56e05f..ec5a4e4 100644 --- a/src/lanes.lua +++ b/src/lanes.lua | |||
@@ -45,13 +45,21 @@ THE SOFTWARE. | |||
45 | -- -> simply create a table, populate it, return it, and be done | 45 | -- -> simply create a table, populate it, return it, and be done |
46 | local lanes = {} | 46 | local lanes = {} |
47 | 47 | ||
48 | lanes.configure = function( _nb_keepers, _timers) | 48 | lanes.configure = function( _params) |
49 | _params = _params or { nb_keepers = 1, with_timers = true, on_state_create = nil} | ||
50 | if type( _params) ~= "table" then | ||
51 | error( "Bad parameter #1 to lanes.configure(), should be a table") | ||
52 | end | ||
53 | -- on_state_create may be nil or a function | ||
54 | if _params.on_state_create and (type( _params.on_state_create) ~= "function") then | ||
55 | error( "Bad on_state_create: " .. tostring( _params.on_state_create), 2) | ||
56 | end | ||
49 | 57 | ||
50 | local mm = require "lua51-lanes" | 58 | local mm = require "lua51-lanes" |
51 | assert( type(mm)=="table" ) | 59 | assert( type(mm)=="table" ) |
52 | 60 | ||
53 | -- configure() is available only the first time lua51-lanes is required process-wide, and we *must* call it to have the other functions in the interface | 61 | -- configure() is available only the first time lua51-lanes is required process-wide, and we *must* call it to have the other functions in the interface |
54 | if mm.configure then mm.configure( _nb_keepers) end | 62 | if mm.configure then mm.configure( _params.nb_keepers, _params.on_state_create) end |
55 | 63 | ||
56 | local thread_new = assert(mm.thread_new) | 64 | local thread_new = assert(mm.thread_new) |
57 | 65 | ||
@@ -238,7 +246,7 @@ local function gen( ... ) | |||
238 | -- Lane generator | 246 | -- Lane generator |
239 | -- | 247 | -- |
240 | return function(...) | 248 | return function(...) |
241 | return thread_new( func, libs, cs, prio, g_tbl, package_tbl, required, ...) -- args | 249 | return thread_new( func, libs, _params.on_state_create, cs, prio, g_tbl, package_tbl, required, ...) -- args |
242 | end | 250 | end |
243 | end | 251 | end |
244 | 252 | ||
@@ -258,7 +266,7 @@ local linda = mm.linda | |||
258 | -- PUBLIC LANES API | 266 | -- PUBLIC LANES API |
259 | local timer = function() error "timers are not active" end | 267 | local timer = function() error "timers are not active" end |
260 | 268 | ||
261 | if _timers ~= "NO_TIMERS" then | 269 | if _params.with_timers ~= false then |
262 | 270 | ||
263 | local timer_gateway= assert( mm.timer_gateway ) | 271 | local timer_gateway= assert( mm.timer_gateway ) |
264 | -- | 272 | -- |
@@ -477,7 +485,7 @@ timer = function( linda, key, a, period ) | |||
477 | timer_gateway:send( TGW_KEY, linda, key, wakeup_at, period ) | 485 | timer_gateway:send( TGW_KEY, linda, key, wakeup_at, period ) |
478 | end | 486 | end |
479 | 487 | ||
480 | end -- _timers | 488 | end -- _params.with_timers |
481 | 489 | ||
482 | ---=== Lock & atomic generators ===--- | 490 | ---=== Lock & atomic generators ===--- |
483 | 491 | ||
@@ -552,12 +560,16 @@ end | |||
552 | lanes.genlock = genlock | 560 | lanes.genlock = genlock |
553 | lanes.genatomic = genatomic | 561 | lanes.genatomic = genatomic |
554 | -- from now on, calling configure does nothing but checking that we don't call it with parameters that changed compared to the first invocation | 562 | -- from now on, calling configure does nothing but checking that we don't call it with parameters that changed compared to the first invocation |
555 | lanes.configure = function( _nk, _t) | 563 | lanes.configure = function( _params2) |
556 | if _nk ~= _nb_keepers then | 564 | _params2 = _params2 or _params |
557 | error( "mismatched configuration: " .. tostring( _nk) .. " keepers instead of " .. tostring( _nb_keepers)) | 565 | if _params2.nb_keepers ~= _params.nb_keepers then |
566 | error( "mismatched configuration: " .. tostring( _params2.nb_keepers) .. " keepers instead of " .. tostring( _params.nb_keepers)) | ||
567 | end | ||
568 | if _params2.with_timers ~= _params.with_timers then | ||
569 | error( "mismatched configuration: " .. tostring( _params2.with_timers) .. " timer activity instead of " .. tostring( _params.with_timers)) | ||
558 | end | 570 | end |
559 | if _t ~= _timers then | 571 | if _params2.on_create_state and _params2.on_create_state ~= _params.on_create_state then |
560 | error( "mismatched configuration: " .. tostring( _t) .. " timer activity instead of " .. tostring( _timers)) | 572 | error( "mismatched configuration: " .. tostring( _params2.on_create_state) .. " timer activity instead of " .. tostring( _params.on_create_state)) |
561 | end | 573 | end |
562 | return lanes | 574 | return lanes |
563 | end | 575 | end |
diff --git a/src/tools.c b/src/tools.c index 85672e2..212cf52 100644 --- a/src/tools.c +++ b/src/tools.c | |||
@@ -91,7 +91,7 @@ void luaG_dump( lua_State* L ) { | |||
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | /*---=== luaG_openlibs ===---*/ | 94 | /*---=== luaG_newstate ===---*/ |
95 | 95 | ||
96 | static const luaL_Reg libs[] = { | 96 | static const luaL_Reg libs[] = { |
97 | { LUA_LOADLIBNAME, luaopen_package }, | 97 | { LUA_LOADLIBNAME, luaopen_package }, |
@@ -371,7 +371,7 @@ static void populate_func_lookup_table_recur( lua_State *L, int _ctx_base, int _ | |||
371 | } | 371 | } |
372 | 372 | ||
373 | /* | 373 | /* |
374 | * create a "fully.qualified.name" <-> function equivalence dabase | 374 | * create a "fully.qualified.name" <-> function equivalence database |
375 | */ | 375 | */ |
376 | void populate_func_lookup_table( lua_State *L, int _i, char const *_name) | 376 | void populate_func_lookup_table( lua_State *L, int _i, char const *_name) |
377 | { | 377 | { |
@@ -422,39 +422,52 @@ void populate_func_lookup_table( lua_State *L, int _i, char const *_name) | |||
422 | */ | 422 | */ |
423 | #define is_name_char(c) (isalpha(c) || (c)=='*') | 423 | #define is_name_char(c) (isalpha(c) || (c)=='*') |
424 | 424 | ||
425 | const char *luaG_openlibs( lua_State *L, const char *libs) | 425 | lua_State* luaG_newstate( char const* libs, lua_CFunction _on_state_create) |
426 | { | 426 | { |
427 | const char *p; | 427 | char const* p; |
428 | unsigned len; | 428 | unsigned int len; |
429 | lua_State* const L = luaL_newstate(); | ||
429 | 430 | ||
430 | if (!libs) return NULL; // no libs, not even 'base' | 431 | // no libs, or special init func (not even 'base') |
431 | 432 | if (libs || _on_state_create) | |
432 | // 'lua.c' stops GC during initialization so perhaps its a good idea. :) | ||
433 | // | ||
434 | lua_gc( L, LUA_GCSTOP, 0); | ||
435 | |||
436 | // Anything causes 'base' to be taken in | ||
437 | // | ||
438 | STACK_GROW(L,2); | ||
439 | STACK_CHECK(L) | ||
440 | lua_pushcfunction( L, luaopen_base); | ||
441 | lua_call( L, 0, 1); | ||
442 | // after opening base, register the functions they exported in our name<->function database | ||
443 | populate_func_lookup_table( L, LUA_GLOBALSINDEX, NULL); | ||
444 | lua_pop( L, 1); | ||
445 | STACK_MID( L, 0); | ||
446 | for( p= libs; *p; p+=len ) | ||
447 | { | 433 | { |
448 | len=0; | 434 | // 'lua.c' stops GC during initialization so perhaps its a good idea. :) |
449 | while (*p && !is_name_char(*p)) p++; // bypass delimiters | 435 | // |
450 | while (is_name_char(p[len])) len++; // bypass name | 436 | lua_gc( L, LUA_GCSTOP, 0); |
451 | if (len && (!openlib( L, p, len ))) | ||
452 | break; | ||
453 | } | ||
454 | STACK_END(L,0) | ||
455 | lua_gc(L, LUA_GCRESTART, 0); | ||
456 | 437 | ||
457 | return *p ? p : NULL; | 438 | // Anything causes 'base' to be taken in |
439 | // | ||
440 | STACK_GROW( L, 2); | ||
441 | STACK_CHECK( L) | ||
442 | if( _on_state_create) | ||
443 | { | ||
444 | lua_pushcfunction( L, _on_state_create); | ||
445 | lua_call( L, 0, 0); | ||
446 | } | ||
447 | if( libs) | ||
448 | { | ||
449 | lua_pushcfunction( L, luaopen_base); | ||
450 | lua_call( L, 0, 0); | ||
451 | } | ||
452 | // after opening base, register the functions it exported in our name<->function database | ||
453 | populate_func_lookup_table( L, LUA_GLOBALSINDEX, NULL); | ||
454 | STACK_MID( L, 0); | ||
455 | if( libs) | ||
456 | { | ||
457 | for( p = libs; *p; p += len) | ||
458 | { | ||
459 | len=0; | ||
460 | while (*p && !is_name_char(*p)) p++; // bypass delimiters | ||
461 | while (is_name_char(p[len])) len++; // bypass name | ||
462 | if (len && (!openlib( L, p, len ))) | ||
463 | break; | ||
464 | } | ||
465 | serialize_require( L); | ||
466 | } | ||
467 | STACK_END(L,0) | ||
468 | lua_gc( L, LUA_GCRESTART, 0); | ||
469 | } | ||
470 | return L; | ||
458 | } | 471 | } |
459 | 472 | ||
460 | 473 | ||
@@ -1317,7 +1330,7 @@ static void inter_copy_func( lua_State *L2, uint_t L2_cache_i, lua_State *L, uin | |||
1317 | else | 1330 | else |
1318 | { | 1331 | { |
1319 | if( !inter_copy_one_( L2, L2_cache_i, L, lua_gettop(L), VT_NORMAL)) | 1332 | if( !inter_copy_one_( L2, L2_cache_i, L, lua_gettop(L), VT_NORMAL)) |
1320 | luaL_error( L, "Cannot copy upvalue type '%s'", luaG_typename( L, -1)); | 1333 | luaL_error( L, "Cannot copy upvalue type '%s'", luaL_typename( L, -1)); |
1321 | } | 1334 | } |
1322 | lua_pop( L, 1); | 1335 | lua_pop( L, 1); |
1323 | } | 1336 | } |
@@ -1475,7 +1488,7 @@ static bool_t inter_copy_one_( lua_State *L2, uint_t L2_cache_i, lua_State *L, u | |||
1475 | lua_rawset( L2, -3 ); // add to table (pops key & val) | 1488 | lua_rawset( L2, -3 ); // add to table (pops key & val) |
1476 | } else { | 1489 | } else { |
1477 | luaL_error( L, "Unable to copy over type '%s' (in %s)", | 1490 | luaL_error( L, "Unable to copy over type '%s' (in %s)", |
1478 | luaG_typename(L,val_i), | 1491 | luaL_typename(L,val_i), |
1479 | vt==VT_NORMAL ? "table":"metatable" ); | 1492 | vt==VT_NORMAL ? "table":"metatable" ); |
1480 | } | 1493 | } |
1481 | } | 1494 | } |
@@ -1647,7 +1660,7 @@ static int new_require( lua_State *L) | |||
1647 | { | 1660 | { |
1648 | int rc, i; | 1661 | int rc, i; |
1649 | int args = lua_gettop( L); | 1662 | int args = lua_gettop( L); |
1650 | //char const *modname = luaL_checkstring( L, 1); | 1663 | //char const* modname = luaL_checkstring( L, 1); |
1651 | 1664 | ||
1652 | STACK_GROW( L, args + 1); | 1665 | STACK_GROW( L, args + 1); |
1653 | STACK_CHECK( L) | 1666 | STACK_CHECK( L) |
diff --git a/src/tools.h b/src/tools.h index 1c9b00a..67f9874 100644 --- a/src/tools.h +++ b/src/tools.h | |||
@@ -46,13 +46,11 @@ | |||
46 | 46 | ||
47 | #define luaG_isany(L,i) (!lua_isnil(L,i)) | 47 | #define luaG_isany(L,i) (!lua_isnil(L,i)) |
48 | 48 | ||
49 | #define luaG_typename( L, index ) lua_typename( L, lua_type(L,index) ) | ||
50 | |||
51 | typedef void (*luaG_IdFunction)( lua_State *L, char const * const which); | 49 | typedef void (*luaG_IdFunction)( lua_State *L, char const * const which); |
52 | 50 | ||
53 | void luaG_dump( lua_State* L ); | 51 | void luaG_dump( lua_State* L ); |
54 | 52 | ||
55 | const char *luaG_openlibs( lua_State *L, const char *libs ); | 53 | lua_State* luaG_newstate( char const* libs, lua_CFunction _on_state_create); |
56 | 54 | ||
57 | int luaG_deep_userdata( lua_State *L, luaG_IdFunction idfunc); | 55 | int luaG_deep_userdata( lua_State *L, luaG_IdFunction idfunc); |
58 | void *luaG_todeep( lua_State *L, luaG_IdFunction idfunc, int index ); | 56 | void *luaG_todeep( lua_State *L, luaG_IdFunction idfunc, int index ); |
diff --git a/tests/appendud.lua b/tests/appendud.lua index e275a98..d0efb26 100644 --- a/tests/appendud.lua +++ b/tests/appendud.lua | |||
@@ -7,7 +7,7 @@ | |||
7 | -- Needs Lanes >= 2.0.3 | 7 | -- Needs Lanes >= 2.0.3 |
8 | -- | 8 | -- |
9 | local lanes = require "lanes" | 9 | local lanes = require "lanes" |
10 | lanes.configure( 1) | 10 | lanes.configure() |
11 | 11 | ||
12 | local _tab = { | 12 | local _tab = { |
13 | beginupdate = function (this) print('tab.beginupdate') end; | 13 | beginupdate = function (this) print('tab.beginupdate') end; |
diff --git a/tests/atexit.lua b/tests/atexit.lua index 09fbafd..31e1199 100644 --- a/tests/atexit.lua +++ b/tests/atexit.lua | |||
@@ -1,5 +1,5 @@ | |||
1 | local lanes = require "lanes" | 1 | local lanes = require "lanes" |
2 | lanes.configure( 1) | 2 | lanes.configure() |
3 | 3 | ||
4 | -- create a free-running lane | 4 | -- create a free-running lane |
5 | 5 | ||
diff --git a/tests/atomic.lua b/tests/atomic.lua index f1c9428..12bdf02 100644 --- a/tests/atomic.lua +++ b/tests/atomic.lua | |||
@@ -5,7 +5,7 @@ | |||
5 | -- | 5 | -- |
6 | 6 | ||
7 | local lanes = require "lanes" | 7 | local lanes = require "lanes" |
8 | lanes.configure( 1) | 8 | lanes.configure() |
9 | 9 | ||
10 | local linda= lanes.linda() | 10 | local linda= lanes.linda() |
11 | local key= "$" | 11 | local key= "$" |
diff --git a/tests/basic.lua b/tests/basic.lua index 8b07697..eb8c04b 100644 --- a/tests/basic.lua +++ b/tests/basic.lua | |||
@@ -8,7 +8,7 @@ | |||
8 | -- | 8 | -- |
9 | 9 | ||
10 | local lanes = require "lanes" | 10 | local lanes = require "lanes" |
11 | lanes.configure( 1) | 11 | lanes.configure() |
12 | require "assert" -- assert.fails() | 12 | require "assert" -- assert.fails() |
13 | 13 | ||
14 | local lanes_gen= assert( lanes.gen ) | 14 | local lanes_gen= assert( lanes.gen ) |
diff --git a/tests/cyclic.lua b/tests/cyclic.lua index 15abc9c..656fde3 100644 --- a/tests/cyclic.lua +++ b/tests/cyclic.lua | |||
@@ -5,7 +5,7 @@ | |||
5 | -- | 5 | -- |
6 | 6 | ||
7 | local lanes = require "lanes" | 7 | local lanes = require "lanes" |
8 | lanes.configure( 1) | 8 | lanes.configure() |
9 | 9 | ||
10 | local table_concat= assert(table.concat) | 10 | local table_concat= assert(table.concat) |
11 | 11 | ||
diff --git a/tests/ehynes.lua b/tests/ehynes.lua index b529f98..fff008c 100644 --- a/tests/ehynes.lua +++ b/tests/ehynes.lua | |||
@@ -2,7 +2,7 @@ | |||
2 | -- Test from <ehynes at dharmagaia.com> | 2 | -- Test from <ehynes at dharmagaia.com> |
3 | -- | 3 | -- |
4 | local lanes = require "lanes" | 4 | local lanes = require "lanes" |
5 | lanes.configure( 1) | 5 | lanes.configure() |
6 | 6 | ||
7 | local function PRINT_FMT( fmt, ... ) | 7 | local function PRINT_FMT( fmt, ... ) |
8 | io.stderr:write( string.format(fmt,...).."\n" ) | 8 | io.stderr:write( string.format(fmt,...).."\n" ) |
diff --git a/tests/errhangtest.lua b/tests/errhangtest.lua index 7127326..5974005 100644 --- a/tests/errhangtest.lua +++ b/tests/errhangtest.lua | |||
@@ -1,5 +1,5 @@ | |||
1 | local lanes = require "lanes" | 1 | local lanes = require "lanes" |
2 | lanes.configure( 1) | 2 | lanes.configure() |
3 | 3 | ||
4 | local linda = lanes.linda() | 4 | local linda = lanes.linda() |
5 | 5 | ||
diff --git a/tests/error.lua b/tests/error.lua index aee4221..c4a64e3 100644 --- a/tests/error.lua +++ b/tests/error.lua | |||
@@ -5,7 +5,7 @@ | |||
5 | -- | 5 | -- |
6 | 6 | ||
7 | local lanes = require "lanes" | 7 | local lanes = require "lanes" |
8 | lanes.configure( 1) | 8 | lanes.configure() |
9 | 9 | ||
10 | local function lane() | 10 | local function lane() |
11 | 11 | ||
diff --git a/tests/fibonacci.lua b/tests/fibonacci.lua index 2e0cd62..55dede1 100644 --- a/tests/fibonacci.lua +++ b/tests/fibonacci.lua | |||
@@ -13,7 +13,7 @@ | |||
13 | -- Need to say it's 'local' so it can be an upvalue | 13 | -- Need to say it's 'local' so it can be an upvalue |
14 | -- | 14 | -- |
15 | local lanes = require "lanes" | 15 | local lanes = require "lanes" |
16 | lanes.configure( 1, "NO_TIMERS") | 16 | lanes.configure{ nb_keepers =1, with_timers = false} |
17 | 17 | ||
18 | local function WR(str) | 18 | local function WR(str) |
19 | io.stderr:write( str.."\n" ) | 19 | io.stderr:write( str.."\n" ) |
diff --git a/tests/fifo.lua b/tests/fifo.lua index d8289c1..3c403fa 100644 --- a/tests/fifo.lua +++ b/tests/fifo.lua | |||
@@ -5,7 +5,7 @@ | |||
5 | -- | 5 | -- |
6 | 6 | ||
7 | local lanes = require "lanes" | 7 | local lanes = require "lanes" |
8 | lanes.configure( 1) | 8 | lanes.configure() |
9 | 9 | ||
10 | local linda= lanes.linda() | 10 | local linda= lanes.linda() |
11 | local atomic_inc= lanes.genatomic( linda, "FIFO_n" ) | 11 | local atomic_inc= lanes.genatomic( linda, "FIFO_n" ) |
diff --git a/tests/finalizer.lua b/tests/finalizer.lua index 88f51c1..6f186ab 100644 --- a/tests/finalizer.lua +++ b/tests/finalizer.lua | |||
@@ -9,7 +9,7 @@ | |||
9 | -- | 9 | -- |
10 | 10 | ||
11 | local lanes = require "lanes" | 11 | local lanes = require "lanes" |
12 | lanes.configure( 1) | 12 | lanes.configure() |
13 | 13 | ||
14 | local FN= "finalizer-test.tmp" | 14 | local FN= "finalizer-test.tmp" |
15 | 15 | ||
diff --git a/tests/func_is_string.lua b/tests/func_is_string.lua index 5d94f85..d7cf0b2 100644 --- a/tests/func_is_string.lua +++ b/tests/func_is_string.lua | |||
@@ -1,5 +1,5 @@ | |||
1 | local lanes = require "lanes" | 1 | local lanes = require "lanes" |
2 | lanes.configure( 1) | 2 | lanes.configure() |
3 | 3 | ||
4 | local options = {globals = { b = 666 }} | 4 | local options = {globals = { b = 666 }} |
5 | 5 | ||
diff --git a/tests/hangtest.lua b/tests/hangtest.lua index 923496a..6a9f7aa 100644 --- a/tests/hangtest.lua +++ b/tests/hangtest.lua | |||
@@ -3,7 +3,7 @@ | |||
3 | -- | 3 | -- |
4 | 4 | ||
5 | local lanes = require "lanes" | 5 | local lanes = require "lanes" |
6 | lanes.configure( 1) | 6 | lanes.configure() |
7 | 7 | ||
8 | local function ret(b) | 8 | local function ret(b) |
9 | return b | 9 | return b |
diff --git a/tests/irayo_closure.lua b/tests/irayo_closure.lua index 77ddbde..3278d57 100644 --- a/tests/irayo_closure.lua +++ b/tests/irayo_closure.lua | |||
@@ -11,7 +11,7 @@ e.g. { globals = { data = 1, func = function() useclosurehere() end } }" | |||
11 | ]] | 11 | ]] |
12 | 12 | ||
13 | local lanes = require "lanes" | 13 | local lanes = require "lanes" |
14 | lanes.configure( 1) | 14 | lanes.configure() |
15 | 15 | ||
16 | local function testrun() | 16 | local function testrun() |
17 | assert( print ) | 17 | assert( print ) |
diff --git a/tests/irayo_recursive.lua b/tests/irayo_recursive.lua index 3eb14b8..f6fe87e 100644 --- a/tests/irayo_recursive.lua +++ b/tests/irayo_recursive.lua | |||
@@ -9,7 +9,7 @@ local function recurse() | |||
9 | if i > 10 then return "finished" end | 9 | if i > 10 then return "finished" end |
10 | 10 | ||
11 | local lanes = require "lanes" | 11 | local lanes = require "lanes" |
12 | lanes.configure( 1, "NO_TIMERS") | 12 | lanes.configure{ nb_keepers = 1, with_timers = false} |
13 | 13 | ||
14 | local lane = lanes.gen( "*", { globals = { ["i"]= i + 1 } }, recurse ) () | 14 | local lane = lanes.gen( "*", { globals = { ["i"]= i + 1 } }, recurse ) () |
15 | return lane[1] | 15 | return lane[1] |
diff --git a/tests/keeper.lua b/tests/keeper.lua index 7b11242..40c9e11 100644 --- a/tests/keeper.lua +++ b/tests/keeper.lua | |||
@@ -5,7 +5,7 @@ | |||
5 | -- | 5 | -- |
6 | 6 | ||
7 | local lanes = require "lanes" | 7 | local lanes = require "lanes" |
8 | lanes.configure( 1) | 8 | lanes.configure() |
9 | 9 | ||
10 | local function keeper(linda) | 10 | local function keeper(linda) |
11 | local mt= { | 11 | local mt= { |
diff --git a/tests/launchtest.lua b/tests/launchtest.lua index 8456091..f3a6740 100644 --- a/tests/launchtest.lua +++ b/tests/launchtest.lua | |||
@@ -46,7 +46,7 @@ for k,v in pairs( argtable(...) ) do | |||
46 | end | 46 | end |
47 | 47 | ||
48 | local lanes = require "lanes" | 48 | local lanes = require "lanes" |
49 | lanes.configure( 1) | 49 | lanes.configure() |
50 | 50 | ||
51 | local g= lanes.gen( LIBS, function(i) | 51 | local g= lanes.gen( LIBS, function(i) |
52 | --io.stderr:write( i.."\t" ) | 52 | --io.stderr:write( i.."\t" ) |
diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua index 12159da..fff2670 100644 --- a/tests/linda_perf.lua +++ b/tests/linda_perf.lua | |||
@@ -1,5 +1,5 @@ | |||
1 | local lanes = require "lanes" | 1 | local lanes = require "lanes" |
2 | lanes.configure( 1) | 2 | lanes.configure() |
3 | 3 | ||
4 | -- this lane eats items in the linda one by one | 4 | -- this lane eats items in the linda one by one |
5 | local eater = function( l, loop) | 5 | local eater = function( l, loop) |
diff --git a/tests/objects.lua b/tests/objects.lua index 29e16d8..14cf9ba 100644 --- a/tests/objects.lua +++ b/tests/objects.lua | |||
@@ -5,7 +5,7 @@ | |||
5 | -- | 5 | -- |
6 | 6 | ||
7 | local lanes = require "lanes" | 7 | local lanes = require "lanes" |
8 | lanes.configure( 1) | 8 | lanes.configure() |
9 | 9 | ||
10 | local linda= lanes.linda() | 10 | local linda= lanes.linda() |
11 | 11 | ||
diff --git a/tests/perftest.lua b/tests/perftest.lua index 3d9fde0..4df2ad8 100644 --- a/tests/perftest.lua +++ b/tests/perftest.lua | |||
@@ -28,7 +28,7 @@ local MSYS= os.getenv("OSTYPE")=="msys" | |||
28 | 28 | ||
29 | 29 | ||
30 | local lanes = require "lanes" | 30 | local lanes = require "lanes" |
31 | lanes.configure( 1) | 31 | lanes.configure() |
32 | 32 | ||
33 | local m= require "argtable" | 33 | local m= require "argtable" |
34 | local argtable= assert( m.argtable ) | 34 | local argtable= assert( m.argtable ) |
diff --git a/tests/recursive.lua b/tests/recursive.lua index ad32df8..571fc1e 100644 --- a/tests/recursive.lua +++ b/tests/recursive.lua | |||
@@ -13,7 +13,7 @@ local function func( depth ) | |||
13 | 13 | ||
14 | local lanes = require "lanes" | 14 | local lanes = require "lanes" |
15 | -- lanes.configure() is gone after we call it... | 15 | -- lanes.configure() is gone after we call it... |
16 | lanes.configure( 1) | 16 | lanes.configure() |
17 | local lane= lanes.gen("*", func)( depth+1 ) | 17 | local lane= lanes.gen("*", func)( depth+1 ) |
18 | return lane[1] | 18 | return lane[1] |
19 | end | 19 | end |
diff --git a/tests/require.lua b/tests/require.lua index 96717dc..f538dc6 100644 --- a/tests/require.lua +++ b/tests/require.lua | |||
@@ -4,7 +4,7 @@ | |||
4 | -- Test that 'require' works from sublanes | 4 | -- Test that 'require' works from sublanes |
5 | -- | 5 | -- |
6 | local lanes = require "lanes" | 6 | local lanes = require "lanes" |
7 | lanes.configure( 1) | 7 | lanes.configure() |
8 | 8 | ||
9 | local function a_lane() | 9 | local function a_lane() |
10 | -- To require 'math' we still actually need to have it initialized for | 10 | -- To require 'math' we still actually need to have it initialized for |
diff --git a/tests/timer.lua b/tests/timer.lua index f0027d7..c6f510b 100644 --- a/tests/timer.lua +++ b/tests/timer.lua | |||
@@ -9,7 +9,7 @@ io.stderr:setvbuf "no" | |||
9 | 9 | ||
10 | 10 | ||
11 | local lanes = require "lanes" | 11 | local lanes = require "lanes" |
12 | lanes.configure( 1) | 12 | lanes.configure() |
13 | 13 | ||
14 | local linda= lanes.linda() | 14 | local linda= lanes.linda() |
15 | 15 | ||