Skip to content

Commit 44540b9

Browse files
Benoit GermainBenoit Germain
authored andcommitted
version 3.7.0
* fix lanes.threads() not being available in a lane where lanes.configure() settings didn't contain track_lanes although the initial configure() call did. * require "lanes".configure() sequence is only necessary at the first require "lanes". * fix a crash at application shutdown where in some situations we could deinitialize the protected allocator mutex while a lane was still using it. * fix timers broken by change 69
1 parent 938ee19 commit 44540b9

File tree

13 files changed

+319
-213
lines changed

13 files changed

+319
-213
lines changed

CHANGES

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
CHANGES:
22

3-
CHANGE 72: BGe 3-Ost-13
3+
CHANGE 76: BGe 10-Oct-13
4+
* version 3.7.0
5+
* fix lanes.threads() not being available in a lane where lanes.configure() settings didn't contain track_lanes although the initial configure() call did.
6+
7+
CHANGE 75: BGe 7-Oct-13
8+
* require "lanes".configure() sequence is only necessary at the first require "lanes".
9+
10+
CHANGE 74: BGe 7-Oct-13
11+
* fix a crash at application shutdown where in some situations we could deinitialize the protected allocator mutex while a lane was still using it.
12+
13+
CHANGE 73: BGe 4-Oct-13
14+
* fix timers broken by change 69
15+
16+
CHANGE 72: BGe 3-Oct-13
417
* bugfix: no longer create a global named "lanes.core" inside lanes having "*" as library list
518

619
CHANGE 71: BGe 30-Sept-13

docs/index.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
</p>
7171

7272
<p>
73-
This document was revised on 27-Sept-13, and applies to version <tt>3.6.6</tt>.
73+
This document was revised on 11-Oct-13, and applies to version <tt>3.7.0</tt>.
7474
</p>
7575
</font>
7676
</center>
@@ -248,7 +248,10 @@ <h2 id="initialization">Initialization</h2>
248248
After lanes is required, it is necessary to call <tt>lanes.configure()</tt>, which is the only function exposed by the module at this point. Calling <tt>configure()</tt> will perform one-time initializations and make the rest of the API available.
249249
</p>
250250
<p>
251-
At the same time, <tt>configure()</tt> itself will be replaced by another function that raises an error if called again with differing arguments.
251+
At the same time, <tt>configure()</tt> itself will be replaced by another function that raises an error if called again with differing arguments, if any.
252+
</p>
253+
<p>
254+
<b>IMPORTANT NOTE:</b> Starting with version 3.7.0, only the first occurence of <tt>require "lanes"</tt> must be followed by a call to <tt>.configure()</tt>. From this point, a simple <tt>require "lanes"</tt> will do wherever you need to require lanes again.
252255
</p>
253256

254257
<p>
@@ -326,7 +329,8 @@ <h2 id="initialization">Initialization</h2>
326329
<tt>nil</tt>/<tt>false</tt>/anything
327330
</td>
328331
<td>
329-
Any non-<tt>nil|false</tt> value instructs Lanes keeps track of all lanes, so that <a href="#tracking"><tt>lanes.threads()</tt></a> can list them.
332+
Any non-<tt>nil|false</tt> value instructs Lanes keeps track of all lanes, so that <a href="#tracking"><tt>lanes.threads()</tt></a> can list them. If <tt>false</tt>, <tt>lanes.threads()</tt> will raise an error when called.
333+
Default is <tt>false</tt>.
330334
</td>
331335
</tr>
332336

@@ -364,9 +368,7 @@ <h2 id="initialization">Initialization</h2>
364368
</p>
365369

366370
<p>
367-
NEW (version 3.5.0)
368-
<br>
369-
Once Lanes is configured, one should register with Lanes the modules exporting functions that will be transferred either during lane generation or through <a href="#lindas">lindas</a>.
371+
(Since v3.5.0) Once Lanes is configured, one should register with Lanes the modules exporting functions that will be transferred either during lane generation or through <a href="#lindas">lindas</a>.
370372
<br>
371373
Use <tt>lanes.require()</tt> for this purpose. This will call the original <tt>require()</tt>, then add the result to the lookup databases.
372374
</p>

src/keeper.c

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ typedef struct
7070
static keeper_fifo* prepare_fifo_access( lua_State* L, int idx)
7171
{
7272
keeper_fifo* fifo = (keeper_fifo*) lua_touserdata( L, idx);
73-
if( fifo)
73+
if( fifo != NULL)
7474
{
7575
idx = lua_absindex( L, idx);
7676
STACK_GROW( L, 1);
@@ -286,15 +286,15 @@ int keepercall_receive( lua_State* L)
286286
{
287287
int top = lua_gettop( L);
288288
int i;
289-
keeper_fifo* fifo;
290289
push_table( L, 1); // ud keys fifos
291290
lua_replace( L, 1); // fifos keys
292291
for( i = 2; i <= top; ++ i)
293292
{
293+
keeper_fifo* fifo;
294294
lua_pushvalue( L, i); // fifos keys key[i]
295295
lua_rawget( L, 1); // fifos keys fifo
296296
fifo = prepare_fifo_access( L, -1); // fifos keys fifo
297-
if( fifo && fifo->count > 0)
297+
if( fifo != NULL && fifo->count > 0)
298298
{
299299
fifo_pop( L, fifo, 1); // fifos keys val
300300
if( !lua_isnil( L, -1))
@@ -332,7 +332,7 @@ int keepercall_receive_batched( lua_State* L)
332332
lua_rawget( L, 2); // key fifos fifo
333333
lua_remove( L, 2); // key fifo
334334
fifo = prepare_fifo_access( L, 2); // key fifo
335-
if( fifo && fifo->count >= min_count)
335+
if( fifo != NULL && fifo->count >= min_count)
336336
{
337337
fifo_pop( L, fifo, __min( max_count, fifo->count)); // key ...
338338
}
@@ -360,7 +360,7 @@ int keepercall_limit( lua_State* L)
360360
lua_pushvalue( L, -1); // fifos key key
361361
lua_rawget( L, -3); // fifos key fifo
362362
fifo = (keeper_fifo*) lua_touserdata( L, -1);
363-
if( !fifo)
363+
if( fifo == NULL)
364364
{
365365
lua_pop( L, 1); // fifos key
366366
fifo_new( L); // fifos key fifo
@@ -437,7 +437,7 @@ int keepercall_get( lua_State* L)
437437
lua_replace( L, 1); // fifos key
438438
lua_rawget( L, 1); // fifos fifo
439439
fifo = prepare_fifo_access( L, -1); // fifos fifo
440-
if( fifo && fifo->count > 0)
440+
if( fifo != NULL && fifo->count > 0)
441441
{
442442
lua_remove( L, 1); // fifo
443443
// read one value off the fifo
@@ -497,7 +497,7 @@ int keepercall_count( lua_State* L)
497497
lua_rawget( L, 2); // out fifos keys fifo
498498
fifo = prepare_fifo_access( L, -1); // out fifos keys fifo
499499
lua_pop( L, 1); // out fifos keys
500-
if( fifo)
500+
if( fifo != NULL)
501501
{
502502
lua_pushinteger( L, fifo->count); // out fifos keys count
503503
lua_rawset( L, 1); // out fifos keys
@@ -540,14 +540,17 @@ void close_keepers( void)
540540
for( i = 0; i < GNbKeepers; ++ i)
541541
{
542542
lua_State* L = GKeepers[i].L;
543-
GKeepers[i].L = 0;
543+
GKeepers[i].L = NULL;
544544
lua_close( L);
545545
}
546546
for( i = 0; i < GNbKeepers; ++ i)
547547
{
548548
MUTEX_FREE( &GKeepers[i].lock_);
549549
}
550-
if( GKeepers) free( GKeepers);
550+
if( GKeepers != NULL)
551+
{
552+
free( GKeepers);
553+
}
551554
GKeepers = NULL;
552555
GNbKeepers = 0;
553556
}
@@ -560,20 +563,29 @@ void close_keepers( void)
560563
* Note: Any problems would be design flaws; the created Lua state is left
561564
* unclosed, because it does not really matter. In production code, this
562565
* function never fails.
566+
* settings table is at position 1 on the stack
563567
*/
564-
char const* init_keepers( lua_State* L, int _on_state_create, int const _nbKeepers)
568+
char const* init_keepers( lua_State* L)
565569
{
566-
int i;
567-
assert( _nbKeepers >= 1);
568-
GNbKeepers = _nbKeepers;
569-
GKeepers = malloc( _nbKeepers * sizeof( struct s_Keeper));
570-
for( i = 0; i < _nbKeepers; ++ i)
570+
int i, on_state_create;
571+
STACK_CHECK( L);
572+
lua_getfield( L, 1, "nb_keepers");
573+
GNbKeepers = lua_tointeger( L, -1);
574+
lua_pop( L, 1);
575+
STACK_MID( L, 0);
576+
assert( GNbKeepers >= 1);
577+
578+
lua_getfield( L, 1, "on_state_create");
579+
on_state_create = lua_isnil( L, -1) ? -1 : lua_absindex( L, -1);
580+
581+
GKeepers = malloc( GNbKeepers * sizeof( struct s_Keeper));
582+
for( i = 0; i < GNbKeepers; ++ i)
571583
{
572584
lua_State* K;
573585
DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "### init_keepers %d BEGIN\n" INDENT_END, i));
574586
DEBUGSPEW_CODE( ++ debugspew_indent_depth);
575587
// we don't need any libs in the keeper states
576-
K = luaG_newstate( L, _on_state_create, NULL);
588+
K = luaG_newstate( L, on_state_create, NULL);
577589

578590
STACK_CHECK( K);
579591

@@ -596,6 +608,8 @@ char const* init_keepers( lua_State* L, int _on_state_create, int const _nbKeepe
596608
GKeepers[i].L = K;
597609
//GKeepers[i].count = 0;
598610
}
611+
lua_pop( L, 1);
612+
STACK_END( L, 0);
599613
#if HAVE_KEEPER_ATEXIT_DESINIT
600614
atexit( atexit_close_keepers);
601615
#endif // HAVE_KEEPER_ATEXIT_DESINIT

src/keeper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct s_Keeper
1313
// problem: maybe on some platforms (linux) atexit() is called after DLL/so are unloaded...
1414
#define HAVE_KEEPER_ATEXIT_DESINIT 0
1515

16-
char const* init_keepers( lua_State* L, int _on_state_create, int const _nbKeepers);
16+
char const* init_keepers( lua_State* L);
1717
#if !HAVE_KEEPER_ATEXIT_DESINIT
1818
void close_keepers( void);
1919
#endif // HAVE_KEEPER_ATEXIT_DESINIT

0 commit comments

Comments
 (0)